Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 其它 > 资料存档
资料存档 资料存档
回复
 
主题工具 显示模式
旧 2019-12-10, 16:49   #1
poster
高级会员
 
注册日期: 2019-11-21
帖子: 3,006
声望力: 66
poster 正向着好的方向发展
帖子 如何在MATLAB中的图像中找到局部最大值?

我在MATLAB中有一张图片:

y = rgb2gray(imread('some_image_file.jpg')); 我想对其进行一些处理:

pic = some_processing(y); 并找到输出的局部最大值。也就是说, y中所有大于其所有邻居的点。

我似乎找不到MATLAB函数可以很好地做到这一点。我能想到的最好的是:

[dim_y,dim_x]=size(pic); enlarged_pic=[zeros(1,dim_x+2); zeros(dim_y,1),pic,zeros(dim_y,1); zeros(1,dim_x+2)]; % now build a 3D array % each plane will be the enlarged picture % moved up,down,left or right, % to all the diagonals, or not at all [en_dim_y,en_dim_x]=size(enlarged_pic); three_d(:,:,1)=enlarged_pic; three_d(:,:,2)=[enlarged_pic(2:end,:);zeros(1,en_dim_x)]; three_d(:,:,3)=[zeros(1,en_dim_x);enlarged_pic(1:end-1,:)]; three_d(:,:,4)=[zeros(en_dim_y,1),enlarged_pic(:,1:end-1)]; three_d(:,:,5)=[enlarged_pic(:,2:end),zeros(en_dim_y,1)]; three_d(:,:,6)=[pic,zeros(dim_y,2);zeros(2,en_dim_x)]; three_d(:,:,7)=[zeros(2,en_dim_x);pic,zeros(dim_y,2)]; three_d(:,:,8)=[zeros(dim_y,2),pic;zeros(2,en_dim_x)]; three_d(:,:,9)=[zeros(2,en_dim_x);zeros(dim_y,2),pic]; 然后查看沿第三维的最大值是否出现在第一层中(即: three_d(:,:,1) ):

(max_val, max_i) = max(three_d, 3); result = find(max_i == 1); 还有其他更优雅的方法吗?这似乎有点不合时宜。


回答:
bw = pic > imdilate(pic, [1 1 1; 1 0 1; 1 1 1]);

更多&回答...
poster 当前离线   回复时引用此帖
回复


发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛禁用 表情符号
论坛启用 [IMG] 代码
论坛启用 HTML 代码



所有时间均为北京时间。现在的时间是 02:35


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.