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 COM2REAL (
00013 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 ) { register short i, j, k, n;
00023     char   msg[SLEN];
00024     double re, im;
00025 
00026     if (TIMES) TIMING(T_COM2REAL);
00027     if (NAMES) {
00028         MESSAGE('I',"");
00029         MESSAGE('I',"COM2REAL");
00030         MESSAGE('I',"");
00031         sprintf(msg," Input image:  %s",in->text);
00032         MESSAGE('I',msg);
00033         if (option == REIMAG) {
00034             MESSAGE('I'," Real and imaginary images computed");
00035         } else if (option == MAGPHA) {
00036             MESSAGE('I'," Magnitude and phase images computed");
00037         }
00038         MESSAGE('I',"");
00039         MESSAGE('I'," ...............");
00040     }
00041 
00042     /* check input */
00043     if (!CHECKIMG(in)) {
00044         MESSAGE('E'," Can't identify image.");
00045         goto the_end;
00046     } else if (in->npix%2 != 0) {
00047         MESSAGE('E'," Number of pixels/line must be even.");
00048         goto the_end;
00049     } else if (option != REIMAG  &&  option != MAGPHA) {
00050         MESSAGE('E'," Option must be either REIMAG or MAGPHA.");
00051         goto the_end;
00052     }
00053 
00054     /* create image of appropriate size */
00055     if (!CHECKIMG(*out1)) GETMEM(in->nbnd,in->nlin,in->npix/2,out1);
00056     if (!*out1) goto the_end;
00057     if (!CHECKIMG(*out2)) GETMEM(in->nbnd,in->nlin,in->npix/2,out2);
00058     if (!*out2) goto the_end;
00059 
00060     if (option == REIMAG) {
00061         /* separate real and imaginary parts */
00062         for (i=0; i<in->nbnd; i++) {
00063             for (j=0; j<in->nlin; j++) {
00064                 for (k=0,n=0; k<in->npix/2; k+=1,n+=2) {
00065                     (*out1)->data[i][j][k] = in->data[i][j][n];
00066                     (*out2)->data[i][j][k] = in->data[i][j][n+1];
00067                 }
00068             }
00069         }
00070     } else /* (option == MAGPHA) */ {
00071         /* calculate magnitude and phase parts */
00072         for (i=0; i<in->nbnd; i++) {
00073             for (j=0; j<in->nlin; j++) {
00074                 for (k=0,n=0; k<in->npix/2; k+=1,n+=2) {
00075                     re = (double)in->data[i][j][n];
00076                     im = (double)in->data[i][j][n+1];
00077                     (*out1)->data[i][j][k] = (PIXEL)sqrt((re*re + im*im));
00078                     if (re == 0.0) {
00079                         if (im > 0.0) {
00080                             (*out2)->data[i][j][k] = (PIXEL)(PI/2.0);
00081                         } else if (im < 0.0) {
00082                             (*out2)->data[i][j][k] = (PIXEL)(-PI/2.0);
00083                         } else /* (im == 0.0 ) */ {
00084                             (*out2)->data[i][j][k] = (PIXEL)0.0;
00085                         }
00086                     } else {
00087                         (*out2)->data[i][j][k] = (PIXEL)atan2(im,re);
00088                     }
00089                 }
00090             }
00091         }
00092     }       
00093 
00094     the_end:
00095     if (TIMES) TIMING(T_EXIT);
00096 }

Generated on Wed Apr 9 08:56:04 2003 for TREES by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002