I wish to convert a grayscale image to RGB where I would have color-to-black scale instead of white-to-black scale. Let's say I have a specific color given by [r g b] components. I want the image to present the shades of this color, not the shades of gray. My pO2values will range from 1 to 128, so I use jet(128) to create a gamma of 128 colors from blue all the way to red. Then, I determine what rgb components represent that color. For example, if my pO2value is 60, it will correspond to some green color specified by [r g b] components. Now, I want my grayscale image to be 'greenscale', that is green-to-black gradient instead of original white-to-black gradient.
- generating r g b is equivalent of me selecting a color pixel using your demo
- don't see cat() in your script
im=zeros(512,512,3);im(:,:,1)=I; %where I is 512x512 uint8 grayscale image
im(:,:,2)=I;im(:,:,3)=I;% I create a desired color using values from jet spectrum
c = 128;pO2value=60;map = jet(c);pO2value=double(pO2value);r = ceil(map(pO2value,1)*128);g = ceil(map(pO2value,2)*128);b = ceil(map(pO2value,3)*128);% here's what I got from Image Analyst's demo code
hsv = rgb2hsv(im);hueImage = hsv(:, :, 1);selectedPixelRGB = [r g b];hsvOfThisPixel = rgb2hsv(selectedPixelRGB);% Make the hue plane of the hsv image this same hue
hsv(:, :, 1) = hsvOfThisPixel(1);hueImage2 = hsv(:, :, 1);% Convert back to rgb space.
singleHueRGBImage = hsv2rgb(hsv);imshow(singleHueRGBImage);
However, I get an error:
??? Attempted to access r(:,2); index out of bounds because size(r)=[1,1,1].
Error in ==> rgb2hsv at 74 g = r(:,2); b = r(:,3); r = r(:,1);
Here is an example of what I am trying to do:
Best Answer