Matlab实现SUSAN角点检测
时间: 2023-10-18 19:12:14 浏览: 112
lhmSUSAN.rar_matlab图片特征_特征点检测_角点_角点 susan_角点检测
SUSAN(Smallest Univalue Segment Assimilating Nucleus)算法是一种基于像素灰度值的角点检测算法,它可以检测出图像中的角点和边缘。下面是Matlab实现SUSAN角点检测的步骤:
1. 读入图像并转化为灰度图像
```matlab
img = imread('lena.jpg');
gray_img = rgb2gray(img);
```
2. 初始化参数
```matlab
r = 3; % 邻域半径
t = 27; % 阈值
```
3. 计算像素与邻域内像素的灰度值差异
```matlab
[m, n] = size(gray_img);
susan_img = zeros(m, n);
for i = r+1:m-r
for j = r+1:n-r
% 计算邻域内像素与中心像素的灰度值差异
diff = gray_img(i-r:i+r,j-r:j+r) - gray_img(i,j);
% 计算像素灰度值的方差
var = sum(sum(diff.^2))/(numel(diff)-1);
% 计算像素与邻域内像素的灰度值差异的均值
mean_diff = sum(sum(abs(diff)))/numel(diff);
% 计算SUSAN函数值
susan_img(i,j) = mean_diff/var;
end
end
```
4. 根据SUSAN函数值进行角点检测
```matlab
corners = zeros(m, n);
for i = r+1:m-r
for j = r+1:n-r
% 判断SUSAN函数值是否超过阈值
if susan_img(i,j) > t
% 标记为角点
corners(i,j) = 1;
end
end
end
```
5. 可视化结果
```matlab
figure;
subplot(1,2,1);
imshow(img);
title('原始图像');
subplot(1,2,2);
imshow(corners);
title('SUSAN角点检测结果');
```
完整的代码如下:
```matlab
img = imread('lena.jpg');
gray_img = rgb2gray(img);
r = 3;
t = 27;
[m, n] = size(gray_img);
susan_img = zeros(m, n);
for i = r+1:m-r
for j = r+1:n-r
diff = gray_img(i-r:i+r,j-r:j+r) - gray_img(i,j);
var = sum(sum(diff.^2))/(numel(diff)-1);
mean_diff = sum(sum(abs(diff)))/numel(diff);
susan_img(i,j) = mean_diff/var;
end
end
corners = zeros(m, n);
for i = r+1:m-r
for j = r+1:n-r
if susan_img(i,j) > t
corners(i,j) = 1;
end
end
end
figure;
subplot(1,2,1);
imshow(img);
title('原始图像');
subplot(1,2,2);
imshow(corners);
title('SUSAN角点检测结果');
```
阅读全文