Main Page   Data Structures   File List   Data Fields   Globals  

trnsform.c

Go to the documentation of this file.
00001 #include        "sadie.h"
00002 
00003 /*-Copyright Information------------------------------------------------------*/
00004 /* Copyright (c) 1988 by the University of Arizona Digital Image Analysis Lab */
00005 /*----------------------------------------------------------------------------*/
00006 /*-General Information--------------------------------------------------------*/
00007 /*                                                                            */
00008 /*   This function transforms the input image according to the given option.  */
00009 /*                                                                            */
00010 /*----------------------------------------------------------------------------*/
00011 /*-Interface Information------------------------------------------------------*/
00012 void
00013 TRNSFORM (IMAGE * in,           /*  I   Pointer to the input image                            */
00014           short option,         /*  I   Switch, indicating the type of transformation:        */
00015           /*      FLIP0   -   Mirror axis vertical.                     */
00016           /*      FLIPM45 -   Mirror axis -45 degree diagonal.          */
00017           /*      FLIPP45 -   Mirror axis +45 degree diagonal.          */
00018           /*      FLIP90  -   Mirror axis horizontal.                   */
00019           /*      ROTPM0  -   Rotate +/-0 degrees.                      */
00020           /*      ROTP90  -   Rotate +90 degrees.                       */
00021           /*      ROTM90  -   Rotate -90 degrees.                       */
00022           /*      ROT180  -   Rotate 180 degrees.                       */
00023           IMAGE ** out          /*  O   Address of a pointer to the output image              */
00024 /*----------------------------------------------------------------------------*/
00025   )
00026 {
00027   register short i, j1, k1, j2, k2;
00028   char msg[SLEN];
00029 
00030   if (TIMES)
00031     TIMING (T_TRNSFORM);
00032   if (NAMES)
00033     {
00034       MESSAGE ('I', "");
00035       MESSAGE ('I', "TRNSFORM");
00036       MESSAGE ('I', "");
00037       sprintf (msg, " Input image:   %s", in->text);
00038       MESSAGE ('I', msg);
00039       if (option == FLIP0)
00040         {
00041           MESSAGE ('I', " Mirror axis vertical");
00042         }
00043       else if (option == FLIPM45)
00044         {
00045           MESSAGE ('I', " Mirror axis -45 degree diagonal");
00046         }
00047       else if (option == FLIPP45)
00048         {
00049           MESSAGE ('I', " Mirror axis +45 degree diagonal");
00050         }
00051       else if (option == FLIP90)
00052         {
00053           MESSAGE ('I', " Mirror axis horizontal");
00054         }
00055       else if (option == ROTPM0)
00056         {
00057           MESSAGE ('I', " Rotate +/-0 degrees");
00058         }
00059       else if (option == ROTP90)
00060         {
00061           MESSAGE ('I', " Rotate +90 degrees");
00062         }
00063       else if (option == ROTM90)
00064         {
00065           MESSAGE ('I', " Rotate -90 degrees");
00066         }
00067       else if (option == ROT180)
00068         {
00069           MESSAGE ('I', " Rotate 180 degrees");
00070         }
00071       MESSAGE ('I', " ...............");
00072     }
00073 
00074   /* check input */
00075   if (!CHECKIMG (in))
00076     {
00077       MESSAGE ('E', " Can't identify image");
00078       goto the_end;
00079     }
00080   else if (option != FLIP0 && option != FLIPP45 && option != FLIPM45
00081            && option != FLIP90 && option != ROTPM0 && option != ROTP90
00082            && option != ROTM90 && option != ROT180)
00083     {
00084       MESSAGE ('E',
00085                " Option must be one of FLIP0, FLIPP45, FLIPM45, FLIP90, ROTPM0, ROTP90, ROTM90, and ROT180.");
00086       goto the_end;
00087     }
00088 
00089   /* transform image */
00090   switch (option)
00091     {
00092     case FLIP0:
00093       if (!CHECKIMG (*out))
00094         GETMEM (in->nbnd, in->nlin, in->npix, out);
00095       if (!*out)
00096         goto the_end;
00097       for (i = 0; i < in->nbnd; i++)
00098         {
00099           for (j1 = 0; j1 < in->nlin; j1++)
00100             {
00101               for (k1 = in->npix - 1, k2 = 0; k1 >= 0; k1--, k2++)
00102                 {
00103                   (*out)->data[i][j1][k2] = in->data[i][j1][k1];
00104                 }
00105             }
00106         }
00107       break;
00108     case FLIPM45:
00109       if (!CHECKIMG (*out))
00110         GETMEM (in->nbnd, in->npix, in->nlin, out);
00111       if (!*out)
00112         goto the_end;
00113       for (i = 0; i < in->nbnd; i++)
00114         {
00115           for (j1 = 0; j1 < in->nlin; j1++)
00116             {
00117               for (k1 = 0; k1 < in->npix; k1++)
00118                 {
00119                   (*out)->data[i][k1][j1] = in->data[i][j1][k1];
00120                 }
00121             }
00122         }
00123       break;
00124     case FLIPP45:
00125       if (!CHECKIMG (*out))
00126         GETMEM (in->nbnd, in->npix, in->nlin, out);
00127       if (!*out)
00128         goto the_end;
00129       for (i = 0; i < in->nbnd; i++)
00130         {
00131           for (j1 = 0, j2 = in->nlin - 1; j1 < in->nlin; j1++, j2--)
00132             {
00133               for (k1 = 0, k2 = in->npix - 1; k1 < in->npix; k1++, k2--)
00134                 {
00135                   (*out)->data[i][k1][j2] = in->data[i][j1][k2];
00136                 }
00137             }
00138         }
00139       break;
00140     case FLIP90:
00141       if (!CHECKIMG (*out))
00142         GETMEM (in->nbnd, in->nlin, in->npix, out);
00143       if (!*out)
00144         goto the_end;
00145       for (i = 0; i < in->nbnd; i++)
00146         {
00147           for (j1 = in->nlin - 1, j2 = 0; j1 >= 0; j1--, j2++)
00148             {
00149               for (k1 = 0; k1 < in->npix; k1++)
00150                 {
00151                   (*out)->data[i][j2][k1] = in->data[i][j1][k1];
00152                 }
00153             }
00154         }
00155       break;
00156     case ROTPM0:
00157       if (!CHECKIMG (*out))
00158         GETMEM (in->nbnd, in->nlin, in->npix, out);
00159       if (!*out)
00160         goto the_end;
00161       for (i = 0; i < in->nbnd; i++)
00162         {
00163           for (j1 = j2 = 0; j1 < in->nlin; j1++, j2++)
00164             {
00165               for (k1 = k2 = 0; k1 < in->npix; k1++, k2++)
00166                 {
00167                   (*out)->data[i][j2][k2] = in->data[i][j1][k1];
00168                 }
00169             }
00170         }
00171       break;
00172     case ROTP90:
00173       if (!CHECKIMG (*out))
00174         GETMEM (in->nbnd, in->npix, in->nlin, out);
00175       if (!*out)
00176         goto the_end;
00177       for (i = 0; i < in->nbnd; i++)
00178         {
00179           for (k1 = j2 = 0; k1 < in->npix; k1++, j2++)
00180             {
00181               for (j1 = in->nlin - 1, k2 = 0; j1 >= 0; j1--, k2++)
00182                 {
00183                   (*out)->data[i][j2][k2] = in->data[i][j1][k1];
00184                 }
00185             }
00186         }
00187       break;
00188     case ROTM90:
00189       if (!CHECKIMG (*out))
00190         GETMEM (in->nbnd, in->npix, in->nlin, out);
00191       if (!*out)
00192         goto the_end;
00193       for (i = 0; i < in->nbnd; i++)
00194         {
00195           for (k1 = in->npix - 1, j2 = 0; k1 >= 0; k1--, j2++)
00196             {
00197               for (j1 = k2 = 0; j1 < in->nlin; j1++, k2++)
00198                 {
00199                   (*out)->data[i][j2][k2] = in->data[i][j1][k1];
00200                 }
00201             }
00202         }
00203       break;
00204     case ROT180:
00205       if (!CHECKIMG (*out))
00206         GETMEM (in->nbnd, in->nlin, in->npix, out);
00207       if (!*out)
00208         goto the_end;
00209       for (i = 0; i < in->nbnd; i++)
00210         {
00211           for (j1 = in->nlin - 1, j2 = 0; j1 >= 0; j1--, j2++)
00212             {
00213               for (k1 = in->npix - 1, k2 = 0; k1 >= 0; k1--, k2++)
00214                 {
00215                   (*out)->data[i][j2][k2] = in->data[i][j1][k1];
00216                 }
00217             }
00218         }
00219       break;
00220     }
00221 
00222   (*out)->gmin = in->gmin;
00223   (*out)->gmax = in->gmax;
00224 
00225 the_end:
00226   if (TIMES)
00227     TIMING (T_EXIT);
00228 }

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