matlab求图像的局部峰值点集

经过辛苦寻找,目前发现三种方法来做(其中alpha控制强度):
方法一:
I = imread('lena-gray.bmp');
%BW = nlfilter(I, [3 3], @(x) all(x(5) > x([1:4 6:9])+ alpha ) ); %方法1
imshow(BW);
This  "find strict max"  function would simply check if the center of the neighborhood is strictly greater than all the other elements in that neighborhood, which is always 3x3 for this purpose.

方法二:
I = imread('lena-gray.bmp');
%BW = imregionalmax(I);%方法2
imshow(BW);

The variable BW will be a logical matrix the same size as y with ones indicating the local maxima and zeroes otherwise.

NOTE: As you point out, IMREGIONALMAX will find maxima that are greater than or equal to their neighbors. If you want to exclude neighboring maxima with the same value (i.e. find maxima that are single pixels), you could use the BWCONNCOMP function. The following should remove points in BW that have any neighbors, leaving only single pixels:

CC = bwconncomp(BW);
for i = 1:CC.NumObjects,
index = CC.PixelIdxList{i};
if (numel(index) > 1),
BW(index) = false;
end
end


方法三:
I = imread('lena-gray.bmp');
BW = I > imdilate(I, [1 1 1; 1 0 1; 1 1 1]) +alpha ; %方法3
imshow(BW);

@Nathan: IMDILATE operates on each pixel of the grayscale image. The center of the 3-by-3 matrix is positioned at each pixel, and the pixel value is replaced by the maximum value found at the neighboring pixels where there is a value of 1 in the 3-by-3 matrix. The call to IMDILATE therefore returns a new matrix where each point is replaced by the maximum value of its 8 neighbors (zero padded at the edges as needed), and the points where the original matrix is larger indicates a local maxima.

imdilate goes over each pixel and computes the max of the neighboring pixels centered around it and specified by the mask given (notice the zero in the middle to exclude the pixel itself). Then we compare the resulting image with the original to check whether each pixel is strictly greater than the max of its neighborhood. Make sure to read the documentation page on morphological operations:


注:转自http://hi.baidu.com/lewutian

  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您可以使用MATLAB的`polyfit`函数来拟合一个集,并使用`polyval`函数计算合的多项式在给定点的。接下来,您可以使用`plot`函数绘制原始点集和拟合的曲线。 下面是一个示例代码,演示如何使用`polyfit`拟合点集并绘制图像: ```matlab % 假设您有一个包含 x 和 y 坐标的点集 x = [1, 2, 3, 4, 5]; y = [2, 4, 6, 8, 10]; % 使用 polyfit 函数拟合点集,这里假设拟合多项式的阶数为1(线性拟合) coefficients = polyfit(x, y, 1); % 计算拟合曲线在给定点的值 x_fit = linspace(min(x), max(x), 100); % 在 x 范围内生成一些点 y_fit = polyval(coefficients, x_fit); % 绘制原始点集和拟合曲线 figure; plot(x, y, 'o', 'MarkerSize', 8); % 绘制原始点集 hold on; plot(x_fit, y_fit, 'r', 'LineWidth', 2); % 绘制拟合曲线 hold off; grid on; legend('观测点', '拟合曲线'); xlabel('x'); ylabel('y'); title('点集拟合与图像绘制'); ``` 在上面的代码中,我们首先定义了一组x和y坐标的点集。然后,使用`polyfit`函数拟合点集,并得到拟合多项式的系数。接下来,我们使用`polyval`函数计算拟合曲线在一系列新点上的值,并使用`plot`函数绘制原始点集和拟合曲线。最后,我们添加了网格、图例、坐标轴标签和标题。 请注意,上述示例中假设拟合的多项式为一次多项式(线性拟合),即通过一条直线拟合数据。您可以根据需要更改多项式的阶数来进行更高次的多项式拟合。 希望这能帮到您!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值