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