rgb to gray image indeces matching

조회 수: 4 (최근 30일)
Sokhib Tukhtayev
Sokhib Tukhtayev 2017년 4월 27일
댓글: Sokhib Tukhtayev 2017년 5월 6일
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
Adam
Adam 2017년 4월 27일
Don't call a variable length, it is a builtin function that you just over-rode.
Sokhib Tukhtayev
Sokhib Tukhtayev 2017년 4월 27일
편집: Sokhib Tukhtayev 2017년 4월 27일
ok, it is just for reference, it could be any name. I changed it. Thank you, by the way!

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2017년 4월 27일
편집: Image Analyst 2017년 4월 27일
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
Image Analyst
Image Analyst 2017년 5월 4일
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
Sokhib Tukhtayev 2017년 5월 6일
Sorry sir, I combined your code with other code and got some side effects. Therefore I thought it didn't work. Thank you!

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by