|
G'day All
I was wondering if someone can help me with some
C++ coding for a filter I want to run in ERMapper. The code I am trying to use
is shown below. Basically I am trying to create (1) a circular filter that will
pick the brightest pixel within the defined radius and (2) a circular filter
that will pick the darkest pixel within a defined radius (I am will use the
filters on a DEM to create a map of local relief). A friend of mine helped
me write the code below, but it doesn't seem to be working properly. When I run
either filter using a diameter of 69 pixels, I get prominent overlapping
circular patterns all over the map at ~same sacle as the filter itself .... and
I don't think that should happen. Could someone check the code below and tell if
I have done anything screwy????
Cheers
Ken Hickey
/*
** circ_ranking.c ** ** Includes several kernel functions: ** ** dark_pixel - returns the darkest pixel in the kernel ** bright_pixel - returns the brightest pixel in the kernel ** ** [01] sns 18-jun-93 Created file ** [02] dh 27-Aug-93 Modified to use values.h and -MAXDOUBLE instead of ** MINDOUBLE ** [03] aph 18-Oct-93 Modified dark_pixel to use a 2d array rather than ** pointers, to fix coredump bug. */ #ifdef NOTUSED /* [02[ */
#define MAXDOUBLE 1e+308 /* actually a bit larger than this */ #define MINDOUBLE 1e-308 #endif // commented the following out (April
2002)
//#if ! defined(win32) //#include <values.h> /* [02] */ //#else #include <float.h> #include <math.h> #define MAXDOUBLE DBL_MAX //#endif /* * * * * * * * * * * * * * * * * * * */
/*
The functions in this file return the
darkest and lightest
pixels with a cicular filter kernal. The radius of the circle is assumed to be 1/2 (nr_rows-1) and while we don't check it is assumed that nr_rows = nr_cols Modifications by April
2002
*/
double dark_pixel(nr_rows, nr_cols, array) int nr_rows; int nr_cols; double **array; { double darkest = MAXDOUBLE; int r; int c; int cen_row; int cen_col; /*
** # This code coredumps [03] # ** int i = nr_rows * nr_cols; ** while(i>0) { ** if( darkest > **array ) darkest = **array; ** --i; ** ++array; ** } */ cen_row = (nr_rows-1)/2; cen_col = (nr_cols-1)/2; for (r = 0; r < nr_rows; r++)
for (c = 0; c < nr_cols; c++) if (sqrt(pow((double) (r-cen_row),2.)+pow((double) (c-cen_col),2.)) <= cen_row) if( darkest > array[r][c] ) darkest = array[r][c]; return(darkest);
} double bright_pixel(nr_rows, nr_cols, array)
int nr_rows; int nr_cols; double **array; { int r; int c; int cen_row; int cen_col; double brightest = -MAXDOUBLE; /* [02] */ cen_row =
(nr_rows-1)/2;
cen_col = (nr_cols-1)/2; for (r = 0; r < nr_rows; r++)
for (c = 0; c < nr_cols; c++) if (sqrt(pow((double) (r-cen_row),2.)+pow((double) (c-cen_col),2.)) <= cen_row) if( brightest < array[r][c]) brightest = array[r][c]; return(brightest);
}
/* * * * * * * * * * * * * * * * * * * */
------------------------------------------------------------------ Kenneth Hickey Mineral Deposit Research Unit (MDRU) Department of Earth and Ocean Sciences University of British Columbia 6339 Stores Rd, Vancouver, BC V6T 1Z4, Canada phone +1-604-822-3765; Fax +1-604-822-6088 email: [EMAIL PROTECTED] . |
