How to do a Fourier analysis with a mask?
13 views (last 30 days)
Show older comments
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 Comments
Walter Roberson
on 9 Sep 2023
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.
Answers (2)
Walter Roberson
on 7 Sep 2022
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 Comments
Walter Roberson
on 8 Sep 2022
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
on 13 Sep 2022
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
on 14 Sep 2022
Edited: Bruno Luong
on 14 Sep 2022
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 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!