def spectrum_mask(size):
    """Creates a mask to filter the image of size size"""
    import numpy as np
    from scipy.ndimage.morphology import distance_transform_edt as distance

    ftmask = np.ones(size)

    # Set zeros on corners
    # ftmask[0, 0] = 0
    # ftmask[size[0] - 1, size[1] - 1] = 0
    # ftmask[0, size[1] - 1] = 0
    # ftmask[size[0] - 1, 0] = 0
    ftmask[size[0] // 2, size[1] // 2] = 0

    # Distance transform
    ftmask = distance(ftmask)
    ftmask /= ftmask.max()

    # Keep this just in case we want to switch to the opposite filter
    ftmask *= -1.0
    ftmask += 1.0

    ftmask[ftmask >= 0.4] = 1
    ftmask[ftmask < 1] = 0
    return ftmask
Beispiel #2
0
def spectrum_mask(size):
    """Creates a mask to filter the image of size size"""
    import numpy as np
    from scipy.ndimage.morphology import distance_transform_edt as distance

    ftmask = np.ones(size)

    # Set zeros on corners
    # ftmask[0, 0] = 0
    # ftmask[size[0] - 1, size[1] - 1] = 0
    # ftmask[0, size[1] - 1] = 0
    # ftmask[size[0] - 1, 0] = 0
    ftmask[size[0]/2, size[1]/2] = 0

    # Distance transform
    ftmask = distance(ftmask)
    ftmask /= ftmask.max()

    # Keep this just in case we want to switch to the opposite filter
    ftmask *= -1.0
    ftmask += 1.0

    ftmask[ftmask >= 0.4] = 1
    ftmask[ftmask < 1] = 0
    return ftmask
Beispiel #3
0
def wfm(FG, GT):
    dGT = np.asarray(GT, np.float32)
    dGT /= (GT.max() + 1e-8)

    E = np.abs(FG - dGT)
    Dst, Idxt = distance(dGT, return_indices=True)
    Et = E
    Et[~GT] = Et[Idxt[~GT]]
    EA = imfilter(Et, 'blur')
    MIN_E_EA = E
    MIN_E_EA[GT & EA < E] = EA[GT & EA < E]
    B = np.ones(GT.shape)
    B[~GT] = 2.0 - 1 * math.exp(math.log(1 - 0.5) / 5. * Dst[~GT])
    Ew = np.multiply(MIN_E_EA, B)

    TPw = np.sum(dGT[:] - np.sum(np.sum(Ew[GT])))
    FPw = np.sum(np.sum(Ew[~GT]))
    R = np.mean(Ew[GT])
    P = TPw
 def reset_phi(self, mask):
     phi = distance(1 - self.mask) - distance(self.mask) + self.mask
     return phi
 def get_phi(self):
     phi = distance(1 - self.mask) - distance(self.mask) + self.mask
     return phi