Main Page   Data Structures   File List   Data Fields   Globals  

com2real.c

Go to the documentation of this file.
00001 #include        "sadie.h"
00002 
00003 /*-Copyright Information------------------------------------------------------*/
00004 /* Copyright (c) 1990 by the University of Arizona Digital Image Analysis Lab */
00005 /*----------------------------------------------------------------------------*/
00006 /*-General Information--------------------------------------------------------*/
00007 /*                                                                            */
00008 /*   This function separates one "complex" image into two "real" images.      */
00009 /*                                                                            */
00010 /*----------------------------------------------------------------------------*/
00011 /*-Interface Information------------------------------------------------------*/
00012 void
00013 COM2REAL (IMAGE * in,           /*  I   Pointer to the input image.                           */
00014           short option,         /*  I   Switch, indicating the type of real images:           */
00015           /*      REIMAG   -   real and imaginary images are computed.  */
00016           /*      MAGPHA   -   magnitude and phase images are computed. */
00017           IMAGE ** out1,        /*  O   Address of a pointer to the output image              */
00018           /*      containing the real/magnitude component.              */
00019           IMAGE ** out2         /*  O   Address of a pointer to the output image              */
00020           /*      containing the imaginary/phase component.             */
00021 /*----------------------------------------------------------------------------*/
00022   )
00023 {
00024   register short i, j, k, n;
00025   char msg[SLEN];
00026   double re, im;
00027 
00028   if (TIMES)
00029     TIMING (T_COM2REAL);
00030   if (NAMES)
00031     {
00032       MESSAGE ('I', "");
00033       MESSAGE ('I', "COM2REAL");
00034       MESSAGE ('I', "");
00035       sprintf (msg, " Input image:  %s", in->text);
00036       MESSAGE ('I', msg);
00037       if (option == REIMAG)
00038         {
00039           MESSAGE ('I', " Real and imaginary images computed");
00040         }
00041       else if (option == MAGPHA)
00042         {
00043           MESSAGE ('I', " Magnitude and phase images computed");
00044         }
00045       MESSAGE ('I', "");
00046       MESSAGE ('I', " ...............");
00047     }
00048 
00049   /* check input */
00050   if (!CHECKIMG (in))
00051     {
00052       MESSAGE ('E', " Can't identify image.");
00053       goto the_end;
00054     }
00055   else if (in->npix % 2 != 0)
00056     {
00057       MESSAGE ('E', " Number of pixels/line must be even.");
00058       goto the_end;
00059     }
00060   else if (option != REIMAG && option != MAGPHA)
00061     {
00062       MESSAGE ('E', " Option must be either REIMAG or MAGPHA.");
00063       goto the_end;
00064     }
00065 
00066   /* create image of appropriate size */
00067   if (!CHECKIMG (*out1))
00068     GETMEM (in->nbnd, in->nlin, in->npix / 2, out1);
00069   if (!*out1)
00070     goto the_end;
00071   if (!CHECKIMG (*out2))
00072     GETMEM (in->nbnd, in->nlin, in->npix / 2, out2);
00073   if (!*out2)
00074     goto the_end;
00075 
00076   if (option == REIMAG)
00077     {
00078       /* separate real and imaginary parts */
00079       for (i = 0; i < in->nbnd; i++)
00080         {
00081           for (j = 0; j < in->nlin; j++)
00082             {
00083               for (k = 0, n = 0; k < in->npix / 2; k += 1, n += 2)
00084                 {
00085                   (*out1)->data[i][j][k] = in->data[i][j][n];
00086                   (*out2)->data[i][j][k] = in->data[i][j][n + 1];
00087                 }
00088             }
00089         }
00090     }
00091   else                          /* (option == MAGPHA) */
00092     {
00093       /* calculate magnitude and phase parts */
00094       for (i = 0; i < in->nbnd; i++)
00095         {
00096           for (j = 0; j < in->nlin; j++)
00097             {
00098               for (k = 0, n = 0; k < in->npix / 2; k += 1, n += 2)
00099                 {
00100                   re = (double) in->data[i][j][n];
00101                   im = (double) in->data[i][j][n + 1];
00102                   (*out1)->data[i][j][k] = (PIXEL) sqrt ((re * re + im * im));
00103                   if (re == 0.0)
00104                     {
00105                       if (im > 0.0)
00106                         {
00107                           (*out2)->data[i][j][k] = (PIXEL) (PI / 2.0);
00108                         }
00109                       else if (im < 0.0)
00110                         {
00111                           (*out2)->data[i][j][k] = (PIXEL) (-PI / 2.0);
00112                         }
00113                       else      /* (im == 0.0 ) */
00114                         {
00115                           (*out2)->data[i][j][k] = (PIXEL) 0.0;
00116                         }
00117                     }
00118                   else
00119                     {
00120                       (*out2)->data[i][j][k] = (PIXEL) atan2 (im, re);
00121                     }
00122                 }
00123             }
00124         }
00125     }
00126 
00127 the_end:
00128   if (TIMES)
00129     TIMING (T_EXIT);
00130 }

Generated on Sun May 18 15:36:08 2003 for tclSadie by doxygen1.3