Exemplo n.º 1
0
def smoothing_bilateral(data,
                        sigma_space=15,
                        sigma_color=0.05,
                        pseudo_3D='True',
                        sliceId=2):
    if data.ndim == 3 and pseudo_3D:
        if sliceId == 2:
            for idx in range(data.shape[2]):
                temp = skifil.denoise_bilateral(data[:, :, idx],
                                                sigma_range=sigma_color,
                                                sigma_spatial=sigma_space)
                # temp = skires.denoise_bilateral(data[:, :, idx], sigma_range=sigma_color, sigma_spatial=sigma_space)
                data[:, :, idx] = (255 * temp).astype(np.uint8)
        elif sliceId == 0:
            for idx in range(data.shape[0]):
                temp = skifil.denoise_bilateral(data[idx, :, :],
                                                sigma_range=sigma_color,
                                                sigma_spatial=sigma_space)
                # temp = skires.denoise_bilateral(data[idx, :, :], sigma_range=sigma_color, sigma_spatial=sigma_space)
                data[idx, :, :] = (255 * temp).astype(np.uint8)
    else:
        data = skifil.denoise_bilateral(data,
                                        sigma_range=sigma_color,
                                        sigma_spatial=sigma_space)
        # data = skires.denoise_bilateral(data, sigma_range=sigma_color, sigma_spatial=sigma_space)
        data = (255 * data).astype(np.uint8)
    return data
Exemplo n.º 2
0
Arquivo: tools.py Projeto: mjirik/lisa
def smoothing_bilateral(data, sigma_space=15, sigma_color=0.05, pseudo_3D='True', sliceId=2):
    if data.ndim == 3 and pseudo_3D:
        if sliceId == 2:
            for idx in range(data.shape[2]):
                temp = skifil.denoise_bilateral(data[:, :, idx], sigma_range=sigma_color, sigma_spatial=sigma_space)
                data[idx, :, :] = (255 * temp).astype(np.uint8)
        elif sliceId == 0:
            for idx in range(data.shape[0]):
                temp = skifil.denoise_bilateral(data[idx, :, :], sigma_range=sigma_color, sigma_spatial=sigma_space)
                data[idx, :, :] = (255 * temp).astype(np.uint8)
    else:
        data = skifil.denoise_bilateral(data, sigma_range=sigma_color, sigma_spatial=sigma_space)
        data = (255 * data).astype(np.uint8)
    return data
Exemplo n.º 3
0
def bilateral_blur_gray_image_nz(image_nz, image_shape, mask_nz, sigma_range, sigma_spatial):
    """ Blur a masked grayscale image """

    # deal with the mask -- set the unmasked entries to the average
    orig_mean = np.mean(image_nz)
    image = np.empty(image_shape[0:2])
    image.fill(orig_mean)
    image[mask_nz] = image_nz

    blurred = denoise_bilateral(
        image,
        sigma_range=sigma_range,
        sigma_spatial=sigma_spatial,
        win_size=max(int(sigma_spatial * 2), 3),
        mode='reflect',
    )
    blurred_nz = blurred[mask_nz]

    # adjust to keep the mean the same
    new_mean = np.mean(blurred_nz)
    blurred_nz *= orig_mean / new_mean
    return blurred_nz