Main Page   Data Structures   File List   Data Fields   Globals  

scatter.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 joint two-dimensional histogram               */
00009 /*   (scattergram) between two bands from either the same or from             */
00010 /*   two different images.  The first input image graylevels are              */
00011 /*   along the ordinate and the second input image graylevels are             */
00012 /*   along the abscissa of the scattergram.                                   */
00013 /*                                                                            */
00014 /*----------------------------------------------------------------------------*/
00015 /*-Interface Information------------------------------------------------------*/
00016 void SCATTER (
00017 IMAGE *in1,     /*  I   Pointer to the first input image.                     */
00018 IMAGE *in2,     /*  I   Pointer to the second input image.                    */
00019 short bnd1,     /*  I   Band in the first image.                              */
00020 short bnd2,     /*  I   Band in the second image.                             */
00021 short inc,      /*  I   Line and pixel subsample increment.                   */
00022 short nlev,     /*  I   Histogram resolution (and number of lines and         */
00023                 /*      pixels/line in the output image).                     */
00024 IMAGE **out     /*  O   Address of a pointer to the output image.             */
00025 /*----------------------------------------------------------------------------*/
00026 ) { register short i, j, ix, iy;
00027     char   msg[SLEN];
00028     double width, pinc, psum;
00029     PIXEL  gmin, gmax;
00030 
00031     if (TIMES) TIMING(T_SCATTER);
00032     if (NAMES) {
00033         MESSAGE('I',"");
00034         MESSAGE('I',"SCATTER");
00035         MESSAGE('I',"");
00036         sprintf(msg," First input image:                    %s - band %d",in1->text,bnd1+1);
00037         MESSAGE('I',msg);
00038         sprintf(msg," Second input image:                   %s - band %d",in2->text,bnd2+1);
00039         MESSAGE('I',msg);
00040         sprintf(msg," Histogram resolution:                 %d",nlev);
00041         MESSAGE('I',msg);
00042         sprintf(msg," Line and pixel subsample increment:   %d",inc);
00043         MESSAGE('I',msg);
00044         MESSAGE('I'," ...............");
00045     }
00046 
00047     /* check input */
00048     if (!CHECKIMG(in1)) {
00049         MESSAGE('E'," Can't identify first image.");
00050         goto the_end;
00051     } else if (!CHECKIMG(in2)) {
00052         MESSAGE('E'," Can't identify second image.");
00053         goto the_end;
00054     } else if (0 > bnd1  ||  bnd1 >= in1->nbnd) {
00055         MESSAGE('E'," Can't identify first band.");
00056         goto the_end;
00057     } else if (0 > bnd2  ||  bnd2 >= in2->nbnd) {
00058         MESSAGE('E'," Can't identify second band.");
00059         goto the_end;
00060     } else if (in1->nlin != in2->nlin) {
00061         MESSAGE('E'," Number of lines must be identical in both images.");
00062         goto the_end;
00063     } else if (in1->npix != in2->npix) {
00064         MESSAGE('E'," Number of pixels/line must be identical in both images.");
00065         goto the_end;
00066     } else if (inc <= 0) {
00067         MESSAGE('E'," Subsample increment must be greater than zero.");
00068         goto the_end;
00069     } else if (nlev <= 0) {
00070         MESSAGE('E'," Number of histogram bins must be greater than zero.");
00071         goto the_end;
00072     }
00073 
00074     /* create image of appropriate size */
00075     if (!CHECKIMG(*out)) GETMEM(1,nlev,nlev,out);
00076     if (!*out) goto the_end;
00077 
00078     /* initialize progress indicator */
00079     if (LINES  &&  !PROGRESS(psum=0.0)) goto the_end;
00080     pinc = 1.0/(double)(in1->nlin/inc + (in1->nlin%inc?1:0));
00081 
00082     /* compute min, max, and bandwidth */
00083     RANGE(in1);
00084     RANGE(in2);
00085     gmin  = min(in1->gmin,in2->gmin);
00086     gmax  = max(in1->gmax,in2->gmax);
00087     width = (double)(gmax-gmin)/(double)(nlev-1);
00088 
00089     /* initialize scattergram */
00090     for (i=0; i<nlev; i++) {
00091         for (j=0; j<nlev; j++) {
00092             (*out)->data[0][i][j] = (PIXEL)0;
00093         }
00094     }
00095 
00096     /* calculate the scattergram */
00097     for (i=0; i<in1->nlin; i+=inc) {
00098         for (j=0; j<in1->npix; j+=inc) {
00099             ix = (short)((double)(in1->data[bnd1][i][j]-gmin)/width);
00100             iy = (short)((double)(in2->data[bnd2][i][j]-gmin)/width);
00101             (*out)->data[0][ix][iy] += (PIXEL)1;
00102         }
00103         if (LINES  &&  !PROGRESS(psum+=pinc)) goto the_end;
00104     }
00105 
00106     the_end:
00107     if (TIMES) TIMING(T_EXIT);
00108 }

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