why the image has no color in this code?

5 views (last 30 days)
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

Walter Roberson
Walter Roberson on 28 Jan 2013
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
Image Analyst
Image Analyst on 29 Jan 2013
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.
Isee You
Isee You on 29 Jan 2013
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 Read, Write, and Modify Image 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!