How to do a Fourier analysis with a mask?
14 ビュー (過去 30 日間)
古いコメントを表示
I want to exclude the transparent parts of PNG pictures in Fourier analysis.
I just don't know how to use the alpha mask given by imread to do Fourier analysis analysis through fft2 (which needs the input images being rectangular) appropriately when the transparent part is not rectangle.
Do you know how to exclude transparent parts which are not rectangles of PNG picture?
Thank you very much!
5 件のコメント
Walter Roberson
2023 年 9 月 9 日
You should read the terms and conditions for using the MATLAB Answers facility. You had to click to signify acceptance of the terms in order to post your question.
回答 (2 件)
Walter Roberson
2022 年 9 月 7 日
Use
[A,MAP,ALPHA] = imread(...)
syntax. You can then threshold based on alpha to determine whether to include a pixel or not.
However... your fft2 depends upon the image being rectangular. It is not going to be easy to ignore the pixels outside the mask when you use fft2 for phase analysis.
Also, we do not recommend naming a variable image due to the conflict with the important MATLAB function named image
3 件のコメント
Walter Roberson
2022 年 9 月 8 日
Taking the fourier transform of an interval of a continuous function is equivalent to taking the fourier transform of a rectangular pulse multiplied by the function. The fourier transform of a product of functions is the convolution of the fourier transform of the two functions.
So in theory if you could define the opaque area as a disk instead of by mask you could take the 2D fft of the full image, and the 2D fft of the disk, and convolve them. You would probably have to be careful with the fft shift for the convolvution.
Walter Roberson
2022 年 9 月 13 日
I looked at the code. The option for separating the image into foreground and background and matching the two separately, only applies to Luminance and Histogram matching, and does not apply to spectral matching (fft)
Bruno Luong
2022 年 9 月 14 日
編集済み: Bruno Luong
2022 年 9 月 14 日
Discrete Fourier transform always has unwanted artefact on finite region, due to boundary wrapping jumps, even for rectangular region.
The way people overcome is to multiply the data by window functions https://en.wikipedia.org/wiki/Window_function to smooth out the boundary, then take the FFT to get a less affectef spectrum.
You could do the same with you disk-region image by (1) multiplying the image with a tensorial of two window functions then (2) taking the FFT on the bounding box rectangle to find the spectrum.
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!