Why is the output of corr2 of two matrixes not same dimension as the input matrix?
显示 更早的评论
Hi, I am currently implementing an algorithm of segmentation based on flow orientation, and one of the equations in the paper uses autocorrelation and crosscorrelation of image gradient.
The code runs fine, but when I try to reshape the final values into a matrix with same dimension as the input image, I receive error. The following is my code:
close all
x = imread(imfile);
x = im2double(x);
%%Gradient - orientation estimate
[Gx,Gy] = imgradientxy(x);
gxx = xcorr2(Gx(:,:));
gyy = xcorr2(Gy(:,:));
gxy = xcorr2(Gx(:,:), Gy(:,:));
angle = 0.5.*atan((2.*gxy)./(gxx - gyy)); % Equation 4
temp = (angle< 0);
angle(temp) = angle(temp) + 2.*pi; % angle within 0 to 2pi
angle = angle / pi *180;
Equation 4:

I spent some time looking at the length of each entry, and it turned out that all the values after processing by corr2 are double of the initial size; i.e.
input_image = 450 x 369
gx (after imgradientxy) = 450 x 450
gxx = 899 x 750
angle = 899 x 737
My questions:
1) How to make the matrix after autocorrelation & cross correlation same as the initial image dimension?
2) Why is there a difference in the matrix dimension after processing by imgradientxy ?
Any help would be greatly appreciated, thanks!
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Image Transforms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!