-1

Dears, I would like to ask you for help with the code. My goal is to find the brightest point an image and mark it.
I used the following code to get the Image in Grey Values -> How to find and highlight the brightest region an image in Matlab? and tried to extend it based on my intention.
Then I found the max value of the matrix and go with the for loop function to highlight the coordinates of the max points. Unfortunately, here I have started struggle.

rgbImage = imread( 'Zoom1_WhiteImage.png' );
%imshow(rgbImage);

[rows, columns, numberOfColorChannels] = size(rgbImage)  

if numberOfColorChannels == 1  
    brightness = rgbImage;  % For a 1 channel image, brightness is the same as the original pixel value.
else
    % For an RGB image, the brightness can be estimated in various ways, here's one standard formula: 
    brightness = (0.2126*rgbImage(:, :, 1) + 0.7152*rgbImage(:, :, 2) + 0.0722*rgbImage(:, :, 3));
end

% Establish a brightness threshold - pixels brighter than this value will
% be highlighted
threshold = 105;

% Create a zero-filled mask of equal size to the image to hold the
% information of which pixels met the brightness criterion:
mask = zeros(rows, columns, 'logical');

% Assign "1" to any mask pixels whose corresponding image pixel met the
% brightness criterion:
mask(brightness > threshold) = 1;

[a,b] = size(brightness) 

maxgrey = max(max(brightness));

aux=0;

for i=1:1:a;   
    for j=1:1:b;
        if brightness(a,b)>brightness(a,b+1)
            aux=brightness(a,b+1)
        else aux
            
            
        end
    end
end

Could you help me to finish the code, please?

Tomáš
  • 35
  • 6

1 Answers1

1

You can achieve your goal with the function find() or with the function ind2sub():

% Random 2D matrix
I = rand(10);

% First option with find
[x,y] = find(I == max(I(:)))

% Second option using ind2sub, a bit more efficient since we only read I once.
[~,ind] =   max(I(:))
[x,y] = ind2sub(size(I),ind)
obchardon
  • 10,614
  • 1
  • 17
  • 33
  • Hi, I was not express myself properly. From the code above I can detect all pixels higher than my threshold. My intention here is to find the brightest pixel from the whole matrix and highlight it. Step one should be to convert RGB to Grey Values. If I know the size of the matrix and max value then I would like to with loop function detect the point. Thank you in advance. – Tomáš Apr 19 '21 at 18:43
  • This is exactly what my code do, I don't get your point. By the brightest pixel do you mean the brightest pixel**S** ? – obchardon Apr 20 '21 at 09:07