贴一下 计算机视觉课的作业
有时候 需要用下
function F = DetectCorner(I, threshold, sigma) %Harris Corner Detect %by:LiFeiteng %Version1.0 灰度图像 2013/5/08 %Version1.1 彩色图像 2013/5/13 %存在问题:没有实现跟 corner 相似的接口,对噪声也不能很好的处理<checkerboard(50,2,2)>。 if nargin < 3 sigma = 0.01; end if nargin < 2 threshold = 0.6; %实验表明 对此参数不敏感 sigma = 0.01; %对此参数敏感 end if size(I,3)==3 I = rgb2gray(I); end W = fspecial('gaussian', [5 5], 2); I = double(I); I = imfilter(I, W, 'same'); Ix = imfilter(I,[-1 0 1], 'same'); Iy = imfilter(I,[-1 0 1]', 'same'); A = Ix.^2; B = Ix.*Iy; C = Iy.^2; A = imfilter(A, W, 'same'); B = imfilter(B, W, 'same'); C = imfilter(C, W, 'same'); %F = (A.*C-B.*B)./(A+C+eps); F = (A.*C-B.*B)-threshold*(A+C); F = F/max(F(:)); F = F.*(F>sigma); %F = F.*(F>0.01); cor = 10; F(1:cor,1:cor)=0; F(1:cor,end-cor:end)=0;F(end-cor:end,1:cor)=0;F(end-cor:end,end-cor:end)=0; F = imregionalmax(F, 8); [row, col] = find(F==1); F = [col, row]; end
img = imread('lena_gray.tif'); img = imread('corner.jpg'); %img = checkerboard(50,2,2); % img = rgb2gray(img); img = imnoise(img,'gaussian'); figure(1),imshow(img, []) F = DetectCorner(img,0.6); figure(1),hold on, plot(F(:,1), F(:,2), 'y.')