Implement a function for image correlation

5 ビュー (過去 30 日間)
shikun chen
shikun chen 2017 年 10 月 30 日
編集済み: shikun chen 2017 年 10 月 30 日
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?

回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by