/********************************************************************* * filtered = modefilt2_mex(img,win,ignore) * * Each pixel in the output gets the mode of its neighbors in the input. * The local neighborhood is defined by . Also, numbers below ignore * are not considered when computing the modes. * * Inputs: * > img: 2D double matrix holding only positive integers (I know) * > win: [x_window_radius, y_window_radius] * > ignore: minimum value of pixels to consider (0 to consider all pixels) * * Outputs: * > filtered: 2D double matrix size(img) with filter result. * * * Coded by: Shawn Lankton, April 2008, (www.shawnlankton.com) * ********************************************************************/ #include #include /* Definitions to keep compatibility with earlier versions of ML */ #ifndef MWSIZE_MAX typedef int mwSize; typedef int mwIndex; typedef int mwSignedIndex; #if (defined(_LP64) || defined(_WIN64)) && !defined(MX_COMPAT_32) /* Currently 2^48 based on hardware limitations */ # define MWSIZE_MAX 281474976710655UL # define MWINDEX_MAX 281474976710655UL # define MWSINDEX_MAX 281474976710655L # define MWSINDEX_MIN -281474976710655L #else # define MWSIZE_MAX 2147483647UL # define MWINDEX_MAX 2147483647UL # define MWSINDEX_MAX 2147483647L # define MWSINDEX_MIN -2147483647L #endif #define MWSIZE_MIN 0UL #define MWINDEX_MIN 0UL #endif double max(double a,double b){ if(a>b) return a; return b;} double min(double a,double b){ if(apenmax) // if its a new mode { penmax = pen[idx]; // update bin count max mode = idx; // update mode } } } f[i*dimy+j]=mode; // set output pixel to mode from window } } return; }