# Interest Points Detection

## Moravec corner detection algorithm

### Method

This corner detection analyse each pixel of an image. It measure the similarities between different neighbour patchs thanks to a sum of squared differences). The similarity is strong if the SSD is weak.
The first stage is to do the derivative of a pixel (x,y) on the eight possible direction (u,v):
(1,0),(1,1),(0,1),(-1,1),(-1,0),(-1,-1),(0,-1),(1,-1)
then we make a smooth step on the result images. A 3x3 mean mask has been used.
Then we compute the C matrix which is the lowest value of the squared variation for each pixel.
To finish, we apply a local maxima detection algorithm.

### Program

```clear all; close all;   [filename, pathname] = uigetfile({'*.jpg;*.tif;*.png;*.gif;*.bmp','All Image Files';...           '*.*','All Files' },'mytitle',...           'C:\Work\myfile.jpg'); img = imread(filename); img=mean(img,3); [ligne colonne]=size(img); hori = [1 -1]; vert = hori'; diag1 = [1 0; 0 -1]; diag2 = [0 1; -1 0]; h = conv2(img,hori,'same'); v = conv2(img,vert,'same'); d1 = conv2(img,diag1,'same'); d2 = conv2(img,diag2,'same'); average = ones(3,3); % average filter hh = conv2(abs(h),average,'same'); vv = conv2(abs(v),average,'same'); dd1= conv2(abs(d1),average,'same'); dd2= conv2(abs(d2),average,'same'); clear h v d1 d2 matmin = cat(3, hh.^2, vv.^2, dd1.^2, dd2.^2); clear hh vv dd1 dd2 c=min(matmin,[],3); clear matmin threshold = max(max(c))*0.3; c(c<threshold)=0; [zmax,imax,zmin,imin]= extrema2(c); imshow(uint8(img)) hold nb=1000; if length(imax)>nb     nbcorner = nb; else     nbcorner=length(imax); end for i = 1 :  nbcorner %length(imax)     quotien= floor(imax(i)/ligne);     reste = imax(i) - quotien*ligne;     plot([quotien-2 quotien-2 quotien+2 quotien+2 quotien-2],...         [reste-2 reste+2 reste+2 reste-2 reste-2] ,'r','LineWidth',1) end  ```