用于计算 FFT_2D 的 2D double* 指针中图像的像素值
我想计算图像的 FFT,我读取图像,ITK SmartPointer 称为“imagen”。 我用于计算 FFT (fftw_plan_dft_r2c_2d) 的函数的输入需要一个 2D double* 指针作为输入。因此,我这样做:
double *in = (double*) imagen.GetPointer(); // conversión de itk.smartpointer --> double*.
但是当我尝试访问图像的像素值时,它们没有定义 “图像”的像素类型是双精度的:
typedef double PixelType;
typedef itk::Image < PixelType, 2> ImageType;
ImageType::Pointer imagen;
并且图像是使用 Qt 通过用户界面从框架中读取的:
imagen=ui.imageframe->imagereader;
任何人都可以帮我解决这个问题吗?我需要将图像的值放在 2D double* 指针中以计算 fft。
干杯并感谢您的提前帮助!
Antonio Gómez Barquero
编辑
我已经解决了我的问题,发布在下面,但现在的问题是将结果转换为二维矩阵,直到执行时才知道它的第二维,因为图像是在执行期间加载而不是在编译期间加载,有什么提示吗?谢谢!
解决方案
double *in;
ImageType::IndexType pixelIndex;
ImageType::PixelType pixelValue;
for ( int x = 0; x<ancho; x++){
for (int y = 0; y<alto; y++){
pixelIndex[0] = x; //x position
pixelIndex[1] = y; //y position
ImageType::PixelType pixel2 = imagen->GetPixel(pixelIndex);
*(in+x*ancho+y) = static_cast <double> (imagen->GetPixel(pixelIndex));
}
}
I want to calculate the FFT of an image, I read the image, and the ITK SmartPointer is called “imagen”.
The input of the function I use for calculating the FFT (fftw_plan_dft_r2c_2d) need a 2D double* pointer as input. Because of that I do that:
double *in = (double*) imagen.GetPointer(); // conversión de itk.smartpointer --> double*.
But when I try to access the values of pixels of the image they are not defined
The pixeltype of ‘image’ is double:
typedef double PixelType;
typedef itk::Image < PixelType, 2> ImageType;
ImageType::Pointer imagen;
And the image is read from a frame trhoug the user interface using Qt:
imagen=ui.imageframe->imagereader;
Can anyone help me with this? I need to have the values of the image in a 2D double* pointer for calculating the fft.
Cheers and thanks for your help in advanced!
Antonio Gómez Barquero
EDITED
I have solved my problem, is posted below, but now the problem is to convert the result to a 2D matrix without knowing the second dimension of it until the execution time, because the image is loaded during the execution not during compilation, any tips?? THANKS!
SOLUTION
double *in;
ImageType::IndexType pixelIndex;
ImageType::PixelType pixelValue;
for ( int x = 0; x<ancho; x++){
for (int y = 0; y<alto; y++){
pixelIndex[0] = x; //x position
pixelIndex[1] = y; //y position
ImageType::PixelType pixel2 = imagen->GetPixel(pixelIndex);
*(in+x*ancho+y) = static_cast <double> (imagen->GetPixel(pixelIndex));
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ITK 还提供 FFT。
该框架的示例是:
http://www.vtk.org/Wiki/ITK/Examples/SpectralAnalysis/VnlFFTRealToComplexConjugateImageFilter
还有另一个使用 FFTW 的非常相似的选项。只需将 USE_FFTW 标志设置为 on 即可构建 ITK。 (注意:USE_FFTW 选项位于“高级”设置下,用于固化 cmake 配置步骤)。
来自 ITK 邮件列表:http://old.nabble。 com/如何使用-FFTW-with-ITK-td19531608.html
ITK also has FFT's available.
Example of the framework is:
http://www.vtk.org/Wiki/ITK/Examples/SpectralAnalysis/VnlFFTRealToComplexConjugateImageFilter
There is another very very similar options to use FFTW. Just build ITK with the USE_FFTW flag set to on. (NOTE : The USE_FFTW option is under "Advanced" settings curing the cmake configuration step).
From ITK Mailing List: http://old.nabble.com/how-to-use-FFTW-with-ITK-td19531608.html