【问题标题】:How to find a brightest point an image and mark it in Matlab? [duplicate]如何找到图像的最亮点并在Matlab中标记它? [复制]
【发布时间】:2021-07-13 11:51:53
【问题描述】:

亲爱的, 我想向您寻求代码方面的帮助。我的目标是找到图像的最亮点并标记它。
我使用以下代码以灰度值获取图像 -> How to find and highlight the brightest region an image in Matlab? 并尝试根据我的意图对其进行扩展。
然后我找到了矩阵的最大值并使用 for 循环函数来突出显示最大点的坐标。不幸的是,在这里我已经开始挣扎了。

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

你能帮我完成代码吗?

【问题讨论】:

    标签: matlab image-processing find max brightness


    【解决方案1】:

    您可以使用函数find() 或使用函数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)
    

    【讨论】:

    • 嗨,我没有正确表达自己。从上面的代码中,我可以检测到所有高于我的阈值的像素。我的目的是从整个矩阵中找到最亮的像素并突出显示它。第一步应该是将 RGB 转换为灰度值。如果我知道矩阵的大小和最大值,那么我想用循环函数检测点。提前谢谢你。
    • 这正是我的代码所做的,我不明白你的意思。最亮的像素是指最亮的像素S 吗?
    猜你喜欢
    • 2021-07-10
    • 1970-01-01
    • 2017-05-18
    • 1970-01-01
    • 2013-11-24
    • 2015-12-15
    • 2016-12-23
    • 1970-01-01
    • 2010-12-03
    相关资源
    最近更新 更多