why the image has no color in this code?

when i run this code the image with title""('rgbimage inside if');"" show as binary image .id don't know why?? here is the code and u can download the mat file from "u.mat" http://www.mediafire.com/?tf3ef09n4it3aa2 and "var.mat" http://www.mediafire.com/?ovn31e28d51eb1c
filename = 'u.mat';
matObj = matfile(filename);
moving = matObj.u;
I2 = matObj.im1;
filename2 = 'var.mat';
matObj = matfile(filename2);
storedColorMap = matObj.storedColorMap;
figure, imshow(moving,[]), title('binary gradient ');impixelinfo;
[rrr ccc] = size(I2);
moving = imresize(moving, [rrr ccc]);
rgbImage = moving;
% Read in image into an array.
[rows columns numberOfColorBands] = size(rgbImage);
% If it's monochrome (indexed), convert it to color.
% Check to see if it's an 8-bit image needed later for scaling).
if strcmpi(class(rgbImage), 'uint8')
% Flag for 256 gray levels.
eightBit = true;
else
eightBit = false;
end
if numberOfColorBands == 1
if isempty(storedColorMap)
% Just a simple gray level image, not indexed with a stored color map.
% Create a 3D true color image where we copy the monochrome image into all 3 (R, G, & B) color planes.
rgbImage = cat(3, rgbImage, rgbImage, rgbImage);
figure,imshow(rgbImage);title('rgbimage inside if');
else
% It's an indexed image.
rgbImage = ind2rgb(rgbImage, storedColorMap);
figure,imshow(rgbImage,[]);title('rgbimage inside esle');
% ind2rgb() will convert it to double and normalize it to the range 0-1.
% Convert back to uint8 in the range 0-255, if needed.
if eightBit
rgbImage = uint8(255 * rgbImage);
end
end
end

 Accepted Answer

You show "moving" as a "binary gradient". Then you convert "moving" to an RGB image by splicing three copies of it together, into the RGB planes. The locations in the binary array "moving" that were 0 will become [0,0,0] (black) and the locations in the binary array "moving" that were 1 will become [1,1,1] (white), so the result will still look like a binary image.

11 Comments

what can i do to solve this problem. i want "rgbImage" become a gray or color image .
Well, it is a color image, it's just that all the pixel colors are either pure black (0,0,0) or pure white (1,1,1). I still don't know what you want. Do you want the values to go from 0 to 255? Do you want values in the range 1-254? If you want that, then "in between" values need to exist, so you can't start with a binary (true/false, 1/0) image.
yes i want the values to go from 0 to 255. "moving" is gray image . i use impixelinfo(). and i found values to go from 0 to 255
Image Analyst
Image Analyst on 29 Jan 2013
Edited: Image Analyst on 29 Jan 2013
So multiply your image by 255. And why do you have all that general purpose code that handles RGB, grayscale, or indexed images? Don't you know in advance what kind of image you stored in your mat file?
multiply my image by 255!!!!!!!! which image "moving" or "rgbImage " i try both and i don't have any result
is there difference between these 2 codes the image "Icrop" suppose to be gray in the first code it shows as gray but in the second it shows white and black also it values are from 0 to 255
1-figure,imshow(Icrop,[]);
2-figure,imshow(Icrop);
If the image is floating point, the first one will scale the min to 0 and the max to 255 and the image should look fine. The second one will expect the image values to lie between 0 and 1. Any pixel less than 0 will be 0 and any pixel more than 1 will show up as white. What does this say:
minValue = min(lcrop(:))
maxValue = max(lcrop(:))
Tell us so we know what range lcrop lies in. While you're at it, do it for moving and rgbImage also.
I'm sorry for the delay in a reply because of the time difference
minValueofIcrop =
0
maxValueofIcrop =
255
minValueofmoving =
-34.1147
maxValueofmoving =
290.2519
minValueofrgbImage =
-34.1147
maxValueofrgbImage =
290.2519
If it's a floating point RGB image, you can't use [] in imshow() - it doesn't do anything. You either have to scale to 0-255 using typical math, or maybe im2double(), or else you can cast to uint8 before displaying.
imshow(uint8(rgbImage));
If you cast to uint8 any values outside 0-255 will get clipped.
i use
imshow(uint8(rgbImage));
it show image as gray but i still white and black when i use it after that is there any way to make it aloes shows gray . im2double() doesn't work
i don't familiar with "a floating point RGB image" what do mean ?
A floating point RGB image would be a color image with the values not being integers in the set 0, 1, 2, 3, 4, ...255. For example an image that had all kinds of continuous values ranging from -34.1147 to +290.2591. Casting to uint8 should work unless all the values are less than 0 and more than 255.
thanks a lot i use
moving= uint8(moving);
and it work will thanks a lot

Sign in to comment.

More Answers (0)

Categories

Find more on Images in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!