potential bug using MIFF for FFT in IM 6.4.1-1 Q16-HDRI
Posted: 2008-05-09T17:13:29-07:00
Hi,
I have been testing Sean Burke's FFT and have run into a potential issue using MIFF for storage of the FFT component images (real, imaginary, magnitude and phase) when converting the real and imaginary to phase using -fx. The phase image gets created but has bad values in it. Whereas, if I use PFM for storage, it all works fine. I wanted to inform you of this regarding the MIFF format. Also there are some oddities that I wanted to present and see if you could clarify them for me.
Here is what I have done:
I started with the following image:
I then did an FFT to create the real and imaginary components. Following that I converted the real and imaginary components to magnitude and phase using:
convert real.miff imaginary.miff -fx "sqrt(u*u+v*v)" magnitude.miff
convert real.miff imaginary.miff -fx "atan2(v,u)" phase.miff
Then I did an IFT using these magnitude and phase images, but the result is bad
Likewise using PFM format
convert real.pfm imaginary. pfm -fx "sqrt(u*u+v*v)" magnitude. pfm
convert real.pfm imaginary. pfm -fx "atan2(v,u)" phase. pfm
Here the result gave an image that was comparable to the original.
Note that there is NO scaling in creating the component images when using HDRI in the FFT routines.
Here are my intermediate and resulting images (after scaling to stretch to full dynamic range and converting to png for viewing). Note also the -verbose info: that I present as that is where there are some very strange things going on that I need clarification. The verbose info is coming from the MIFF or PFM images, not the PNG.
________________________________________________________
MIFF RESULTS:
real:
Depth: 32/16-bit
Channel depth:
gray: 16-bit
Channel statistics:
gray:
min: -997.818 (-0.0152257)
max: 1023.98 (0.015625)
mean: 2.26895e-09 (3.46219e-14)
standard deviation: 31.5035 (0.000480712)
Min and Max seem reasonable:
imaginary:
Depth: 32/16-bit
Channel depth:
gray: 16-bit
Channel statistics:
gray:
min: -46.3475 (-0.000707218)
max: 46.3475 (0.000707218)
mean: 5.3717e-12 (8.19669e-17)
standard deviation: 5.61079 (8.56152e-05)
Min and Max seem reasonable
Real/Imaginary convert to Magnitude:
Depth: 16-bit
Channel depth:
gray: 16-bit
Channel statistics:
gray:
min: 0 (0)
max: 1024 (0.0156252)
mean: 5.63159 (8.59326e-05)
standard deviation: 31.5031 (0.000480706)
Min and Max seem reasonable, BUT note that the Depth is reported as 16-bit and NOT 32/16-bit as are the real and imaginary images. Why is this? Is this a bug?
Real/Imaginary convert to Phase:
Depth: 16-bit
Channel depth:
gray: 16-bit
Channel statistics:
gray:
min: 0 (0)
max: 65535 (1)
mean: 21188.2 (0.323312)
standard deviation: 29190 (0.44541)
Min and Max are completely wrong. The phase should vary between -pi and +pi (NOT 0-QuantumRange). Also the same issue with the Depth reported as 16-bit and not 32/16-bit.
Resulting IFT from converted MIFF magnitude and phase:
This is not even close to the original image.
_______________________________________________________
PFM RESULTS:
real:
Depth: 32/16-bit
Channel depth:
gray: 16-bit
Channel statistics:
gray:
min: -997.818 (-0.0152257)
max: 1023.98 (0.015625)
mean: 2.26895e-09 (3.46219e-14)
standard deviation: 31.5035 (0.000480712)
Min and Max seem reasonable:
imaginary:
Depth: 32/16-bit
Channel depth:
gray: 16-bit
Channel statistics:
gray:
min: -46.3475 (-0.000707218)
max: 46.3475 (0.000707218)
mean: 5.3717e-12 (8.19669e-17)
standard deviation: 5.61079 (8.56152e-05)
Min and Max seem reasonable
Real/Imaginary convert to Magnitude:
Depth: 32/16-bit
Channel depth:
gray: 16-bit
Channel statistics:
gray:
min: 0 (0)
max: 1023.98 (0.015625)
mean: 5.63846 (8.60374e-05)
standard deviation: 31.4985 (0.000480637)
Min and Max seem reasonable, BUT note that the Depth is reasonably reported as 32/16-bit as expected.
Real/Imaginary convert to Phase:
Depth: 32/16-bit
Channel depth:
gray: 16-bit
Channel statistics:
gray:
min: -205080 (-3.12932)
max: 205080 (3.12932)
mean: 1.19035 (1.81636e-05)
standard deviation: 104241 (1.59061)
Min and Max are are between -pi and +pi, BUT as fractional values (where it should be in the range of 0-1) and I would have expected them to be the raw value. Also here the Depth is properly reported as 32/16-bit
_____________________
ASSIDE: Note when doing an FFT DIRECTLY to magnitude and phase in MIFF format and looking at the verbose statistics for the PHASE (whose image does look correct), I get the following verbose statistics for the PHASE:
Depth: 32/16-bit
Channel depth:
gray: 16-bit
Channel statistics:
gray:
min: -3.12932 (-4.77504e-05)
max: 3.12932 (4.77504e-05)
mean: 1.81636e-05 (2.77158e-10)
standard deviation: 1.59061 (2.42712e-05)
Note that the values -pi to +pi are now in the raw values not the fractional values.
_____________________
Getting back to the resulting IFT from the CONVERTED PFM magnitude and phase:
This is very close to the original image.
______________________________________________________
Thus:
1) Is there a bug in MIFF storage for data calculated from -fx in Q16-HDRI? (See verbose info for MIFF phase)
2) Why is the conversion from MIFF depth 32/16-bit to changed to MIFF depth 16-bit when output from -fx, but when using PFM it stays as 32/16-bit when output from -fx?
3) Why is the phase between -pi and +pi in the raw value for MIFF, but in the fractional values for PFM? (See verbose info for PFM phase vs MIFF).
Thanks for your help on this.
Here are links to the original MIFF and PFM images in case you need them to test for yourself:
http://www.fmwconcepts.com/misc_tests/F ... _real.miff
http://www.fmwconcepts.com/misc_tests/F ... t_real.pfm
http://www.fmwconcepts.com/misc_tests/F ... inary.miff
http://www.fmwconcepts.com/misc_tests/F ... ginary.pfm
http://www.fmwconcepts.com/misc_tests/F ... t_mag.miff
http://www.fmwconcepts.com/misc_tests/F ... ft_mag.pfm
http://www.fmwconcepts.com/misc_tests/F ... phase.miff
http://www.fmwconcepts.com/misc_tests/F ... _phase.pfm
Fred
P.S. Another piece of information: I just changed my script to do Normalized Cross Correlation (template matching) from using MIFF for FFT storage and computation storage to PFM and got much better results -- more accurate in finding the match point and the NCC surface was much more discriminating.
I have been testing Sean Burke's FFT and have run into a potential issue using MIFF for storage of the FFT component images (real, imaginary, magnitude and phase) when converting the real and imaginary to phase using -fx. The phase image gets created but has bad values in it. Whereas, if I use PFM for storage, it all works fine. I wanted to inform you of this regarding the MIFF format. Also there are some oddities that I wanted to present and see if you could clarify them for me.
Here is what I have done:
I started with the following image:
I then did an FFT to create the real and imaginary components. Following that I converted the real and imaginary components to magnitude and phase using:
convert real.miff imaginary.miff -fx "sqrt(u*u+v*v)" magnitude.miff
convert real.miff imaginary.miff -fx "atan2(v,u)" phase.miff
Then I did an IFT using these magnitude and phase images, but the result is bad
Likewise using PFM format
convert real.pfm imaginary. pfm -fx "sqrt(u*u+v*v)" magnitude. pfm
convert real.pfm imaginary. pfm -fx "atan2(v,u)" phase. pfm
Here the result gave an image that was comparable to the original.
Note that there is NO scaling in creating the component images when using HDRI in the FFT routines.
Here are my intermediate and resulting images (after scaling to stretch to full dynamic range and converting to png for viewing). Note also the -verbose info: that I present as that is where there are some very strange things going on that I need clarification. The verbose info is coming from the MIFF or PFM images, not the PNG.
________________________________________________________
MIFF RESULTS:
real:
Depth: 32/16-bit
Channel depth:
gray: 16-bit
Channel statistics:
gray:
min: -997.818 (-0.0152257)
max: 1023.98 (0.015625)
mean: 2.26895e-09 (3.46219e-14)
standard deviation: 31.5035 (0.000480712)
Min and Max seem reasonable:
imaginary:
Depth: 32/16-bit
Channel depth:
gray: 16-bit
Channel statistics:
gray:
min: -46.3475 (-0.000707218)
max: 46.3475 (0.000707218)
mean: 5.3717e-12 (8.19669e-17)
standard deviation: 5.61079 (8.56152e-05)
Min and Max seem reasonable
Real/Imaginary convert to Magnitude:
Depth: 16-bit
Channel depth:
gray: 16-bit
Channel statistics:
gray:
min: 0 (0)
max: 1024 (0.0156252)
mean: 5.63159 (8.59326e-05)
standard deviation: 31.5031 (0.000480706)
Min and Max seem reasonable, BUT note that the Depth is reported as 16-bit and NOT 32/16-bit as are the real and imaginary images. Why is this? Is this a bug?
Real/Imaginary convert to Phase:
Depth: 16-bit
Channel depth:
gray: 16-bit
Channel statistics:
gray:
min: 0 (0)
max: 65535 (1)
mean: 21188.2 (0.323312)
standard deviation: 29190 (0.44541)
Min and Max are completely wrong. The phase should vary between -pi and +pi (NOT 0-QuantumRange). Also the same issue with the Depth reported as 16-bit and not 32/16-bit.
Resulting IFT from converted MIFF magnitude and phase:
This is not even close to the original image.
_______________________________________________________
PFM RESULTS:
real:
Depth: 32/16-bit
Channel depth:
gray: 16-bit
Channel statistics:
gray:
min: -997.818 (-0.0152257)
max: 1023.98 (0.015625)
mean: 2.26895e-09 (3.46219e-14)
standard deviation: 31.5035 (0.000480712)
Min and Max seem reasonable:
imaginary:
Depth: 32/16-bit
Channel depth:
gray: 16-bit
Channel statistics:
gray:
min: -46.3475 (-0.000707218)
max: 46.3475 (0.000707218)
mean: 5.3717e-12 (8.19669e-17)
standard deviation: 5.61079 (8.56152e-05)
Min and Max seem reasonable
Real/Imaginary convert to Magnitude:
Depth: 32/16-bit
Channel depth:
gray: 16-bit
Channel statistics:
gray:
min: 0 (0)
max: 1023.98 (0.015625)
mean: 5.63846 (8.60374e-05)
standard deviation: 31.4985 (0.000480637)
Min and Max seem reasonable, BUT note that the Depth is reasonably reported as 32/16-bit as expected.
Real/Imaginary convert to Phase:
Depth: 32/16-bit
Channel depth:
gray: 16-bit
Channel statistics:
gray:
min: -205080 (-3.12932)
max: 205080 (3.12932)
mean: 1.19035 (1.81636e-05)
standard deviation: 104241 (1.59061)
Min and Max are are between -pi and +pi, BUT as fractional values (where it should be in the range of 0-1) and I would have expected them to be the raw value. Also here the Depth is properly reported as 32/16-bit
_____________________
ASSIDE: Note when doing an FFT DIRECTLY to magnitude and phase in MIFF format and looking at the verbose statistics for the PHASE (whose image does look correct), I get the following verbose statistics for the PHASE:
Depth: 32/16-bit
Channel depth:
gray: 16-bit
Channel statistics:
gray:
min: -3.12932 (-4.77504e-05)
max: 3.12932 (4.77504e-05)
mean: 1.81636e-05 (2.77158e-10)
standard deviation: 1.59061 (2.42712e-05)
Note that the values -pi to +pi are now in the raw values not the fractional values.
_____________________
Getting back to the resulting IFT from the CONVERTED PFM magnitude and phase:
This is very close to the original image.
______________________________________________________
Thus:
1) Is there a bug in MIFF storage for data calculated from -fx in Q16-HDRI? (See verbose info for MIFF phase)
2) Why is the conversion from MIFF depth 32/16-bit to changed to MIFF depth 16-bit when output from -fx, but when using PFM it stays as 32/16-bit when output from -fx?
3) Why is the phase between -pi and +pi in the raw value for MIFF, but in the fractional values for PFM? (See verbose info for PFM phase vs MIFF).
Thanks for your help on this.
Here are links to the original MIFF and PFM images in case you need them to test for yourself:
http://www.fmwconcepts.com/misc_tests/F ... _real.miff
http://www.fmwconcepts.com/misc_tests/F ... t_real.pfm
http://www.fmwconcepts.com/misc_tests/F ... inary.miff
http://www.fmwconcepts.com/misc_tests/F ... ginary.pfm
http://www.fmwconcepts.com/misc_tests/F ... t_mag.miff
http://www.fmwconcepts.com/misc_tests/F ... ft_mag.pfm
http://www.fmwconcepts.com/misc_tests/F ... phase.miff
http://www.fmwconcepts.com/misc_tests/F ... _phase.pfm
Fred
P.S. Another piece of information: I just changed my script to do Normalized Cross Correlation (template matching) from using MIFF for FFT storage and computation storage to PFM and got much better results -- more accurate in finding the match point and the NCC surface was much more discriminating.