Finding the Brightest Pixel in an Image

17 views (last 30 days)
I have an RGB image, but its mostly black with different areas of shining light. I want my code to find the pixel where the light is shining brightest and mark that pixel but I'm not sure how.
Any help is appreciated. Thanks.

Accepted Answer

Sean de Wolski
Sean de Wolski on 26 Oct 2012
Well we have to figure out how to define "brightest". Is red brighter than blue?
Anyway, if we say brightness is the sum of the RGB channels, then the max pixel will be:
I = your_image;
S = sum(I,3) %
[~,idx] = max(S(:));
[row,col] = ind2sub(size(S),idx);
  2 Comments
Image Analyst
Image Analyst on 26 Oct 2012
Or, alternatively
[rows columns] = find(S == max(S(:)));
Not sure which is better but I find this more intuitive and easier to understand - you're just finding the rows/column pairs where S equals its max and don't need to worry about understanding what ind2sub does or how it works. But they both work.
Sean de Wolski
Sean de Wolski on 26 Oct 2012
True, IA. This also works for multiple maxima where mine only identifies the first.

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 26 Oct 2012
An alternative is to convert your image to monochrome by using rgb2gray() or taking just one of the color channels,
% Convert to gray with a weighted average of the R, G, and B channels.
grayImage = rgb2gray(rgbImage);
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
Then using imregionalmax() on whichever monochrome image you create. This will find ALL of the shiny peaks of light, with the brightest of those being just one of the peaks that it finds. But in general to find the brightest spot, use the method Sean gave. If you want to go further and find the one pixel that is the centroid of that spot, then you need to call regionprops(). See my Image Segmentation Tutorial if you want an example.
  2 Comments
James
James on 26 Oct 2012
If I convert the rgb to monochrome, it will give me a 2 dimensional matrix with values between 0 and 255 (0 being darkest, 255 being lightest) correct?

Sign in to comment.

Categories

Find more on Image Processing Toolbox 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!