diff --git a/magick/fourier.c b/magick/fourier.c
index 852928d..103e090 100644
--- a/magick/fourier.c
+++ b/magick/fourier.c
@@ -125,26 +125,25 @@
 
 #if defined(MAGICKCORE_FFTW_DELEGATE)
 
-static MagickBooleanType RollFourier(const size_t width,
-  const size_t height,const ssize_t x_offset,const ssize_t y_offset,
-  double *fourier)
+static MagickBooleanType RollFourier(const size_t width,const size_t height,
+  const ssize_t x_offset,const ssize_t y_offset,double *fourier)
 {
   double
     *roll;
 
+  register ssize_t
+    i,
+    x;
+
   ssize_t
     u,
     v,
     y;
 
-  register ssize_t
-    i,
-    x;
-
   /*
     Move zero frequency (DC, average color) from (0,0) to (width/2,height/2).
   */
-  roll=(double *) AcquireQuantumMemory((size_t) width,height*sizeof(*roll));
+  roll=(double *) AcquireQuantumMemory((size_t) height,width*sizeof(*roll));
   if (roll == (double *) NULL)
     return(MagickFalse);
   i=0L;
@@ -163,9 +162,9 @@
         u=((x+x_offset) > ((ssize_t) width-1L)) ? x+x_offset-(ssize_t) width :
           x+x_offset;
       roll[v*width+u]=fourier[i++];
-   }
+    }
   }
-  (void) CopyMagickMemory(fourier,roll,width*height*sizeof(*roll));
+  (void) CopyMagickMemory(fourier,roll,height*width*sizeof(*roll));
   roll=(double *) RelinquishMagickMemory(roll);
   return(MagickTrue);
 }
@@ -173,16 +172,16 @@
 static MagickBooleanType ForwardQuadrantSwap(const size_t width,
   const size_t height,double *source,double *destination)
 {
-  ssize_t
-    center,
-    y;
-
   MagickBooleanType
     status;
 
   register ssize_t
     x;
 
+  ssize_t
+    center,
+    y;
+
   /*
     Swap quadrants.
   */
@@ -201,8 +200,8 @@
   return(MagickTrue);
 }
 
-static void CorrectPhaseLHS(const size_t width,
-  const size_t height,double *fourier)
+static void CorrectPhaseLHS(const size_t width,const size_t height,
+  double *fourier)
 {
   ssize_t
     y;
@@ -230,10 +229,6 @@
     *magnitude_image,
     *phase_image;
 
-  ssize_t
-    i,
-    y;
-
   MagickBooleanType
     status;
 
@@ -246,6 +241,10 @@
   register PixelPacket
     *q;
 
+  ssize_t
+    i,
+    y;
+
   magnitude_image=GetFirstImageInList(image);
   phase_image=GetNextImageInList(image);
   if (phase_image == (Image *) NULL)
@@ -261,11 +260,11 @@
     fourier_info->height,fourier_info->width*sizeof(*magnitude_source));
   if (magnitude_source == (double *) NULL)
     return(MagickFalse);
-  (void) ResetMagickMemory(magnitude_source,0,fourier_info->width*
-    fourier_info->height*sizeof(*magnitude_source));
+  (void) ResetMagickMemory(magnitude_source,0,fourier_info->height*
+    fourier_info->width*sizeof(*magnitude_source));
   phase_source=(double *) AcquireQuantumMemory((size_t) fourier_info->height,
     fourier_info->width*sizeof(*phase_source));
-  if (magnitude_source == (double *) NULL)
+  if (phase_source == (double *) NULL)
     {
       (void) ThrowMagickException(exception,GetMagickModule(),
         ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
@@ -331,9 +330,8 @@
         }
         case GrayChannels:
         {
-          q->red=ClampToQuantum(QuantumRange*magnitude_source[i]);
-          q->green=q->red;
-          q->blue=q->red;
+          SetGrayPixelComponent(q,ClampToQuantum(QuantumRange*
+            magnitude_source[i]));
           break;
         }
       }
@@ -384,9 +382,7 @@
         }
         case GrayChannels:
         {
-          q->red=ClampToQuantum(QuantumRange*phase_source[i]);
-          q->green=q->red;
-          q->blue=q->red;
+          SetGrayPixelComponent(q,ClampToQuantum(QuantumRange*phase_source[i]));
           break;
         }
       }
@@ -420,9 +416,6 @@
   fftw_plan
     fftw_r2c_plan;
 
-  ssize_t
-    y;
-
   register const IndexPacket
     *indexes;
 
@@ -433,6 +426,9 @@
     i,
     x;
 
+  ssize_t
+    y;
+
   /*
     Generate the forward Fourier transform.
   */
@@ -444,7 +440,7 @@
         ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
       return(MagickFalse);
     }
