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 RMSDIFF (
00014 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 ) { register short i, j, k;
00019     char msg[SLEN];
00020 
00021     if (TIMES) TIMING(T_RMSDIFF);
00022     if (NAMES) {
00023         MESSAGE('I',"");
00024         MESSAGE('I',"RMSDIFF");
00025         MESSAGE('I',"");
00026         sprintf(msg," First input image:    %s",in1->text);
00027         MESSAGE('I',msg);
00028         sprintf(msg," Second input image:   %s",in2->text);
00029         MESSAGE('I',msg);
00030         MESSAGE('I'," ...............");
00031     }
00032 
00033     /* check input */
00034     if (!CHECKIMG(in1)) {
00035         MESSAGE('E'," Can't identify first image.");
00036         goto the_end;
00037     } else if (!CHECKIMG(in2)) {
00038         MESSAGE('E'," Can't identify second image.");
00039         goto the_end;
00040     } else if (in1->nbnd != in2->nbnd) {
00041         MESSAGE('E'," Number of bands must be identical in both images.");
00042         goto the_end;
00043     } else if (in1->nlin != in2->nlin) {
00044         MESSAGE('E'," Number of lines must be identical in both images.");
00045         goto the_end;
00046     } else if (in1->npix != in2->npix) {
00047         MESSAGE('E'," Number of pixels/line must be identical in both images.");
00048         goto the_end;
00049     }
00050 
00051     /* calculate the root-mean-squared difference */
00052     for (*diff=0.0,i=0; i<in1->nbnd; i++) {
00053         for (j=0; j<in1->nlin; j++) {
00054             for (k=0; k<in1->npix; k++) {
00055                 *diff += (double)((in1->data[i][j][k]-in2->data[i][j][k])*(in1->data[i][j][k]-in2->data[i][j][k]));
00056             }
00057         }
00058     }
00059     *diff = sqrt(*diff/((double)in1->nbnd*(double)in1->nlin*(double)in1->npix));
00060 
00061     /* output the resulting difference */
00062     MESSAGE('I',"");
00063     sprintf(msg," Root-Mean-Squared Difference = %-11.4e",*diff);
00064     MESSAGE('I',msg);
00065 
00066     the_end:
00067     if (TIMES) TIMING(T_EXIT);
00068 }

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