相关疑难解决方法(0)

如何在MATLAB中找到图像中的局部最大值?

我在MATLAB中有一个图像:

y = rgb2gray(imread('some_image_file.jpg'));
Run Code Online (Sandbox Code Playgroud)

我想对它做一些处理:

pic = some_processing(y);
Run Code Online (Sandbox Code Playgroud)

并找到输出的局部最大值.也就是说,其中的所有点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];
Run Code Online (Sandbox Code Playgroud)

然后查看第3维中的最大值是否出现在第1层(即:)three_d(:,:,1):

(max_val, max_i) = max(three_d, 3);
result = find(max_i == 1);
Run Code Online (Sandbox Code Playgroud)

有没有更优雅的方式来做到这一点?这看起来像是一块垃圾.

matlab image-processing mathematical-optimization

20
推荐指数
3
解决办法
3万
查看次数

如何创建自定义非线性滤波器?

所以我对创建自定义非线性滤波器感兴趣.我的掩码是一个3乘3的矩阵,我想要做的是取我的中心点并查看与其直接相邻的值(不包括对角线元素).我想通过每个相邻值减去中间元素,然后找到这些值中的最小值.基本上我正在查看高程数据,我想找到中间点的最小delta-Z.

例:

Z = [64 21 31 59 38 30 92 26 81 47 43 60 53 23 18 71];

所以我想Z(3,3)现在只是看着= 43.我会拿43并减去92,60,18和47; 分别产生-49,-17,25和-4.然后我希望它只输出-49.对Z矩阵中的每个元素重复该过程.我该怎么做呢?谢谢!

matlab filtering image-processing matrix

3
推荐指数
1
解决办法
656
查看次数