http://www.imagemagick.org/Usage/fourier/fft_math/
The kernel I'm using is a circle generated using IM. This code snippet, modified from the above URL. This is what it's trying to do:
Line 1: creates the circle, saves it to circle.png, then fft's it into magnitude/phase
Line 2: finds the mean (DC) of the circle image and divides by that mean. This is most probably because the FFT is unnormalized and will multiply by a constant, so this operation is set to undo that
Line 3: Pulls in the image I want to convolve and crops the top left 128x128 of it, then fft's it
Line 4: performs the multiplication of the magnitudes
Line 5: performs the addition of phases. I'm not too sure why it is adding gray50 and what the -flatten is for.
Line 6: removes the unnecessary layers, ift's and saves.
Code: Select all
convert \( -size 128x128 xc:black -fill white -draw "circle 64,64 70,64" -write circle.png -roll -64-64 -fft \)\
\( -clone 0 -crop 1x1+64+64 +repage -scale 128x128 -clone 0 -compose divide -composite \) -swap 0 +delete \
\( image.jpg -crop 128x128+0+0 -fft \) \
\( -clone 0,2 -compose multiply -composite \) \
\( -clone 1,3 -compose add -background gray50 -flatten \) \
-delete 0-3 -ift -compress none image_convolved1.png
However if I do this:
Code: Select all
convert circle.png -roll -64-64 -fft\
\( -clone 0 -crop 1x1+64+64 +repage -scale 128x128 -clone 0 -compose divide -composite \) -swap 0 +delete \
\( image.jpg -crop 128x128+0+0 -fft \) \
\( -clone 0,2 -compose multiply -composite \) \
\( -clone 1,3 -compose add -background gray50 -flatten \) \
-delete 0-3 -ift image_convolved2.png
The only difference is that it uses the circle saved in the above operation from the file, rather than being created by IM directly.
Can someone explain why the first one fails, but the second works?
Thanks.