Example #1
0
    def __init__(self,
                 img_shape,
                 blur_sigma,
                 flow_sigma,
                 normalize_max=False,
                 **kwargs):
        super(RandFlow, self).__init__(**kwargs)
        n_dims = len(img_shape) - 1

        self.flow_shape = img_shape[:-1] + (n_dims, )

        if blur_sigma > 0:
            blur_kernel = image_utils.create_gaussian_kernel(blur_sigma,
                                                             n_dims=n_dims)
            # TODO: make this work for 3D
            if n_dims == 2:
                blur_kernel = np.tile(
                    np.reshape(blur_kernel, blur_kernel.shape + (1, 1)),
                    tuple([1] * n_dims) + (n_dims, 1))
            else:
                blur_kernel = np.reshape(blur_kernel,
                                         blur_kernel.shape + (1, 1))
            self.blur_kernel = tf.constant(blur_kernel, dtype=tf.float32)
        else:
            self.blur_kernel = None
        self.flow_sigma = flow_sigma
        self.normalize_max = normalize_max
        self.n_dims = n_dims
        print('Randflow dims: {}'.format(self.n_dims))
Example #2
0
    def __init__(self, img_shape, blur_sigma, **kwargs):
        super(BlurFlow, self).__init__(**kwargs)
        n_dims = len(img_shape) - 1

        self.flow_shape = tuple(img_shape[:-1]) + (n_dims,)

        blur_kernel = image_utils.create_gaussian_kernel(blur_sigma, n_dims=n_dims, n_sigmas_per_side=2)
        # TODO: make this work for 3D
        if n_dims == 2:
            blur_kernel = np.tile(np.reshape(blur_kernel, blur_kernel.shape + (1, 1)),
                                  tuple([1] * n_dims) + (n_dims, 1))
        else:
            blur_kernel = np.reshape(blur_kernel, blur_kernel.shape + (1, 1))
        self.blur_kernel = tf.constant(blur_kernel, dtype=tf.float32)
        self.n_dims = n_dims
Example #3
0
    def __init__(self, img_shape, dilate_kernel_size, blur_sigma, flow_sigma, **kwargs):
        super(DilateAndBlur, self).__init__(**kwargs)
        n_dims = len(img_shape) - 1

        self.flow_shape = img_shape[:-1] + (n_dims,)

        dilate_kernel = np.reshape(
                cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (dilate_kernel_size, dilate_kernel_size)),
                (dilate_kernel_size, dilate_kernel_size, 1, 1))
        self.dilate_kernel = tf.constant(dilate_kernel, dtype=tf.float32)

        blur_kernel = image_utils.create_gaussian_kernel(blur_sigma, n_dims=n_dims)
        blur_kernel = np.reshape(blur_kernel, blur_kernel.shape + (1, 1))
        blur_kernel = blur_kernel / np.max(blur_kernel)  # normalize by max instead of by sum

        self.blur_kernel = tf.constant(blur_kernel, dtype=tf.float32)
        self.flow_sigma = flow_sigma
    def __init__(self, n_chans=3, n_dims=2, do_blur=True, **kwargs):
        super(Blur_Downsample, self).__init__(**kwargs)
        scale_factor = 0.5  # we only support halving right now

        if do_blur:
            # according to scikit-image.transform.rescale documentation
            blur_sigma = (1. - scale_factor) / 2

            blur_kernel = image_utils.create_gaussian_kernel(blur_sigma, n_dims=n_dims, n_sigmas_per_side=4)
            #			if n_dims==2:
            #				blur_kernel = np.tile(np.reshape(blur_kernel, blur_kernel.shape + (1, 1)), tuple([1] * n_dims) + (n_chans, 1))
            #			else:
            blur_kernel = np.reshape(blur_kernel, blur_kernel.shape + (1, 1))
            self.blur_kernel = tf.constant(blur_kernel, dtype=tf.float32)
        else:
            self.blur_kernel = tf.constant(np.ones([1] * n_dims + [1, 1]), dtype=tf.float32)
        self.n_dims = n_dims
        self.n_chans = n_chans
Example #5
0
    def __init__(self, n_chans, n_dims, do_blur=True, **kwargs):
        super(Blur_Downsample, self).__init__(**kwargs)
        scale_factor = 0.5 # we only support halving right now

        if do_blur:
            # according to scikit-image.transform.rescale documentation
            blur_sigma = (1. - scale_factor) / 2

            blur_kernel = image_utils.create_gaussian_kernel(blur_sigma, n_dims=n_dims, n_sigmas_per_side=4)
            if n_dims==2:
                blur_kernel = np.tile(np.reshape(blur_kernel, blur_kernel.shape + (1,1)), tuple([1]*n_dims) + (n_dims, 1))
            else:
                blur_kernel = np.reshape(blur_kernel, blur_kernel.shape + (1,1))
            self.blur_kernel = tf.constant(blur_kernel, dtype=tf.float32)
        else:
            self.blur_kernel = tf.constant(np.ones([1] * n_dims + [1, 1]), dtype=tf.float32)
        self.n_dims = n_dims
        self.n_chans = n_chans