从Matlab/Octave fft2()函数输出中读出特定点 [英] Reading out specific points off the Matlab / Octave fft2() function output
问题描述
我已经熟悉Octave和功能fft2()
.在这个玩具示例中,我的目标是产生以下256 x 256 png图像的2D DFT:
I am getting familiarized with Octave and the function fft2()
. In this toy example, I am aiming at producing the 2D DFT of the following 256 x 256 png image:
为了易于理解输出,我尝试将此图像转换为256 x 256图像,消除了颜色信息:
To be able to understand the output easily, I try to convert this image into a 256 x 256 image, eliminating color information:
Im = imread('circ.png');
pkg load image
Im = rgb2gray(Im);
figure, imshow(Im)
在完成簿记准备之后,我运行:
After this bookkeeping preliminaries I run:
A = fft2(double(Im));
好.现在,我拍摄相同的图像,并使用ImageJ分析它,检查点(157, 96)
处的输出,如下所示:
OK. Now I take the same image, and analyze it with ImageJ, checking the output at point (157, 96)
, like this:
所以幅度将是sqrt(7.448^2 + 10.458^2) = 12.83
相位arctan(-10.458 / 7.448) = 54.54 degrees
.
问题是,如何从fft2()
输出中获取这些值?
The question is, How can I get these values out of the fft2()
output?
如果有所作为,这就是我绘制八度输出2D DFT的方式:
In case it makes a difference, this is how I plotted the Octave output 2D DFT:
subplot(132);
h = imshow(abs(fftshift(A)),[24 100000]);
h2 = get(h,'Parent');
set(h2,'YDir','Normal');
axis equal tight;
title("2D FFT Magnitude");
subplot(133);
h = imshow(angle(fftshift(A)),[-pi pi]);
h2 = get(h,'Parent');
set(h2,'YDir','Normal');
axis equal tight;
title("2D FFT Phase");
这是ImageJ中的过程:
and this is the process in ImageJ:
推荐答案
以下是一些观察结果,它们可以澄清所使用的缩放比例:
Here are a few observations which should clarify the scaling used:
- ImageJ的X和Y位置基于0,而Matlab的索引基于1.
- 增加ImageJ的X位置对应于增加Matlab中的列索引,增加ImageJ的Y位置对应于增加Matlab中的行索引,因此在ImageJ中的
(X,Y)
坐标对将在Matlab的索引(Y+1,X+1)
处找到. - ImageJ在图像的中间显示频率分量为0的图像,因此有效地进行了等效于
fftshift(Im)
的测量
- ImageJ将0-255的灰度值缩放为0.0-1.0范围内的浮点值(即除以255缩放所有值)
- ImageJ's X and Y positions are 0-based whereas Matlab's indexing is 1-based.
- Incrementing ImageJ's X position corresponds to incrementing the column index in Matlab, and incrementing ImageJ's Y position corresponds to incrementing the row index in Matlab, so that an
(X,Y)
coordinate pair in ImageJ will be found at index(Y+1,X+1)
in Matlab. - ImageJ displays the image with the 0 frequency component in the middle of the image, so measurements are effectively made on the equivalent of
fftshift(Im)
- ImageJ scales the 0-255 grayscale values to floating point values in the 0.0-1.0 range (i.e. scaling all values by dividing by 255)
因此,请记住:
>> Ashifted = fftshift(A);
>> Ashifted(97,158)/255
ans = 7.4484 - 10.4582i
>> Ashifted(93,165)/255
ans = 12.1928 - 4.9850i
分别与您在位置(X,Y) = (157,96)
和(X,Y) = (164,92)
处对实部和虚部的测量值完全对应.
which correspond exactly to your illustrated measurements of the real and imaginary parts at positions (X,Y) = (157,96)
and (X,Y) = (164,92)
respectively.
请注意,通过FFT的线性属性,您还可以对输入进行除法并获得相同的结果:
Note that by the linearity property of the FFT, you could also divide the input and get the same results:
A = fft2(double(Im)/255.0);
>> Ashifted = fftshift(A);
>> Ashifted(97,158)
ans = 7.4484 - 10.4582i
>> Ashifted(93,165)
ans = 12.1928 - 4.9850i
这篇关于从Matlab/Octave fft2()函数输出中读出特定点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!