find the minimum RGB values of a pixel from an image

8 views (last 30 days)
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 Comment
Adam
Adam on 19 Mar 2019
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.

Sign in to comment.

Answers (1)

Rik
Rik on 19 Mar 2019
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 Comments
Ilaria Pintus
Ilaria Pintus on 20 Mar 2019
Thank you so much!
In the end I solved it in a way similar to what you suggested to me!
Guillaume
Guillaume on 20 Mar 2019
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.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!