[datatable-help] Harris Corner detection

Faino faino8 at gmail.com
Sat Mar 12 13:51:45 CET 2016


Hello, 

I'm trying to write code for the Harris corner detector in R. But I didn't
find any instructions for the R language, so I'm trying to rewrite this
matlab code. The problem for me is that I can't find similary functions as
filter2 or fspecial from matlab in R. Can anyone advise how to solve this
problem?

Matlab code thaht i want rewrite to R:

clear;
img = imread('seven.jpg'); 
if length(size(img))>2
img = rgb2gray(img);
end 
fx = [-1 0 1;-1 0 1;-1 0 1];
Ix = filter2(fx,img);
fy = [1 1 1;0 0 0;-1 -1 -1];
Iy = filter2(fy,img); 

Ix2 = Ix.^2;
Iy2 = Iy.^2;
Ixy = Ix.*Iy;
clear Ix;
clear Iy;

h= fspecial('gaussian',[7 7],2); 
Ix2 = filter2(h,Ix2);
Iy2 = filter2(h,Iy2);
Ixy = filter2(h,Ixy);
height = size(img,1);
width = size(img,2);
result = zeros(height,width); 
R = zeros(height,width);

Rmax = 0; 
for i = 1:height
for j = 1:width
M = [Ix2(i,j) Ixy(i,j);Ixy(i,j) Iy2(i,j)]; 
R(i,j) = det(M)-0.01*(trace(M))^2;
if R(i,j) > Rmax
Rmax = R(i,j);
end;
end;
end;
cnt = 0;
for i = 2:height-1
for j = 2:width-1
if R(i,j) > 0.1*Rmax && R(i,j) > R(i-1,j-1) && R(i,j) > R(i-1,j) && R(i,j) >
R(i-1,j+1) && R(i,j) > R(i,j-1) && R(i,j) > R(i,j+1) && R(i,j) > R(i+1,j-1)
&& R(i,j) > R(i+1,j) && R(i,j) > R(i+1,j+1)
result(i,j) = 1;
cnt = cnt+1;
end;
end;
end;
[posc, posr] = find(result == 1);
cnt ;
imshow(img);
hold on;
plot(posr,posc,'r.');





--
View this message in context: http://r.789695.n4.nabble.com/Harris-Corner-detection-tp4718538.html
Sent from the datatable-help mailing list archive at Nabble.com.


More information about the datatable-help mailing list