Main Page   Data Structures   File List   Data Fields   Globals  

compare.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 compares two images, and creates a binary mask as the      */
00009 /*   output image.                                                            */
00010 /*                                                                            */
00011 /*----------------------------------------------------------------------------*/
00012 /*-Interface Information------------------------------------------------------*/
00013 void COMPARE (
00014 IMAGE *in1,     /*  I   Pointer to the first input image.                     */
00015 IMAGE *in2,     /*  I   Pointer to the second input image.                    */
00016 short option,   /*  I   Switch, indicating type of comparison operation:      */
00017                 /*      LT    -   Less than.                                  */
00018                 /*      LE    -   Less than or equal to.                      */
00019                 /*      GT    -   Greater than.                               */
00020                 /*      GE    -   Greater than or equal to.                   */
00021                 /*      EQ    -   Equal to.                                   */
00022                 /*      NE    -   Not equal to.                               */
00023                 /*      AND   -   Logical and.                                */
00024                 /*      OR    -   Logical or.                                 */
00025                 /*      XOR   -   Logical xor.                                */
00026                 /*      NOT   -   Logical not (of the first input image).     */
00027 IMAGE **out     /*  O   Address of a pointer to the output image.             */
00028 /*----------------------------------------------------------------------------*/
00029 ) { register short i, j, k;
00030     char msg[SLEN];
00031 
00032     if (TIMES) TIMING(T_COMPARE);
00033     if (NAMES) {
00034         MESSAGE('I',"");
00035         MESSAGE('I',"COMPARE");
00036         MESSAGE('I',"");
00037         sprintf(msg," First input image:    %s",in1->text);
00038         MESSAGE('I',msg);
00039         sprintf(msg," Second input image:   %s",in2->text);
00040         MESSAGE('I',msg);
00041         if (option == LT) {
00042             MESSAGE('I'," Operation:            Less than");
00043         } else if (option == LE) {
00044             MESSAGE('I'," Operation:            Less than or equal to");
00045         } else if (option == GT) {
00046             MESSAGE('I'," Operation:            Greater than");
00047         } else if (option == GE) {
00048             MESSAGE('I'," Operation:            Greater than or equal to");
00049         } else if (option == EQ) {
00050             MESSAGE('I'," Operation:            Equal to");
00051         } else if (option == NE) {
00052             MESSAGE('I'," Operation:            Not equal to");
00053         } else if (option == AND) {
00054             MESSAGE('I'," Operation:            Logical and");
00055         } else if (option == OR) {
00056             MESSAGE('I'," Operation:            Logical or");
00057         } else if (option == XOR) {
00058             MESSAGE('I'," Operation:            Logical xor");
00059         } else if (option == NOT) {
00060             MESSAGE('I'," Operation:            Logical not (of the first input image)");
00061         }
00062         MESSAGE('I'," ...............");
00063     }
00064 
00065     /* check input */
00066     if (!CHECKIMG(in1)) {
00067         MESSAGE('E'," Can't identify first input image.");
00068         goto the_end;
00069     } else if (option != NOT  &&  !CHECKIMG(in2)) {
00070         MESSAGE('E'," Can't identify second input image.");
00071         goto the_end;
00072     } else if (option != NOT  &&  in1->nbnd != in2->nbnd) {
00073         MESSAGE('E'," Number of bands must be identical in both images.");
00074         goto the_end;
00075     } else if (option != NOT  &&  in1->nlin != in2->nlin) {
00076         MESSAGE('E'," Number of lines must be identical in both images.");
00077         goto the_end;
00078     } else if (option != NOT  &&  in1->npix != in2->npix) {
00079         MESSAGE('E'," Number of pixels/line must be identical in both images.");
00080         goto the_end;
00081     } else if (option != LT  &&  option != LE  &&  option != GT  &&  option != GE  &&  option != EQ  &&  option != NE  &&  option != AND  &&  option != OR  &&  option != XOR  &&  option != NOT) {
00082         MESSAGE('E'," Option must be one of LT, LE, GT, GE, EQ, NE, AND, OR, XOR, or NOT.");
00083         goto the_end;
00084     }
00085 
00086     /* create image of appropriate size */
00087     if (!CHECKIMG(*out)) GETMEM(in1->nbnd,in1->nlin,in1->npix,out);
00088     if (!*out) goto the_end;
00089 
00090     /* create mask */
00091     switch (option) {
00092     case LT:
00093         for (i=0; i<in1->nbnd; i++) {
00094             for (j=0; j<in1->nlin; j++) {
00095                 for (k=0; k<in1->npix; k++) {
00096                     if (in1->data[i][j][k] < in2->data[i][j][k]) {
00097                         (*out)->data[i][j][k] = (PIXEL)1;
00098                     } else {
00099                         (*out)->data[i][j][k] = (PIXEL)0;
00100                     }
00101                 }
00102             }
00103         }
00104         break; 
00105      case LE:
00106         for (i=0; i<in1->nbnd; i++) {
00107             for (j=0; j<in1->nlin; j++) {
00108                 for (k=0; k<in1->npix; k++) {
00109                     if (in1->data[i][j][k] <= in2->data[i][j][k]) {
00110                         (*out)->data[i][j][k] = (PIXEL)1;
00111                     } else {
00112                         (*out)->data[i][j][k] = (PIXEL)0;
00113                     }
00114                 }
00115             }
00116         }
00117         break; 
00118     case GT:
00119         for (i=0; i<in1->nbnd; i++) {
00120             for (j=0; j<in1->nlin; j++) {
00121                 for (k=0; k<in1->npix; k++) {
00122                     if (in1->data[i][j][k] > in2->data[i][j][k]) {
00123                         (*out)->data[i][j][k] = (PIXEL)1;
00124                     } else {
00125                         (*out)->data[i][j][k] = (PIXEL)0;
00126                     }
00127                 }
00128             }
00129         }
00130         break; 
00131     case GE:
00132         for (i=0; i<in1->nbnd; i++) {
00133             for (j=0; j<in1->nlin; j++) {
00134                 for (k=0; k<in1->npix; k++) {
00135                     if (in1->data[i][j][k] >= in2->data[i][j][k]) {
00136                         (*out)->data[i][j][k] = (PIXEL)1;
00137                     } else {
00138                         (*out)->data[i][j][k] = (PIXEL)0;
00139                     }
00140                 }
00141             }
00142         }
00143         break; 
00144     case EQ:
00145         for (i=0; i<in1->nbnd; i++) {
00146             for (j=0; j<in1->nlin; j++) {
00147                 for (k=0; k<in1->npix; k++) {
00148                     if (in1->data[i][j][k] == in2->data[i][j][k]) {
00149                         (*out)->data[i][j][k] = (PIXEL)1;
00150                     } else {
00151                         (*out)->data[i][j][k] = (PIXEL)0;
00152                     }
00153                 }
00154             }
00155         }
00156         break; 
00157     case NE:
00158         for (i=0; i<in1->nbnd; i++) {
00159             for (j=0; j<in1->nlin; j++) {
00160                 for (k=0; k<in1->npix; k++) {
00161                     if (in1->data[i][j][k] != in2->data[i][j][k]) {
00162                         (*out)->data[i][j][k] = (PIXEL)1;
00163                     } else {
00164                         (*out)->data[i][j][k] = (PIXEL)0;
00165                     }
00166                 }
00167             }
00168         }
00169         break; 
00170     case AND:
00171         for (i=0; i<in1->nbnd; i++) {
00172             for (j=0; j<in1->nlin; j++) {
00173                 for (k=0; k<in1->npix; k++) {
00174                     if (in1->data[i][j][k] != (PIXEL)0  &&  in2->data[i][j][k] != (PIXEL)0) {
00175                         (*out)->data[i][j][k] = (PIXEL)1;
00176                     } else {
00177                         (*out)->data[i][j][k] = (PIXEL)0;
00178                     }
00179                 }
00180             }
00181         }
00182         break; 
00183     case OR:
00184         for (i=0; i<in1->nbnd; i++) {
00185             for (j=0; j<in1->nlin; j++) {
00186                 for (k=0; k<in1->npix; k++) {
00187                     if (in1->data[i][j][k] != (PIXEL)0  ||  in2->data[i][j][k] != (PIXEL)0) {
00188                         (*out)->data[i][j][k] = (PIXEL)1;
00189                     } else {
00190                         (*out)->data[i][j][k] = (PIXEL)0;
00191                     }
00192                 }
00193             }
00194         }
00195         break; 
00196     case XOR:
00197         for (i=0; i<in1->nbnd; i++) {
00198             for (j=0; j<in1->nlin; j++) {
00199                 for (k=0; k<in1->npix; k++) {
00200                 if (in1->data[i][j][k] != (PIXEL)0  &&  in2->data[i][j][k] == (PIXEL)0   ||   in1->data[i][j][k] == (PIXEL)0  &&  in2->data[i][j][k] != (PIXEL)0) {
00201                         (*out)->data[i][j][k] = (PIXEL)1;
00202                     } else {
00203                         (*out)->data[i][j][k] = (PIXEL)0;
00204                     }
00205                 }
00206             }
00207         }
00208         break; 
00209     case NOT:
00210         for (i=0; i<in1->nbnd; i++) {
00211             for (j=0; j<in1->nlin; j++) {
00212                 for (k=0; k<in1->npix; k++) {
00213                     if (in1->data[i][j][k] == (PIXEL)0) {
00214                         (*out)->data[i][j][k] = (PIXEL)1;
00215                     } else {
00216                         (*out)->data[i][j][k] = (PIXEL)0;
00217                     }
00218                 }
00219             }
00220         }
00221         break; 
00222     }
00223 
00224     the_end:
00225     if (TIMES) TIMING(T_EXIT);
00226 }

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