-  ResetMagickMemory(source,0,fourier_info->width*fourier_info->height*
+  ResetMagickMemory(source,0,fourier_info->height*fourier_info->width*
     sizeof(*source));
   i=0L;
   image_view=AcquireCacheView(image);
@@ -487,7 +483,7 @@
         }
         case GrayChannels:
         {
-          source[i]=QuantumScale*GetRedPixelComponent(p);
+          source[i]=QuantumScale*GetGraGrayyPixelComponent(p);
           break;
         }
       }
@@ -564,12 +560,12 @@
   fftw_complex
     *fourier;
 
-  MagickBooleanType
-    status;
-
   FourierInfo
     fourier_info;
 
+  MagickBooleanType
+    status;
+
   size_t
     extent;
 
@@ -798,13 +794,13 @@
 static MagickBooleanType InverseQuadrantSwap(const size_t width,
   const size_t height,const double *source,double *destination)
 {
+  register ssize_t
+    x;
+
   ssize_t
     center,
     y;
 
-  register ssize_t
-    x;
-
   /*
     Swap quadrants.
   */
@@ -833,9 +829,6 @@
     *magnitude_source,
     *phase_source;
 
-  ssize_t
-    y;
-
   MagickBooleanType
     status;
 
@@ -849,6 +842,9 @@
     i,
     x;
 
+  ssize_t
+    y;
+
   /*
     Inverse fourier - read image and break down into a double array.
   */
@@ -862,7 +858,7 @@
       return(MagickFalse);
     }
   phase_source=(double *) AcquireQuantumMemory((size_t) fourier_info->height,
-    fourier_info->height*sizeof(*phase_source));
+    fourier_info->width*sizeof(*phase_source));
   if (phase_source == (double *) NULL)
     {
       (void) ThrowMagickException(exception,GetMagickModule(),
@@ -912,7 +908,7 @@
         }
         case GrayChannels:
         {
-          magnitude_source[i]=QuantumScale*GetRedPixelComponent(p);
+          magnitude_source[i]=QuantumScale*GetGrayPixelComponent(p);
           break;
         }
       }
@@ -961,7 +957,7 @@
         }
         case GrayChannels:
         {
-          phase_source[i]=QuantumScale*GetRedPixelComponent(p);
+          phase_source[i]=QuantumScale*GetGrayPixelComponent(p);
           break;
         }
       }
@@ -996,8 +992,8 @@
   status=InverseQuadrantSwap(fourier_info->width,fourier_info->height,
     magnitude_source,magnitude);
   magnitude_source=(double *) RelinquishMagickMemory(magnitude_source);
-  phase=(double *) AcquireQuantumMemory((size_t) fourier_info->width,
-    fourier_info->height*sizeof(*phase));
+  phase=(double *) AcquireQuantumMemory((size_t) fourier_info->height,
+    fourier_info->width*sizeof(*phase));
   if (phase == (double *) NULL)
     {
       (void) ThrowMagickException(exception,GetMagickModule(),
@@ -1056,21 +1052,21 @@
   fftw_plan
     fftw_c2r_plan;
 
-  ssize_t
-    y;
-
   register IndexPacket
     *indexes;
 
+  register PixelPacket
+    *q;
+
   register ssize_t
     i,
     x;
 
-  register PixelPacket
-    *q;
+  ssize_t
+    y;
 
-  source=(double *) AcquireQuantumMemory((size_t) fourier_info->width,
-    fourier_info->height*sizeof(double));
+  source=(double *) AcquireQuantumMemory((size_t) fourier_info->height,
+    fourier_info->width*sizeof(*source));
   if (source == (double *) NULL)
     {
       (void) ThrowMagickException(exception,GetMagickModule(),
@@ -1129,9 +1125,7 @@
         }
         case GrayChannels:
         {
-          q->red=ClampToQuantum(QuantumRange*source[i]);
-          q->green=q->red;
-          q->blue=q->red;
+          SetGrayPixelComponent(q,ClampToQuantum(QuantumRange*source[i]));
           break;
         }
       }
@@ -1181,7 +1175,7 @@
   fourier_info.channel=channel;
   fourier_info.modulus=modulus;
   magnitude=(double *) AcquireQuantumMemory((size_t) fourier_info.height,
-    fourier_info.center*sizeof(double));
+    fourier_info.center*sizeof(*magnitude));
   if (magnitude == (double *) NULL)
     {
       (void) ThrowMagickException(exception,GetMagickModule(),
@@ -1190,7 +1184,7 @@
       return(MagickFalse);
     }
   phase=(double *) AcquireQuantumMemory((size_t) fourier_info.height,
-    fourier_info.center*sizeof(double));
+    fourier_info.center*sizeof(*phase));
   if (phase == (double *) NULL)
     {
       (void) ThrowMagickException(exception,GetMagickModule(),