fft 和数组到图像/图像到数组转换
我想对图像进行傅里叶变换。 但是如何将图片转为数组呢? 之后我想我应该使用 numpy.fft.rfft2 进行转换。 以及如何从数组变回图像? 提前致谢。
I want to make a fourier-transformation of an image.
But how can I change the picture to an array?
And after this I think I should use numpy.fft.rfft2 for the transformation.
And how to change back from the array to the image?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 PIL 库来加载/保存图像以及与 numpy 数组之间的转换。
我在上面使用了
abs
,因为 FFT 的结果具有复数值,因此将其直接转换为图像并没有多大意义。转换为灰度后,FFT 仅在单个通道上完成 - 您可以选择另一种方式来选择通道,或将正确的axes
参数传递给rfft2
然后提取您需要的频道。编辑:
要执行逆FFT并取回原始图像,以下方法对我有用:
You can use the PIL library to load/save images and convert to/from numpy arrays.
I used
abs
above because the result of the FFT has complex values so it doesn't really make sense to convert it directly to an image. The conversion to grayscale is done so that the FFT is done on a single channel only - you can choose another way to pick a channel instead, or pass the correctaxes
parameter torfft2
and later extract the channel you need.Edit:
To also perform an inverse FFT and get back the original image, the following works for me: