rgb to gray image indeces matching
Show older comments
I have an RGB color image with dimensions: 460x640x3 and a gray image with the same dimensions: 460x640. They are of the same type, that is, uint8. I want to get the intensity information of the gray image using the coordinate values from color image if that coordinate value is not black (intensity value ~= 0). if not the intensity value of gray image should be 0 (black).
If I loop through each values for example like below:
img_length = 460x640;
for i = 1:img_length
if rgbImage(i) ~= 0;
depthImage(i) = i;
else if rgbImage(i) == 0;
depthImage(i) = 0;
i = i+1;
end;
As for color image how can I use only large dimensions as if it is a gray image?
2 Comments
Adam
on 27 Apr 2017
Don't call a variable length, it is a builtin function that you just over-rode.
Sokhib Tukhtayev
on 27 Apr 2017
Edited: Sokhib Tukhtayev
on 27 Apr 2017
Answers (1)
Image Analyst
on 27 Apr 2017
Edited: Image Analyst
on 27 Apr 2017
Try this:
sumImage = rgbImage(:,:,1) + rgbImage(:,:,2) + rgbImage(:,:,3);
mask = sumImage == 0;
grayValues = grayImage(mask); % 1-d list of gray levels where the color image is black.
6 Comments
Image Analyst
on 27 Apr 2017
Was this not what you wanted?
Sokhib Tukhtayev
on 30 Apr 2017
Image Analyst
on 30 Apr 2017
It gives you a "map" or image of all the places where the values are exactly 0 for red, green, and blue, in other words, a map of where true, pure black pixels live.
Sokhib Tukhtayev
on 4 May 2017
Image Analyst
on 4 May 2017
I don't understand how it does not do what you want. First it finds all the locations (pixels) where the image is totally black - each of red, green, and blue is exactly zero. Then it gives you the gray levels from the gray scale image at those locations. Your code does nothing like that (nothing like what you asked for) whereas mine does.
Sokhib Tukhtayev
on 6 May 2017
Categories
Find more on Images in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!