Main Page   Data Structures   File List   Data Fields   Globals  

rmsdiff.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 computes the root-mean-squared difference between          */
00009 /*   two images.                                                              */
00010 /*                                                                            */
00011 /*----------------------------------------------------------------------------*/
00012 /*-Interface Information------------------------------------------------------*/
00013 void
00014 RMSDIFF (IMAGE * in1,           /*  I   Pointer to the first input image.                     */
00015          IMAGE * in2,           /*  I   Pointer to the second input image.                    */
00016          double *diff           /*  O   Address of a variable to hold the rms-difference.     */
00017 /*----------------------------------------------------------------------------*/
00018   )
00019 {
00020   register short i, j, k;
00021   char msg[SLEN];
00022 
00023   if (TIMES)
00024     TIMING (T_RMSDIFF);
00025   if (NAMES)
00026     {
00027       MESSAGE ('I', "");
00028       MESSAGE ('I', "RMSDIFF");
00029       MESSAGE ('I', "");
00030       sprintf (msg, " First input image:    %s", in1->text);
00031       MESSAGE ('I', msg);
00032       sprintf (msg, " Second input image:   %s", in2->text);
00033       MESSAGE ('I', msg);
00034       MESSAGE ('I', " ...............");
00035     }
00036 
00037   /* check input */
00038   if (!CHECKIMG (in1))
00039     {
00040       MESSAGE ('E', " Can't identify first image.");
00041       goto the_end;
00042     }
00043   else if (!CHECKIMG (in2))
00044     {
00045       MESSAGE ('E', " Can't identify second image.");
00046       goto the_end;
00047     }
00048   else if (in1->nbnd != in2->nbnd)
00049     {
00050       MESSAGE ('E', " Number of bands must be identical in both images.");
00051       goto the_end;
00052     }
00053   else if (in1->nlin != in2->nlin)
00054     {
00055       MESSAGE ('E', " Number of lines must be identical in both images.");
00056       goto the_end;
00057     }
00058   else if (in1->npix != in2->npix)
00059     {
00060       MESSAGE ('E',
00061                " Number of pixels/line must be identical in both images.");
00062       goto the_end;
00063     }
00064 
00065   /* calculate the root-mean-squared difference */
00066   for (*diff = 0.0, i = 0; i < in1->nbnd; i++)
00067     {
00068       for (j = 0; j < in1->nlin; j++)
00069         {
00070           for (k = 0; k < in1->npix; k++)
00071             {
00072               *diff +=
00073                 (double) ((in1->data[i][j][k] -
00074                            in2->data[i][j][k]) * (in1->data[i][j][k] -
00075                                                   in2->data[i][j][k]));
00076             }
00077         }
00078     }
00079   *diff =
00080     sqrt (*diff /
00081           ((double) in1->nbnd * (double) in1->nlin * (double) in1->npix));
00082 
00083   /* output the resulting difference */
00084   MESSAGE ('I', "");
00085   sprintf (msg, " Root-Mean-Squared Difference = %-11.4e", *diff);
00086   MESSAGE ('I', msg);
00087 
00088 the_end:
00089   if (TIMES)
00090     TIMING (T_EXIT);
00091 }

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