本文介绍了在Matlab 2D DFT fft2()函数中读取点的方向和频率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Matlab和函数fft2()很熟悉.在这个玩具示例中,我的目标是产生以下256 x 256 png图像的2D DFT:

I am getting familiarized with Matlab 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));

A是一个256 x 256矩阵,可以从中计算幅度和相位.

A is a 256 x 256 matrix from which amplitude and phase can be calculated.

问题是如何提取方向(θ)和频率(例如像素/周期)?

在SLEUTHEYE回答后比较MATLAB和IMAGEJ输出的示例:

EXAMPLE COMPARING MATLAB AND IMAGEJ OUTPUTS AFTER SLEUTHEYE'S ANSWER:

使用ImageJ:

Frequency = 10.24 pixels/cycle (25 cycles)
Theta (direction) = 16.26 degrees
Real part = -1.255
Imaginary part = 10.142
Phase = arctan(10.142 / -1.255) = -82.95 degrees
Magnitude = sqrt(10.142^2 + 1.255^2) = 10.2194

使用Matlab:

Im = imread('circ.png');
pkg load image
Im = rgb2gray(Im);

A = fft2(double(Im) / 255);
Ashifted = fftshift(A);
Ashifted(121,153)

i = 121;
j = 153;

center = size(A) / 2 + 1;
dx = (j - center(2)) / size(A,2);
dy = (center(1) - i - 1) / size(A,1);

direction = (atan2(dy, dx))
dir_degrees = direction * (360 / (2*pi))
frequency = 1 /sqrt(dx*dx + dy*dy)

输出:

ans =  -1.2553 + 10.1425i
direction =  0.28379
dir_degrees =  16.260
frequency =  10.240

推荐答案

我认为这是对,它描述了您对 ImageJ ,可以直接读取方向和频率参数.

I assume this is a follow up on this question which describe your use of ImageJ which provides direct readings of the direction and frequency parameters.

假设您有一个特定的像素A(i,j),那么可以使用以下方法获得像素/周期的方向和频率(与ImageJ相似):

Let say you have a particular pixel A(i,j), then the direction and frequency in pixels/cycle (as similarly obtained by ImageJ) can be obtained using the following:

center = size(A)/2 + 1;
dx = (j-center(2))/size(A,2);
dy = (center(1)-i-1)/size(A,1);

direction = atan2(dy, dx); % in radians
frequency = 1/sqrt(dx*dx + dy*dy);

这篇关于在Matlab 2D DFT fft2()函数中读取点的方向和频率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 04:09