Setting voxel color and transparency in Mayavi Mlab - mayavi

How can I set the color and transparency of a specific voxel in Mayavi Mlab?

What is a "specific voxel?" Does that refer to a point on a surface? A point on a 2D picture? A cell? The ease of doing this differs considerably depending on the source type and on what you are doing.
See How to directly set RGB/RGBA colors in mayavi and https://github.com/enthought/mayavi/issues/92#issuecomment-29133606

Related

CGContextSetShadowWithColor and Shadow Color

I've been searching for a way of casting inner glow (shadow) on NSImage. And I've landed on this topic. The code given under this topic looks promising. It's an unfamiliar territory for me now. Anyway, I'm stuck with the following line.
CGContextSetShadowWithColor(c,CGSizeMake(0,-1),innerShadowBlurRadius,CGColorGetConstantColor(kCGColorBlack));
More specifically, I don't quite understand the color part. According to the documentation, the last term is CGColorRef, which I have never used. I suppose it's the color type used for Quartz 2D drawing. In other words, specify a color in the language that Quartz 2D understands, maybe? Anyway, the documentation further suggests that there are three color constants. kCGColorWhite, kCGColorBlack, kCGColorClear. Does that mean I cannot specify an RGB color in this respect?
Thank you for your help.
No that's not what it means, and yes, you can specify RGB values; probably just not in the way you might be thinking. Quartz uses something known as CGColorSpaceRef, which you can think of as multidimensional — and each dimension represents a specific color component. An example would be the colors in the RGB color space, as three dimensions (red, green, and blue). The intensity of each component is represented by floating point values, and their range and meaning depends on the color space in question.
This should give you more concise information that you're looking for:
https://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/CGColorSpace/Reference/reference.html#//apple_ref/doc/uid/TP30000949
Specifically take a look at:
CGColorCreateGenericRGB
Creates a color in the Generic RGB color space.
CGColorRef CGColorCreateGenericRGB(
CGFloat red,
CGFloat green,
CGFloat blue,
CGFloat alpha
);
and also the section on Constant Colors

map to gradient, re-color an image in iOS

What would be the most efficient way to remap the colors of an image to a gradient for iOS? This is defined as "apply a color lookup table to the image" in the Image Magic docs, and generally I think. Is there something built in core image for instance to do this? I know it can be done with ImageMagick code using convert -clut, but not certain that is the most efficient way to do it.
the result of remapping the image to a gradient is as pictured here:
http://owolf.net/uploads/ny.jpg
The basic formula, copied from fraxel's comment is:
1.Open your image as grayscale, and RGB
2.Convert the RGB image to HSV (Hue, Saturation, Value/Brightness) color space. This is a cylindrical space, with hue represented by a single value on the polar axis.
3.Set the hue channel to the grayscale image we already opened, this is the crucial step.
4.Set value, and saturation channels both to maximal values.
5.Convert back to RGB space (otherwise display will be incorrect).

Removing background from the sprite

I'm trying to "load" some 2d image as a material for a mesh, (I know about spritemanager) but I'm unfortunately getting this sprite with it's white background. How can I "make it go"(the background)?
Thanks.
If the image is of a file type that supports transparency, open it up in image editing software (paint.net, photoshop, etc.) and delete the white or replace it with empty/transparent color.
Otherwise, look for an option in the unity documentation to set a specific color value as 'background' or 'transparent' so that that color will be ignored.
First of all, you need to add an alpha channel to your texture and save it in a format that supports alpha channel transparency.
Here is a quick tutorial on how to do this in GIMP:
Note that you can remove the selected background with the Delete-key.
In my case, I'm exporting the result as a PNG for alpha transparency support. You can do this from the export menu by renaming the file suffix to .png:
I use these settings to export my PNG:
Then, after importing the image into Unity, Make sure that in the texture's import settings the image's alpha source is set to Input Texture Alpha and that Alpha is Transparency tickbox is checked like so:
Finally, since you are using this on a mesh, you need to ensure that your mesh has a material applied that has it's render mode set to Cutout:
Hope this little guide helps.

Programmatically, how does hue blending work in photoshop?

In Photoshop you can set a layer's blending mode to be "Hue". If that layer is, for example, filled with blue then it seems to take the layer below and makes it all blue wherever a non-whiteish color exists.
I'm wondering what it's actually doing though. If I have a background layer with a pixel aarrggbb and the layer on top of that is set to blend mode "Hue" and there's a pixel aarrggbb on that layer, how are those two values combined to give the result that we see?
It doesn't just drop the rrggbb from the layer below. If it did that it'd color white and black as well. It also wouldn't allow color variations through.
If a background pixel is 0xff00ff00 and the corresponding hue layer pixel is 0xff0000ff then I'm assuming the end result will just be 0xff0000ff because the ff blue replaces the ff green. But, if the background pixel is 0x55112233 and the hue layer pixel is 0xff0000ff, how does it come up with the shade of blue that it comes up with?
The reason I ask is that I'd like to take various images and change the hue of the image programmatically in my app. Rather than storing 8 different versions of the same image with different colors, I'd like to store one image and color it as needed.
I've been researching a way to replicate that blending mode in javascript/canvas but I've only come up with the "colorize" filter/blend mode. (Examples below)
Colorize algorithm:
convert the colors from RGB to HSL;
change the Hue value to the wanted one (in my case 172⁰ or 0.477);
revert the update HSL to RGB
Note: this is ok on the desktop but it's noticeably slow on a smartphone, I found.
You can see the difference by comparing these three images. Original:
colorize:
Fireworks' "blend hue" algorithm (which I think is the same as Photoshop's):
The colorize filter might be a good substitute.
RGB/HSL conversion question
Hue/Chroma and HSL on Wikipedia
I found an algorithm to convert RGB to HSV here:
http://www.cs.rit.edu/~ncs/color/t_convert.html
Of course, at the bottom of that page it mentions that the Java Color object already has methods for converting between RGB and HSV, so I just used that.

How to replace a color in an image?

I'm in search of a simple algorithm to replace a color in an image with a different one like in this one->
http://en.wikipedia.org/wiki/File:Colorswaphelicon.png
I'm using VB.NET. Can a "flood fill" algorithm be applied for this purpose?
Please provide a link if possible.
Greetings.
If you need to replace a color of a connected area then flood fill may work for you. For changing the color in the whole image check How to: Use a Color Remap Table and Recoloring Images topic.
Edit:
To replace all intensities of a color shade, you can check and replace the color hue (e.g. see How To Converting Colors Between RGB and HLS (HBS)). Specifically, colors with hue and saturation within a certain range of a source color can be changed to colors with original intensity and hue and saturation of the target color.
Also, you may find helpful How to change RGB color to HSV? and HSL in .net.