(self)
Perform a single step of the morphological Chan-Vese evolution.
Perform a single step of the morphological Chan-Vese evolution.
Perform a single step of the morphological Chan - Vese evolution .
def step(self):
        """Perform a single step of the morphological Chan-Vese evolution."""
        # Assign attributes to local variables for convenience.
        u = self._u
        
        if u is None:
            raise ValueError("the levelset function is not set "
                             "(use set_levelset)")
        
        data = self.data
        
        # Determine c0 and c1.
        inside = (u > 0)
        outside = (u <= 0)
        c0 = data[outside].sum() / float(outside.sum())
        c1 = data[inside].sum() / float(inside.sum())
        
        # Image attachment.
        dres = np.array(np.gradient(u))
        abs_dres = np.abs(dres).sum(0)
        #aux = abs_dres * (c0 - c1) * (c0 + c1 - 2*data)
        aux = abs_dres * (self.lambda1*(data - c1) ** 2 -
                          self.lambda2*(data - c0) ** 2)
        
        res = np.copy(u)
        res[aux < 0] = 1
        res[aux > 0] = 0
        
        # Smoothing.
        for i in range(self.smoothing):
            res = curvop(res)
        
        self._u = res
def step ( self ) : # Assign attributes to local variables for convenience. u = self . _u if u is None : raise ValueError ( "the levelset function is not set " "(use set_levelset)" ) data = self . data # Determine c0 and c1. inside = ( u > 0 ) outside = ( u <= 0 ) c0 = data [ outside ] . sum ( ) / float ( outside . sum ( ) ) c1 = data [ inside ] . sum ( ) / float ( inside . sum ( ) ) # Image attachment. dres = np . array ( np . gradient ( u ) ) abs_dres = np . abs ( dres ) . sum ( 0 ) #aux = abs_dres * (c0 - c1) * (c0 + c1 - 2*data) aux = abs_dres * ( self . lambda1 * ( data - c1 ) ** 2 - self . lambda2 * ( data - c0 ) ** 2 ) res = np . copy ( u ) res [ aux < 0 ] = 1 res [ aux > 0 ] = 0 # Smoothing. for i in range ( self . smoothing ) : res = curvop ( res ) self . _u = res