How to find which pixel's brightness is the highest?

5 views (last 30 days)
We have a image which is grayscale. We select a row and we must find the highest brightness level pixel in this row. And after that we must do all row white. How can I do that. Which command should I use? Thank You.

Accepted Answer

Image Analyst
Image Analyst on 19 Dec 2021
Try this:
% Demo by Image Analyst, December, 2021.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clearvars;
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 16;
fprintf('Beginning to run %s.m ...\n', mfilename);
grayImage = imread('coins.png');
subplot(1, 2, 2);
imshow(grayImage)
g = gcf;
g.WindowState = 'maximized'
title('Click on this image', 'fontSize', fontSize)
uiwait(helpdlg('Click on a row'));
[x, y] = ginput(1);
row = round(y);
% Extract row
theRowsGrayLevels = grayImage(row, :);
subplot(1, 2, 1);
plot(theRowsGrayLevels, 'b-');
grid on;
caption = sprintf('Intensity of row #%d', row);
title(caption, 'fontSize', fontSize)
xlabel('Column', 'fontSize', fontSize)
ylabel('Gray Level', 'fontSize', fontSize)
% Now set that row to white.
grayImage(row, :) = 255;
subplot(1, 2, 2);
imshow(grayImage)
axis('on', 'image')
caption = sprintf('Row #%d', row);
title(caption, 'fontSize', fontSize)

More Answers (0)

Community Treasure Hunt

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

Start Hunting!