資源簡介
計算機視覺Harris角點檢測算法, 利用matlab實現,簡單易懂。
代碼片段和文件信息
img?=?imresize3(imread(‘pic.png‘)?[1000?1000?3]);
corn_thresh?=?0.18;
interactive?=?1;
%?function?[locscornerness]?=?detHarrisCorners(img?corn_thresh?interactive)
%%?parse?the?parameters
if(~exist(‘corn_thresh‘‘var‘))
????corn_thresh?=?0.01;
end
if(~exist(‘interactive‘‘var‘))
????interactive?=?0;
end
if(size(img3)>1)
????img?=?rgb2gray(img);
end
%%
[nrnc]?=?size(img);
%Filter?for?horizontal?and?vertical?direction
fx?=?[1?0?-1];
fy?=?[1;?0;?-1];
%?Convolution?of?image?with?dx?and?dy
Ix?=?conv2(img?fx?‘same‘);
Iy?=?conv2(img?fy?‘same‘);
if(interactive)
????figure(1);?%?imagesc?對圖像進行縮放后顯示
????subplot(121);?imagesc(Ix);?axis?equal?image?off;?colormap(‘gray‘);?title(‘Ix‘);
????subplot(122);?imagesc(Iy);?axis?equal?image?off;?colormap(‘gray‘);?title(‘Iy‘);
????cdata?=?print(‘-RGBImage‘);
????%imwrite(cdata?fullfile(‘corner‘?[name?‘-grad.png‘]));
????imwrite(cdata?‘/Users/liziniu/Downloads/計算機視覺與模式識別/角點檢測/affine_transform/corner/grad.png‘);
end
%%?Raw?Hessian?Matrix
%?Hessian?Matrix?Ixx?Iyy?Ixy
Ixx?=?Ix.*Ix;
Ixy?=?Ix.*Iy;
Iyy?=?Iy.*Iy;
if(interactive)
????figure(2);?title(‘Before?Smoothing‘);
????subplot(221);?imagesc(Ixx);?axis?equal?image?off;?colormap(‘gray‘);?title(‘Ixx‘);
????subplot(222);?imagesc(Ixy);?axis?equal?image?off;?colormap(‘gray‘);?title(‘Ixy‘);
????subplot(223);?imagesc(Ixy);?axis?equal?image?off;?colormap(‘gray‘);?title(‘Ixy‘);
????subplot(224);?imagesc(Iyy);?axis?equal?image?off;?colormap(‘gray‘);?title(‘Ixy‘);
????cdata?=?print(‘-RGBImage‘);
????%imwrite(cdata?fullfile(‘corner‘?[name?‘-rawHessian.png‘]));
????imwrite(cdata?‘/Users/liziniu/Downloads/計算機視覺與模式識別/角點檢測/affine_transform/corner/rawHessian.png‘);
end
%%?Gaussian?filter?definition?(https://en.wikipedia.org/wiki/Canny_edge_detector)
G?=?[2?4?5?4?2;?4?9?12?9?4;5?12?15?12?5;4?9?12?9?4;2?4?5?4?2];
G?=?1/159.*?G;
%?Convolution?with?Gaussian?filter
Ixx?=?conv2(Ixx?G?‘same‘);
Ixy?=?conv2(Ixy?G?‘same‘);
Iyy?=?conv2(Iyy?G?‘same‘);
if(interactive)
????figure(3);?title(‘After?Smoothing‘);
????subplot(221);?imagesc(Ixx);?axis?equal?image?off;?colormap(‘gray‘);?title(‘Ixx‘);
????subplot(222);?imagesc(Ixy);?axis?equal?image?off;?colormap(‘gray‘);?title(‘Ixy‘);
????subplot(223);?imagesc(Ixy);?axis?equal?image?off;?colormap(‘gray‘);?title(‘Ixy‘);
????subplot(224);?imagesc(Iyy);?axis?equal?image?off;?colormap(‘gray‘);?title(‘Iyy‘);
????cdata?=?print(‘-RGBImage‘);
????%imwrite(cdata?fullfile(‘corner‘?[name?‘-smoothHessi
- 上一篇:最大似然法_監督分類_遙感影像
- 下一篇:RPCA圖像去噪算法
評論
共有 條評論