Selon David Schleef <d...@schleef.org> : > > Sorting neighboring pixel values is a particularly dumb method of > > doing a CWM filter (when all you want is the median), so fixing the > > dumb method of sorting is not really going to make the code good. > > The correct way to do CWM is roughly min(max(center,min(neighbors), > > max(neighbors)), at least for weight=4. (IIRC, this is from memory)
If this is only for to find the median, this code seem to produce a good approximation of the true median for a 3x3 patch (in fact, this seem to return the true median value the majority of time) inline int median3(int a, int b, int c) { if ( a <= b ) { if ( b <= c ) return b; if ( c <= a ) return a; return c; } // a > b if ( a <= c ) return a; if ( b <= c ) return c; return b; } void fast_median3x3(int *d) { int m1, m2 ,m3, m4; m1 = median3(d[0], d[1], d[2]); m2 = median3(d[3], d[4], d[5]); m3 = median3(d[6], d[7], d[8]); return median3(m1,m2,m3); } Note that the median3() func is coded very ugly and can certainly to be coded for to be very more speed (it only return the median from 3 values) On other side, I have found something that produce one approximation of the median for patchs biggers than 3x3, but the value returned can be very far from the true median value :( (n=9 for 3x3 patchs and n have always to be >= 3) int approx_median(int *d , int n) { int i, v, imin=255, imax=-255, sum = 0; for (i= 0; i < n; i++ ) { v = d[i]; if (v < imin ) { imin = v; } else if ( v > imax ) { imax = v; } sum += v; } return (sum - imin - imax)/(n-2); } In fact, this compute the mean but without the minimum and maximum extrems values (this can for example to be used for to filter pictures with a little impulsed white noise) PS : I always don't understand the signification of "min(max(center,min(neighbors),max(neighbors)), at least for weight=4" :( @+ Yannoo ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Schrodinger-devel mailing list Schrodinger-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/schrodinger-devel