如何在Matlab中找到并突出显示图像的最亮区域?

问题描述

亲爱的

我想请求您的支持。我的目标是找到 RGB 图像中最亮的区域并在不使用其他工具的情况下将其突出显示。请看我下面的例子。

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

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

[x,y] = meshgrid(1:columns,1:rows);
% Extract the individual red,green,and blue color channels.
% Need to cast to double or else x and y will be clipped to 255 when we concatenate them.
if numberOfColorChannels == 1
    % Leave as gray scale.
    % Get array listing [r,g,b,x,y].  Using (:) will turn all the 2-D arrays into column vectors.
    output = [rgbImage(:),x(:),y(:)];
else
    redChannel = double(rgbImage(:,:,1));
    greenChannel = double(rgbImage(:,2));
    blueChannel = double(rgbImage(:,3));
    % Get array listing [r,y].  Using (:) will turn all the 2-D arrays into column vectors.
    output = [redChannel(:),greenChannel(:),blueChannel(:),y(:)];
end

[rows,columns] = find(rgbImage == 155);
imshow(rgbImage);
hold on

不幸的是,我正在苦苦思索如何继续绘制应该覆盖灰色图像的点。

请您帮我完成代码好吗?

解决方法

我建议您阅读 MATLAB 中的逻辑索引 - 这是一个非常强大的概念,它允许您通过展平数组并使用 { 创建单独的索引数组来跳过您尝试做的大部分事情{1}}。例如,Here is an article 处理底部的逻辑索引。

我已经修改并添加到您的代码中,因此它使用逻辑索引来完成工作。我在 R2019b 中对此进行了测试。

meshgrid