find the minimum RGB values of a pixel from an image
8 ビュー (過去 30 日間)
古いコメントを表示
Hi! I'm having trouble to get the minimum of Intensity in an RGB image. I want to extract the darkest pixel (so the minimum RGB values) and mark it on the image with x, y coordinates. Could someone help me? Thank you
1 件のコメント
Adam
2019 年 3 月 19 日
You might as well just convert to greyscale if it is only the intensity you are interested in, then you only have to deal with a 2d image rather than 3d.
回答 (1 件)
Rik
2019 年 3 月 19 日
You mean like this?
RGB=uint8(255*rand(100,100,3));%random RGB image
temp_IM=sum(double(RGB),3);%sum the three color channels
[val,ind]=min(temp_IM(:));%find lowest value (first one if there are multiple)
[r,c]=ind2sub(size(temp_IM),ind);%coordinates of lowest intensity pixel
2 件のコメント
Guillaume
2019 年 3 月 20 日
There are several way you can define the intensity of a colour but a plain sum of the 3 colour components is not standard. Using matlab's definition of luminosity (see Algorithms in the doc of rgb2gray) , the intensity would be 0.2989 * R + 0.5870 * G + 0.1140 * B, a weighted mean of the three colour components. There are other definitions that are more attuned to human vision.
Note that instead of
RGB=uint8(255*rand(100,100,3));
you could use
RGB = randi([0 255], 100, 100, 3, 'uint8');
And I would use im2double instead of plain double for the conversion.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!