Page 1 of 1

MagickForwardFourierTransformImage bug?

Posted: 2010-08-21T18:41:47-07:00
by el_supremo
When I try MagickForwardFourierTransformImage in a test program it only returns one image in the MagickWand (checked with MagickNumberImages after the call). If I request the mag/phase I only get the magnitude and requesting real/imag only returns the real component. Shouldn't MagickForwardFourierTransformImage return two images in the MagickWand?
This is with 6.6.3-8 Q16 compiled on WinXP to include fft and HDRI.

Pete

Here's a test function:

Code: Select all

#include <windows.h>
#include <wand/magick_wand.h>

void test_wand(void)
{
	MagickWand *mw = NULL;
	char info[128];
	
	MagickWandGenesis();

	mw = NewMagickWand();

	MagickReadImage(mw,"lena.png");

	// True returns mag/phase and false returns real/imag
	if(MagickForwardFourierTransformImage(mw,MagickTrue) == MagickFalse) {
		MessageBox(NULL,"FFT Failed","",MB_OK);
	}

	sprintf(info,"%d",MagickGetNumberImages(mw));
   // This indicates that there's one image in the wand
	MessageBox(NULL,info,"",MB_OK);

	MagickContrastStretchImage(mw,0,MagickGetImageWidth(mw)*MagickGetImageHeight(mw));
	MagickEvaluateImage(mw,LogEvaluateOperator,10000);

	MagickWriteImage(mw,"lena_mag.png");
	if(mw != NULL)DestroyMagickWand(mw);
	MagickWandTerminus();
}

Re: MagickForwardFourierTransformImage bug?

Posted: 2010-08-22T04:04:16-07:00
by blackhaz
Hi Pete,

I got the same problem. I'm using Magick++ but the idea must work:

image.forwardFourierTransform(true); /* true returns magnitude/phase pair, otherwise real/imaginary pair */
image.adjoin(true); /* Results in multiframe image - magnitude and phase pair */

Once adjoin is set to true the image will be a two-frame image, first frame will be magnitude, second frame will be phase. If you save it with simple:

image.write(fileName);

to a format that supports multiple frames (e.g. TIFF, MPC, etc) you will have a two-frame image. I am now stuck on how to access an individual frame of image, as it looks like subRange and subFrame are not working. So I implemented a work-around saving the result as MPC and reading it as:

strcat(fileName,"[0]"); /* Getting only the magnitude part from frame 0 from the temporary file - THIS IS A WORKAROUND */
image2.read(fileName);

This results in magnitude image in image2. This is really lame and I am waiting for somebody to suggest a better scenario. Setting the argument to [1] will result in phase image in the image2.

Hope this helps.

Re: MagickForwardFourierTransformImage bug?

Posted: 2010-08-22T09:01:14-07:00
by el_supremo
MagickWand doesn't have a way of directly setting adjoin, but MagickWriteImages allows you to specify an adjoin parameter. But it doesn't make any difference.
Changing the write to:

Code: Select all

   MagickWriteImages(mw,"lena_mag.tiff",MagickTrue);
doesn't result in a multiframe TIFF file (and nor does using MagickFalse).

Pete

Re: MagickForwardFourierTransformImage bug?

Posted: 2010-08-22T12:15:11-07:00
by magick
Given this code:

Code: Select all

  MagickWandGenesis();
  magick_wand=NewMagickWand();
  status=MagickReadImage(magick_wand,"logo:");
  if (status == MagickFalse)
    ThrowWandException(magick_wand);
  status=MagickReadImage(magick_wand,"logo:");
  if (status == MagickFalse)
    ThrowWandException(magick_wand);
  status = MagickWriteImages(magick_wand, "logo.tif", MagickTrue);
  if (status == MagickFalse)
    ThrowWandException(magick_wand);
After running it, we try this command:
  • identify logo.tif
returns
  • logo.tif[0] TIFF 640x480 640x480+0+0 8-bit PseudoClass 256c 90.5KB 0.000u 0:00.000
    logo.tif[1] TIFF 640x480 640x480+0+0 8-bit PseudoClass 256c 90.5KB 0.000u 0:00.000
Suggesting the two images we read are adjoined as expected. If we change the adjoin attribute to MagickFalse we get
  • logo-0.tif
    logo-1.tif
as expected. We're using ImageMagick 6.6.3-8.

Re: MagickForwardFourierTransformImage bug?

Posted: 2010-08-22T13:12:09-07:00
by el_supremo
Your test works fine here (also 6.6.3-8) but perhaps I don't understand how MagickForwardFourierTransformImage works. When I specify MagickTrue to get the magnitude and phase, there is only one image in the wand and that is the magnitude. If I request the real/imag there is only one image in the wand and that's the real.
How do I get the phase or imaginary image as well?

Pete

Re: MagickForwardFourierTransformImage bug?

Posted: 2010-08-22T13:39:07-07:00
by magick
We can reproduce the problem you posted. Look for a patch in ImageMagick 6.6.3-9 Beta by sometime tomorrow. Thanks.

Re: MagickForwardFourierTransformImage bug?

Posted: 2010-08-29T12:08:10-07:00
by el_supremo
I've just compiled the 6.6.3-9 windows source distribution and there isn't any change. MagickForwardFourierTransformImage still produces only one image in the wand.

Pete

Re: MagickForwardFourierTransformImage bug?

Posted: 2010-08-29T12:36:51-07:00
by magick
  • MagickForwardFourierTransformImage(mw,MagickTrue);
    printf("%d\n",,MagickGetNumberImages(mw));
This code returns 2 suggesting MagickForwardFourierTransformImage() is working as expected. We're using ImageMagick-6.6.3-9. Can you post code we can download and execute to try to reproduce your problem.

Re: MagickForwardFourierTransformImage bug?

Posted: 2010-08-29T12:40:17-07:00
by el_supremo
Sorry, my bad. I forgot to update the PATH environment variable.

Pete