如何解决如何找到图像的最亮点并在 Matlab 中对其进行标记?
亲爱的,
我想请你帮忙看看代码。我的目标是找到图像的最亮点并标记它。
我使用以下代码获取灰度值中的图像 -> 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,'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
你能帮我完成代码吗?
解决方法
您可以使用函数 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)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。