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 TRNSFORM (
00013 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 ) { register short i, j1, k1, j2, k2;
00026     char msg[SLEN];
00027 
00028     if (TIMES) TIMING(T_TRNSFORM);
00029     if (NAMES) {
00030         MESSAGE('I',"");
00031         MESSAGE('I',"TRNSFORM");
00032         MESSAGE('I',"");
00033         sprintf(msg," Input image:   %s",in->text);
00034         MESSAGE('I',msg);
00035         if (option == FLIP0) {
00036             MESSAGE('I'," Mirror axis vertical");
00037         } else if (option == FLIPM45) {
00038             MESSAGE('I'," Mirror axis -45 degree diagonal");
00039         } else if (option == FLIPP45) {
00040             MESSAGE('I'," Mirror axis +45 degree diagonal");
00041         } else if (option == FLIP90) {
00042             MESSAGE('I'," Mirror axis horizontal");
00043         } else if (option == ROTPM0) {
00044             MESSAGE('I'," Rotate +/-0 degrees");
00045         } else if (option == ROTP90) {
00046             MESSAGE('I'," Rotate +90 degrees");
00047         } else if (option == ROTM90) {
00048             MESSAGE('I'," Rotate -90 degrees");
00049         } else if (option == ROT180) {
00050             MESSAGE('I'," Rotate 180 degrees");
00051         }
00052         MESSAGE('I'," ...............");
00053     }
00054 
00055     /* check input */
00056     if (!CHECKIMG(in)) {
00057         MESSAGE('E'," Can't identify image");
00058         goto the_end;
00059     } else if (option != FLIP0  &&  option != FLIPP45  &&  option != FLIPM45  &&option != FLIP90  &&  option != ROTPM0  &&  option != ROTP90  &&  option != ROTM90  &&  option != ROT180) {
00060         MESSAGE('E'," Option must be one of FLIP0, FLIPP45, FLIPM45, FLIP90, ROTPM0, ROTP90, ROTM90, and ROT180.");
00061         goto the_end;
00062     }
00063 
00064     /* transform image */
00065     switch (option) {
00066     case FLIP0:
00067         if (!CHECKIMG(*out)) GETMEM(in->nbnd,in->nlin,in->npix,out);  
00068         if (!*out) goto the_end;
00069         for (i=0; i<in->nbnd; i++) {
00070             for (j1=0; j1<in->nlin; j1++) {
00071                 for (k1=in->npix-1, k2=0; k1>=0; k1--,k2++) {
00072                     (*out)->data[i][j1][k2] = in->data[i][j1][k1];
00073                 }
00074             }
00075         }
00076         break;
00077     case FLIPM45:
00078         if (!CHECKIMG(*out)) GETMEM(in->nbnd,in->npix,in->nlin,out);  
00079         if (!*out) goto the_end;
00080         for (i=0; i<in->nbnd; i++) {
00081             for (j1=0; j1<in->nlin; j1++) {
00082                 for (k1=0; k1<in->npix; k1++) {
00083                     (*out)->data[i][k1][j1] = in->data[i][j1][k1];
00084                 }
00085             }
00086         }
00087         break;
00088     case FLIPP45:
00089         if (!CHECKIMG(*out)) GETMEM(in->nbnd,in->npix,in->nlin,out);  
00090         if (!*out) goto the_end;
00091         for (i=0; i<in->nbnd; i++) {
00092             for (j1=0,j2=in->nlin-1; j1<in->nlin; j1++,j2--) {
00093                 for (k1=0,k2=in->npix-1; k1<in->npix; k1++,k2--) {
00094                     (*out)->data[i][k1][j2] = in->data[i][j1][k2];
00095                 }
00096             }
00097         }
00098         break;
00099    case FLIP90:
00100         if (!CHECKIMG(*out)) GETMEM(in->nbnd,in->nlin,in->npix,out);  
00101         if (!*out) goto the_end;
00102         for (i=0; i<in->nbnd; i++) {
00103             for (j1=in->nlin-1,j2=0; j1>=0; j1--,j2++) {
00104                 for (k1=0; k1<in->npix; k1++) {
00105                     (*out)->data[i][j2][k1] = in->data[i][j1][k1];
00106                 }
00107             }
00108         }
00109         break;
00110     case ROTPM0:
00111         if (!CHECKIMG(*out)) GETMEM(in->nbnd,in->nlin,in->npix,out);
00112         if (!*out) goto the_end;
00113         for (i=0; i<in->nbnd; i++) {
00114             for (j1=j2=0; j1<in->nlin; j1++,j2++) {
00115                 for (k1=k2=0; k1<in->npix; k1++,k2++) {
00116                     (*out)->data[i][j2][k2] = in->data[i][j1][k1];
00117                 }
00118             }
00119         }
00120         break;
00121     case ROTP90:
00122         if (!CHECKIMG(*out)) GETMEM(in->nbnd,in->npix,in->nlin,out);
00123         if (!*out) goto the_end;
00124         for (i=0; i<in->nbnd; i++) {
00125             for (k1=j2=0; k1<in->npix; k1++,j2++) {
00126                 for (j1=in->nlin-1,k2=0; j1>=0; j1--,k2++) {
00127                     (*out)->data[i][j2][k2] = in->data[i][j1][k1];
00128                 }
00129             }
00130         }
00131         break;
00132     case ROTM90:
00133         if (!CHECKIMG(*out)) GETMEM(in->nbnd,in->npix,in->nlin,out);
00134         if (!*out) goto the_end;
00135         for (i=0; i<in->nbnd; i++) {
00136             for (k1=in->npix-1,j2=0; k1>=0; k1--,j2++) {
00137                 for (j1=k2=0; j1<in->nlin; j1++,k2++) {
00138                      (*out)->data[i][j2][k2] = in->data[i][j1][k1];
00139                 }
00140             }
00141         }
00142         break;
00143     case ROT180:
00144         if (!CHECKIMG(*out)) GETMEM(in->nbnd,in->nlin,in->npix,out);
00145         if (!*out) goto the_end;
00146         for (i=0; i<in->nbnd; i++) {
00147             for (j1=in->nlin-1,j2=0; j1>=0; j1--,j2++) {
00148                 for (k1=in->npix-1,k2=0; k1>=0; k1--,k2++) {
00149                     (*out)->data[i][j2][k2] = in->data[i][j1][k1];
00150                 }
00151             }
00152         }
00153         break;
00154     }
00155 
00156     (*out)->gmin = in->gmin;
00157     (*out)->gmax = in->gmax;
00158 
00159     the_end:
00160     if (TIMES) TIMING(T_EXIT);
00161 }

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