MagickForwardFourierTransformImage bug?

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

MagickForwardFourierTransformImage bug?

Post 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();
}
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
blackhaz

Re: MagickForwardFourierTransformImage bug?

Post 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.
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: MagickForwardFourierTransformImage bug?

Post 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
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: MagickForwardFourierTransformImage bug?

Post 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.
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: MagickForwardFourierTransformImage bug?

Post 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
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: MagickForwardFourierTransformImage bug?

Post by magick »

We can reproduce the problem you posted. Look for a patch in ImageMagick 6.6.3-9 Beta by sometime tomorrow. Thanks.
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: MagickForwardFourierTransformImage bug?

Post 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
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: MagickForwardFourierTransformImage bug?

Post 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.
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: MagickForwardFourierTransformImage bug?

Post by el_supremo »

Sorry, my bad. I forgot to update the PATH environment variable.

Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
Post Reply