Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clc;
- clear;
- close;
- %grayImage = checkerboard(50);
- grayImage = imread('IMG_20141225_001413.jpg');
- grayImage = rgb2gray(grayImage);
- grayImage = im2double(grayImage);
- verticalMask = [-1 0 1;
- -2 0 2;
- -1 0 1]* 0.25;
- % Create a mask for deteting the horizontal edges
- horisontalMask = [-1 -2 -1;
- 0 0 0;
- 1 2 1]* 0.25;
- % Create a mask for Gaussian filter(is used to improve the result)
- gaussianFilter= fspecial('gaussian');
- K = 0.04; % The sensitivity factor used in the Harris detection algorithm (Used to detect sharp corners).
- % Get the gradient of the image [Ix,Iy], using the convulation function
- Ix = conv2(grayImage,verticalMask);
- Iy = conv2(grayImage,horisontalMask);
- % get the input arguments of the harris formula
- Ix2 = Ix.* Ix; % get Ix to the power of two
- Iy2 = Iy.* Iy; % get Iy to the power of two
- Ixy = Ix .* Iy; %get the Ixy by multiply Ix and Iy
- % Apply the gaussian filter to the the arguments
- Ix2 = conv2(Ix2,gaussianFilter);
- Iy2 = conv2(Iy2,gaussianFilter);
- Ixy = conv2(Ixy,gaussianFilter);
- % Enetr the arguments into the formula
- C = (Ix2 .* Iy2) - (Ixy.^2) - K * ( Ix2 + Iy2 ).^ 2;
- thresh = 0.000999;
- radius = 1;
- % Find maxima, threshold, and apply bordermask
- cimmx = (C>thresh);
- [r, c] = find(cimmx); % Return coordinates of corners
- figure, imshow(grayImage);
- hold on;
- plot(c, r, '+');
- hold off;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement