Created
March 11, 2018 19:31
-
-
Save SohanChy/fbe18599e6ebae9a4bccbd79655d36b4 to your computer and use it in GitHub Desktop.
CVPR MATLAB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I = imread('dog.jpg'); | |
I = rgb2gray(I); | |
X = [1 0 0; | |
0 1 0; | |
0 0 1]; | |
Z = sohan_conv(I,X); | |
imshow(I); | |
figure,imshow(Z); | |
function y = sohan_conv(A,X) | |
X = sohan_xflip(X); | |
X = sohan_yflip(X); | |
Z = sohan_correlation(A,X); | |
y = Z; | |
end | |
function y = sohan_yflip(X) | |
y = [ X(3,1) X(3,2), X(3,3); X(2,1) X(2,2), X(2,3); X(1,1) X(1,2), X(1,3)]; | |
end | |
function y = sohan_xflip(X) | |
y = [ X(1,3) X(1,2) X(1,1); X(2,3) X(2,2) X(2,1); X(3,3) X(3,2) X(3,1)]; | |
end | |
function y = sohan_correlation(A,X) | |
[rows,cols] = size(A); | |
rows = rows -1; | |
cols = cols - 1; | |
for row = 2:(rows) | |
for col = 2:(cols) | |
i = A(row-1,col-1) * X(1,1); | |
i = i + A(row-1,col) * X(1,2); | |
i = i + A(row-1,col+1) * X(1,3); | |
i = i + A(row,col-1) * X(2,1); | |
i = i + A(row,col) * X(2,2); | |
i = i + A(row,col+1) * X(2,3); | |
i = i + A(row+1,col-1) * X(3,1); | |
i = i + A(row+1,col) * X(3,2); | |
i = i + A(row+1,col+1) * X(3,3); | |
Y(row,col) = ceil(abs(i)); | |
end | |
end | |
y = Y; | |
end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
InputImg = imread('3d-sahpes.jpg'); | |
%InputImg = imread('dog4.jpg'); | |
img = imresize(InputImg, [400 400]); | |
img = rgb2gray(img); | |
height = size(img,1); | |
width = size(img,2); | |
[xx, yy] = meshgrid(-3:3, -3:3); | |
sigma = 1; | |
Gxy = exp(-(xx .^ 2 + yy .^ 2) /2); | |
Gx = xx .* exp(-(xx .^ 2 + yy .^ 2) / (2 * sigma ^ 2)); | |
Gy = yy .* exp(-(xx .^ 2 + yy .^ 2) / (2 * sigma ^ 2)); | |
Ix = conv2(Gx, img); | |
Iy = conv2(Gy, img); | |
Ix2 = Ix .^ 2; | |
Iy2 = Iy .^ 2; | |
Ixy = Ix .* Iy; | |
Rvals = zeros(height,width); | |
total = 0; | |
count = 0; | |
margin = 4; | |
for i = margin:height-margin | |
for j = margin:width-margin | |
M = [ | |
Ix2(i,j) Ixy(i,j); | |
Ixy(i,j) Iy2(i,j) | |
]; | |
%detM = det(M); | |
detM = M(1,1) * M(2,2) - M(1,2) * M(2,1); | |
traceR = - 0.01*(trace(M))^2; | |
Rvals(i,j) = detM - traceR; | |
if Rvals(i,j) > 0 | |
total = total + Rvals(i,j); | |
count = count + 1; | |
end | |
end | |
end | |
threshold = (total/(count * .08)) ; | |
imshow(img); | |
hold on | |
for i = margin:height-margin | |
for j = margin:width-margin | |
if Rvals(i,j) > threshold && Rvals(i,j) > Rvals(i,j-1) && Rvals(i,j) > Rvals(i,j+1) && Rvals(i,j) > Rvals(i-1,j-1) && Rvals(i,j) > Rvals(i-1,j) && Rvals(i,j) > Rvals(i-1,j+1) && Rvals(i,j) > Rvals(i+1,j-1) && Rvals(i,j) > Rvals(i+1,j) && Rvals(i,j) > Rvals(i+1,j+1) | |
plot(j,i,'gx') | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment