Matlab 中基于傅立叶的字符识别
我有一个可以识别图像中字符位置的源代码。但有一行代码我不明白为什么?
[r c]=size(mainImage);
% Why rotate 90 degree? why multyply? why??? :-??
splash = real(ifft2(fft2(mainImage) .* fft2(rot90(object, 2), r, c)));
thresh = max(splash(:))-10;
for i=1:r
for j=1:c
if splash(i,j)>=thresh
splash(i,j)=1;
else
splash(i,j)=0;
end
end
end
I have a source code that could recognize a character's position in an image. but there is a line of code that i can't figure it out WHY?
[r c]=size(mainImage);
% Why rotate 90 degree? why multyply? why??? :-??
splash = real(ifft2(fft2(mainImage) .* fft2(rot90(object, 2), r, c)));
thresh = max(splash(:))-10;
for i=1:r
for j=1:c
if splash(i,j)>=thresh
splash(i,j)=1;
else
splash(i,j)=0;
end
end
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的 FFT 知识有点生疏,但我认为这本质上是计算互相关。
频域中的乘法相当于空间/时间域中的卷积。互相关相当于与反转信号进行卷积——这就是 180° 旋转试图做的事情。在我有点醉的头脑中,我无法判断这个特定的实现是否应该起作用。
Matlab 具有直接计算互相关的函数,但它们可能位于此代码的作者(或预期用户)无法使用的工具箱中。
My FFT knowledge is a bit rusty, but I think this is essentially calculating the cross-correlation.
Multiplication in the frequency domain is equivalent to convolution in the space/time domain. And cross-correlation is equivalent to convolution with the inverted signal -- which is what the 180° rotation is trying to do. Off the top of my slightly-drunk head I can't say whether this specific implementation should be expected to work.
Matlab has functions to calculate cross-correlations directly, but they may reside in toolboxes that weren't available to the author (or expected users) of this code.