Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Implement the algorithm for harris interest point detection and test it on the

attached two images. Summarize your findings based upon the value of R
using:
I_rgb=imread('Image_2.jpg');
I=rgb2gray(I_rgb);

% Using Prewitt approximation for image gradients Ix, Iy


dx=[-1 0 1;-1 0 1; -1 0 1];
dy=[1 1 1;0 0 0; -1 -1 -1];

% Image Gradients of each pixel


Ix=conv2(double(I),dx,'same');
Iy=conv2(double(I),dy,'same');

% 6x6 Gaussian Filter for Harris


sigma=1;
G=fspecial('gaussian', max(1,fix(6*sigma)),sigma);

% Structure Tensor elements


Ix2=conv2(Ix.*Ix,G,'same');
Ixy=conv2(Ix.*Iy,G,'same');
Iy2=conv2(Iy.*Iy,G,'same');

% Threshold for decision


threshold=0.36;

% Trace of Structure Tensor Matrix


trace=Ix2+Iy2;

% Determinant of Structure Tensor Matrix


det=((Ix2.*Iy2)-(Ixy.^2));

% Eigen values of Structure Tensor Matrix


Lambda0=abs(0.5*((trace)+sqrt((trace.^2)-(4*det))));
Lambda1=abs(0.5*((trace)-sqrt((trace.^2)-(4*det))));

% Harris corner detector


R1=det-(0.04*(trace.^2));
minr = min(min(R1));
maxr = max(max(R1));
R1 = (R1 - minr) / (maxr - minr);%scaling to 0-1 range
maxima1 = ordfilt2(R1, 25, ones(5));%finding maxima
mask1 = (R1 == maxima1) & (R1 > threshold);%applying threshold
maxima1 = mask1.*R1;%extracting the intensities of corner points
[r1,c1]=find(maxima1);%finding the indices of corner points
subplot(221)
imshow(I)
hold on
plot(c1,r1,'r+')
title('Harris')

subplot(224)
imshow(I)
hold on
plot(c4,r4,'r+')
title('Shi-Tomasi')

You might also like