00001 #include "sadie.h"
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 void
00016 SIGMAP (IMAGE * in1,
00017 IMAGE * in2,
00018 IMAGE ** out
00019
00020 )
00021 {
00022 register short i, j, k;
00023 char msg[SLEN];
00024 long n, nlev, index, *count = 0;
00025 PIXEL *table = 0;
00026
00027 if (TIMES)
00028 TIMING (T_SIGMAP);
00029 if (NAMES)
00030 {
00031 MESSAGE ('I', "");
00032 MESSAGE ('I', "SIGMAP");
00033 MESSAGE ('I', "");
00034 sprintf (msg, " Label map: %s", in1->text);
00035 MESSAGE ('I', msg);
00036 sprintf (msg, " Original image: %s", in2->text);
00037 MESSAGE ('I', msg);
00038 MESSAGE ('I', " ...............");
00039 }
00040
00041 if (!CHECKIMG (in1))
00042 {
00043 MESSAGE ('E', " Can't identify image.");
00044 goto the_end;
00045 }
00046 else if (!CHECKIMG (in2))
00047 {
00048 MESSAGE ('E', " Can't identify image.");
00049 goto the_end;
00050 }
00051 else if (in1->nbnd != 1)
00052 {
00053 MESSAGE ('E', " Classification label map must be single-band.");
00054 goto the_end;
00055 }
00056 else if (in1->nlin != in2->nlin)
00057 {
00058 MESSAGE ('E', " Number of lines must be identical in all images.");
00059 goto the_end;
00060 }
00061 else if (in1->npix != in2->npix)
00062 {
00063 MESSAGE ('E',
00064 " Number of pixels/line must be identical in all images.");
00065 goto the_end;
00066 }
00067
00068
00069 if (!CHECKIMG (*out))
00070 GETMEM (in2->nbnd, in2->nlin, in2->npix, out);
00071 if (!*out)
00072 goto the_end;
00073
00074
00075 RANGE (in1);
00076 nlev = (long) in1->gmax - (long) in1->gmin + 1L;
00077 if (!(count = (long *) malloc (nlev * sizeof (long))))
00078 {
00079 MESSAGE ('E', " Memory request failed.");
00080 goto the_end;
00081 }
00082 if (!(table = (PIXEL *) malloc (nlev * (long) in2->nbnd * sizeof (PIXEL))))
00083 {
00084 MESSAGE ('E', " Memory request failed.");
00085 goto the_end;
00086 }
00087 for (n = 0L; n < nlev; count[n++] = 0L);
00088 for (n = 0L; n < nlev * (long) in2->nbnd; table[n++] = (PIXEL) 0);
00089
00090
00091 for (j = 0; j < in2->nlin; j++)
00092 {
00093 for (k = 0; k < in2->npix; k++)
00094 {
00095 index = (long) in1->data[0][j][k] - (long) in1->gmin;
00096 count[index] += 1L;
00097 for (i = 0; i < in2->nbnd; i++)
00098 {
00099 table[(long) i * nlev + index] += in2->data[i][j][k];
00100 }
00101 }
00102 }
00103
00104
00105 for (n = 0L; n < nlev; n++)
00106 {
00107 if (count[n] > 0L)
00108 {
00109 for (i = 0; i < in2->nbnd; i++)
00110 {
00111 table[(long) i * nlev + n] /= (PIXEL) count[n];
00112 }
00113 }
00114 }
00115
00116
00117 for (j = 0; j < in2->nlin; j++)
00118 {
00119 for (k = 0; k < in2->npix; k++)
00120 {
00121 index = (long) in1->data[0][j][k] - (long) in1->gmin;
00122 for (i = 0; i < in2->nbnd; i++)
00123 {
00124 (*out)->data[i][j][k] = table[(long) i * nlev + index];
00125 }
00126 }
00127 }
00128
00129 the_end:
00130 if (count)
00131 free (count);
00132 if (table)
00133 free (table);
00134 if (TIMES)
00135 TIMING (T_EXIT);
00136 }