00001 #include "sadie.h"
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 void
00014 RMSDIFF (IMAGE * in1,
00015 IMAGE * in2,
00016 double *diff
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
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
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
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 }