Implement a function for image correlation

2 views (last 30 days)
shikun chen
shikun chen on 30 Oct 2017
Edited: shikun chen on 30 Oct 2017
Hi, I tried to implement a function, which can calculate the correlation of a matrix within a pattern operator function.
function[output] = correlation[input,pattern]
% Calculate the half side lenghts of the operator pattern.
h1 = (length(pattern)-1)/2;
h2 = h1;
% Implement the correlation.
[m,n] = size(input);
for i = 1:m
for j = 1:n
output(i,j) = 0
for u = -h1:h1
for v = -h2:h2
output(i,j) = output(i,j)+pattern(u,v)*input(i+u,j+v);
end
end
end
end
I want to calculate the inner values and setting the outer values to zeros. But i was stuck by the negative index, Any suggestion?

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!