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
00014 COMPARE (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   )
00030 {
00031   register short i, j, k;
00032   char msg[SLEN];
00033 
00034   if (TIMES)
00035     TIMING (T_COMPARE);
00036   if (NAMES)
00037     {
00038       MESSAGE ('I', "");
00039       MESSAGE ('I', "COMPARE");
00040       MESSAGE ('I', "");
00041       sprintf (msg, " First input image:    %s", in1->text);
00042       MESSAGE ('I', msg);
00043       sprintf (msg, " Second input image:   %s", in2->text);
00044       MESSAGE ('I', msg);
00045       if (option == LT)
00046         {
00047           MESSAGE ('I', " Operation:            Less than");
00048         }
00049       else if (option == LE)
00050         {
00051           MESSAGE ('I', " Operation:            Less than or equal to");
00052         }
00053       else if (option == GT)
00054         {
00055           MESSAGE ('I', " Operation:            Greater than");
00056         }
00057       else if (option == GE)
00058         {
00059           MESSAGE ('I', " Operation:            Greater than or equal to");
00060         }
00061       else if (option == EQ)
00062         {
00063           MESSAGE ('I', " Operation:            Equal to");
00064         }
00065       else if (option == NE)
00066         {
00067           MESSAGE ('I', " Operation:            Not equal to");
00068         }
00069       else if (option == AND)
00070         {
00071           MESSAGE ('I', " Operation:            Logical and");
00072         }
00073       else if (option == OR)
00074         {
00075           MESSAGE ('I', " Operation:            Logical or");
00076         }
00077       else if (option == XOR)
00078         {
00079           MESSAGE ('I', " Operation:            Logical xor");
00080         }
00081       else if (option == NOT)
00082         {
00083           MESSAGE ('I',
00084                    " Operation:            Logical not (of the first input image)");
00085         }
00086       MESSAGE ('I', " ...............");
00087     }
00088 
00089   /* check input */
00090   if (!CHECKIMG (in1))
00091     {
00092       MESSAGE ('E', " Can't identify first input image.");
00093       goto the_end;
00094     }
00095   else if (option != NOT && !CHECKIMG (in2))
00096     {
00097       MESSAGE ('E', " Can't identify second input image.");
00098       goto the_end;
00099     }
00100   else if (option != NOT && in1->nbnd != in2->nbnd)
00101     {
00102       MESSAGE ('E', " Number of bands must be identical in both images.");
00103       goto the_end;
00104     }
00105   else if (option != NOT && in1->nlin != in2->nlin)
00106     {
00107       MESSAGE ('E', " Number of lines must be identical in both images.");
00108       goto the_end;
00109     }
00110   else if (option != NOT && in1->npix != in2->npix)
00111     {
00112       MESSAGE ('E',
00113                " Number of pixels/line must be identical in both images.");
00114       goto the_end;
00115     }
00116   else if (option != LT && option != LE && option != GT && option != GE
00117            && option != EQ && option != NE && option != AND && option != OR
00118            && option != XOR && option != NOT)
00119     {
00120       MESSAGE ('E',
00121                " Option must be one of LT, LE, GT, GE, EQ, NE, AND, OR, XOR, or NOT.");
00122       goto the_end;
00123     }
00124 
00125   /* create image of appropriate size */
00126   if (!CHECKIMG (*out))
00127     GETMEM (in1->nbnd, in1->nlin, in1->npix, out);
00128   if (!*out)
00129     goto the_end;
00130 
00131   /* create mask */
00132   switch (option)
00133     {
00134     case LT:
00135       for (i = 0; i < in1->nbnd; i++)
00136         {
00137           for (j = 0; j < in1->nlin; j++)
00138             {
00139               for (k = 0; k < in1->npix; k++)
00140                 {
00141                   if (in1->data[i][j][k] < in2->data[i][j][k])
00142                     {
00143                       (*out)->data[i][j][k] = (PIXEL) 1;
00144                     }
00145                   else
00146                     {
00147                       (*out)->data[i][j][k] = (PIXEL) 0;
00148                     }
00149                 }
00150             }
00151         }
00152       break;
00153     case LE:
00154       for (i = 0; i < in1->nbnd; i++)
00155         {
00156           for (j = 0; j < in1->nlin; j++)
00157             {
00158               for (k = 0; k < in1->npix; k++)
00159                 {
00160                   if (in1->data[i][j][k] <= in2->data[i][j][k])
00161                     {
00162                       (*out)->data[i][j][k] = (PIXEL) 1;
00163                     }
00164                   else
00165                     {
00166                       (*out)->data[i][j][k] = (PIXEL) 0;
00167                     }
00168                 }
00169             }
00170         }
00171       break;
00172     case GT:
00173       for (i = 0; i < in1->nbnd; i++)
00174         {
00175           for (j = 0; j < in1->nlin; j++)
00176             {
00177               for (k = 0; k < in1->npix; k++)
00178                 {
00179                   if (in1->data[i][j][k] > in2->data[i][j][k])
00180                     {
00181                       (*out)->data[i][j][k] = (PIXEL) 1;
00182                     }
00183                   else
00184                     {
00185                       (*out)->data[i][j][k] = (PIXEL) 0;
00186                     }
00187                 }
00188             }
00189         }
00190       break;
00191     case GE:
00192       for (i = 0; i < in1->nbnd; i++)
00193         {
00194           for (j = 0; j < in1->nlin; j++)
00195             {
00196               for (k = 0; k < in1->npix; k++)
00197                 {
00198                   if (in1->data[i][j][k] >= in2->data[i][j][k])
00199                     {
00200                       (*out)->data[i][j][k] = (PIXEL) 1;
00201                     }
00202                   else
00203                     {
00204                       (*out)->data[i][j][k] = (PIXEL) 0;
00205                     }
00206                 }
00207             }
00208         }
00209       break;
00210     case EQ:
00211       for (i = 0; i < in1->nbnd; i++)
00212         {
00213           for (j = 0; j < in1->nlin; j++)
00214             {
00215               for (k = 0; k < in1->npix; k++)
00216                 {
00217                   if (in1->data[i][j][k] == in2->data[i][j][k])
00218                     {
00219                       (*out)->data[i][j][k] = (PIXEL) 1;
00220                     }
00221                   else
00222                     {
00223                       (*out)->data[i][j][k] = (PIXEL) 0;
00224                     }
00225                 }
00226             }
00227         }
00228       break;
00229     case NE:
00230       for (i = 0; i < in1->nbnd; i++)
00231         {
00232           for (j = 0; j < in1->nlin; j++)
00233             {
00234               for (k = 0; k < in1->npix; k++)
00235                 {
00236                   if (in1->data[i][j][k] != in2->data[i][j][k])
00237                     {
00238                       (*out)->data[i][j][k] = (PIXEL) 1;
00239                     }
00240                   else
00241                     {
00242                       (*out)->data[i][j][k] = (PIXEL) 0;
00243                     }
00244                 }
00245             }
00246         }
00247       break;
00248     case AND:
00249       for (i = 0; i < in1->nbnd; i++)
00250         {
00251           for (j = 0; j < in1->nlin; j++)
00252             {
00253               for (k = 0; k < in1->npix; k++)
00254                 {
00255                   if (in1->data[i][j][k] != (PIXEL) 0
00256                       && in2->data[i][j][k] != (PIXEL) 0)
00257                     {
00258                       (*out)->data[i][j][k] = (PIXEL) 1;
00259                     }
00260                   else
00261                     {
00262                       (*out)->data[i][j][k] = (PIXEL) 0;
00263                     }
00264                 }
00265             }
00266         }
00267       break;
00268     case OR:
00269       for (i = 0; i < in1->nbnd; i++)
00270         {
00271           for (j = 0; j < in1->nlin; j++)
00272             {
00273               for (k = 0; k < in1->npix; k++)
00274                 {
00275                   if (in1->data[i][j][k] != (PIXEL) 0
00276                       || in2->data[i][j][k] != (PIXEL) 0)
00277                     {
00278                       (*out)->data[i][j][k] = (PIXEL) 1;
00279                     }
00280                   else
00281                     {
00282                       (*out)->data[i][j][k] = (PIXEL) 0;
00283                     }
00284                 }
00285             }
00286         }
00287       break;
00288     case XOR:
00289       for (i = 0; i < in1->nbnd; i++)
00290         {
00291           for (j = 0; j < in1->nlin; j++)
00292             {
00293               for (k = 0; k < in1->npix; k++)
00294                 {
00295                   if (in1->data[i][j][k] != (PIXEL) 0
00296                       && in2->data[i][j][k] == (PIXEL) 0
00297                       || in1->data[i][j][k] == (PIXEL) 0
00298                       && in2->data[i][j][k] != (PIXEL) 0)
00299                     {
00300                       (*out)->data[i][j][k] = (PIXEL) 1;
00301                     }
00302                   else
00303                     {
00304                       (*out)->data[i][j][k] = (PIXEL) 0;
00305                     }
00306                 }
00307             }
00308         }
00309       break;
00310     case NOT:
00311       for (i = 0; i < in1->nbnd; i++)
00312         {
00313           for (j = 0; j < in1->nlin; j++)
00314             {
00315               for (k = 0; k < in1->npix; k++)
00316                 {
00317                   if (in1->data[i][j][k] == (PIXEL) 0)
00318                     {
00319                       (*out)->data[i][j][k] = (PIXEL) 1;
00320                     }
00321                   else
00322                     {
00323                       (*out)->data[i][j][k] = (PIXEL) 0;
00324                     }
00325                 }
00326             }
00327         }
00328       break;
00329     }
00330 
00331 the_end:
00332   if (TIMES)
00333     TIMING (T_EXIT);
00334 }

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