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
00017 SCATTER (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   )
00027 {
00028   register short i, j, ix, iy;
00029   char msg[SLEN];
00030   double width, pinc, psum;
00031   PIXEL gmin, gmax;
00032 
00033   if (TIMES)
00034     TIMING (T_SCATTER);
00035   if (NAMES)
00036     {
00037       MESSAGE ('I', "");
00038       MESSAGE ('I', "SCATTER");
00039       MESSAGE ('I', "");
00040       sprintf (msg, " First input image:                    %s - band %d",
00041                in1->text, bnd1 + 1);
00042       MESSAGE ('I', msg);
00043       sprintf (msg, " Second input image:                   %s - band %d",
00044                in2->text, bnd2 + 1);
00045       MESSAGE ('I', msg);
00046       sprintf (msg, " Histogram resolution:                 %d", nlev);
00047       MESSAGE ('I', msg);
00048       sprintf (msg, " Line and pixel subsample increment:   %d", inc);
00049       MESSAGE ('I', msg);
00050       MESSAGE ('I', " ...............");
00051     }
00052 
00053   /* check input */
00054   if (!CHECKIMG (in1))
00055     {
00056       MESSAGE ('E', " Can't identify first image.");
00057       goto the_end;
00058     }
00059   else if (!CHECKIMG (in2))
00060     {
00061       MESSAGE ('E', " Can't identify second image.");
00062       goto the_end;
00063     }
00064   else if (0 > bnd1 || bnd1 >= in1->nbnd)
00065     {
00066       MESSAGE ('E', " Can't identify first band.");
00067       goto the_end;
00068     }
00069   else if (0 > bnd2 || bnd2 >= in2->nbnd)
00070     {
00071       MESSAGE ('E', " Can't identify second band.");
00072       goto the_end;
00073     }
00074   else if (in1->nlin != in2->nlin)
00075     {
00076       MESSAGE ('E', " Number of lines must be identical in both images.");
00077       goto the_end;
00078     }
00079   else if (in1->npix != in2->npix)
00080     {
00081       MESSAGE ('E',
00082                " Number of pixels/line must be identical in both images.");
00083       goto the_end;
00084     }
00085   else if (inc <= 0)
00086     {
00087       MESSAGE ('E', " Subsample increment must be greater than zero.");
00088       goto the_end;
00089     }
00090   else if (nlev <= 0)
00091     {
00092       MESSAGE ('E', " Number of histogram bins must be greater than zero.");
00093       goto the_end;
00094     }
00095 
00096   /* create image of appropriate size */
00097   if (!CHECKIMG (*out))
00098     GETMEM (1, nlev, nlev, out);
00099   if (!*out)
00100     goto the_end;
00101 
00102   /* initialize progress indicator */
00103   if (LINES && !PROGRESS (psum = 0.0))
00104     goto the_end;
00105   pinc = 1.0 / (double) (in1->nlin / inc + (in1->nlin % inc ? 1 : 0));
00106 
00107   /* compute min, max, and bandwidth */
00108   RANGE (in1);
00109   RANGE (in2);
00110   gmin = min (in1->gmin, in2->gmin);
00111   gmax = max (in1->gmax, in2->gmax);
00112   width = (double) (gmax - gmin) / (double) (nlev - 1);
00113 
00114   /* initialize scattergram */
00115   for (i = 0; i < nlev; i++)
00116     {
00117       for (j = 0; j < nlev; j++)
00118         {
00119           (*out)->data[0][i][j] = (PIXEL) 0;
00120         }
00121     }
00122 
00123   /* calculate the scattergram */
00124   for (i = 0; i < in1->nlin; i += inc)
00125     {
00126       for (j = 0; j < in1->npix; j += inc)
00127         {
00128           ix = (short) ((double) (in1->data[bnd1][i][j] - gmin) / width);
00129           iy = (short) ((double) (in2->data[bnd2][i][j] - gmin) / width);
00130           (*out)->data[0][ix][iy] += (PIXEL) 1;
00131         }
00132       if (LINES && !PROGRESS (psum += pinc))
00133         goto the_end;
00134     }
00135 
00136 the_end:
00137   if (TIMES)
00138     TIMING (T_EXIT);
00139 }

Generated on Sun May 18 15:36:18 2003 for tclSadie by doxygen1.3