Python scipy.ndimage 模块,maximum_filter() 实例源码

我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用scipy.ndimage.maximum_filter()

项目:livespin    作者:biocompibens    | 项目源码 | 文件源码
def findMaximaOnFG(self, param):
        self.defineFG(param)
        #self.smooth_corr()
        self.coorExtract = [0, 0]
        xmin, ymin = self.coorExtract


        img=self.candi
        img [self.FG ==0] =0

        im = img_as_float(img)
        image_max = ndimage.maximum_filter(im, size=10, mode='constant')
        coordinates = peak_local_max(im, min_distance=10)

        tep=np.zeros(self.candi.shape)
        for i,ide in enumerate(coordinates):
            tep[ide[0],ide[1]] = self.candi[ide[0],ide[1]]
        lbl = ndimage.label(tep)[0]
        centerc = np.round(ndimage.measurements.center_of_mass(tep, lbl, range(1,np.max(lbl)+1)))
        if centerc.size > 0:
            self.centersX = centerc[:,0].astype(int)
            self.centersY = centerc[:,1].astype(int)
        self.nComponents = len(self.centersX)
项目:nimo    作者:wolfram2012    | 项目源码 | 文件源码
def _detect(self,im):
        '''
        void cvCornerHarris( const CvArr* image, CvArr* harris_responce, int block_size, int aperture_size=3, double k=0.04 );
        '''
        gray = im.asOpenCVBW()
        #gray = opencv.cvCreateImage( opencv.cvGetSize(cvim), 8, 1 );
        corners = cv.CreateImage( cv.GetSize(gray), 32, 1 );
        #opencv.cvCvtColor( cvim, gray, opencv.CV_BGR2GRAY );

        cv.CornerHarris(gray,corners,self.block_size,self.aperture_size,self.k)

        buffer = corners.tostring()
        corners = numpy.frombuffer(buffer,numpy.float32).reshape(corners.height,corners.width).transpose()        

        footprint = ones((3,3))
        mx = maximum_filter(corners, footprint = footprint)
        local_maxima = (corners == mx) * (corners != zeros(corners.shape)) # make sure to remove completly dark points

        points = nonzero(local_maxima)
        del local_maxima

        points = array([points[0],points[1]]).transpose()
        L = []
        for each in points:
            L.append((corners[each[0],each[1]],each[0],each[1],None))

        return L
项目:imagepy    作者:Image-Py    | 项目源码 | 文件源码
def run(self, ips, snap, img, para = None):
        nimg.maximum_filter(snap, para['size'], output=img)
项目:nimo    作者:wolfram2012    | 项目源码 | 文件源码
def _detect(self,image):
        # Asssumes a two dimensional array
        A = None
        if isinstance(image,Image):
            A = image.asMatrix2D()
        elif isinstance(image,array) and len(image.shape)==2:
            A = image
        else:
            raise TypeError("ERROR Unknown Type (%s) - Only arrays and pyvision images supported."%type(image))

        filter = array(self.filter)
        assert len(filter.shape) == 2

        #feature window calculation
        del_A_1 = conv2(A,filter) 
        del_A_2 = conv2(A,filter.transpose())


        del_A_1_1 = del_A_1 * del_A_1
        matrix_1_1 = gaussian_filter(del_A_1_1, self.sigma)
        del del_A_1_1

        del_A_2_2 = del_A_2 * del_A_2
        matrix_2_2 = gaussian_filter(del_A_2_2, self.sigma)
        del del_A_2_2

        del_A_1_2 = del_A_1 * del_A_2
        matrix_1_2 = gaussian_filter(del_A_1_2, self.sigma)
        del del_A_1_2

        del del_A_1,del_A_2

        dM = matrix_1_1*matrix_2_2 - matrix_1_2*matrix_1_2
        tM = matrix_1_1+matrix_2_2

        del matrix_1_1 , matrix_1_2, matrix_2_2

        R = dM-self.k*pow(tM,2)

        footprint = ones((self.radius,self.radius))
        mx = maximum_filter(R, footprint = footprint)
        local_maxima = (R == mx) * (R != zeros(R.shape)) # make sure to remove completly dark points
        del mx

        points = nonzero(local_maxima)
        del local_maxima

        points = array([points[0],points[1]]).transpose()
        L = []
        for each in points:
            L.append((R[each[0],each[1]],each[0],each[1],None))

        del R

        return L