Example #1
0
def test_denoise_bilateral_3d():
    img = lena
    # add some random noise
    img += 0.5 * img.std() * np.random.random(img.shape)
    img = np.clip(img, 0, 1)

    out1 = filter.denoise_bilateral(img, sigma_range=0.1, sigma_spatial=20)
    out2 = filter.denoise_bilateral(img, sigma_range=0.2, sigma_spatial=30)

    # make sure noise is reduced
    assert img.std() > out1.std()
    assert out1.std() > out2.std()
def test_denoise_bilateral_3d():
    img = lena
    # add some random noise
    img += 0.5 * img.std() * np.random.random(img.shape)
    img = np.clip(img, 0, 1)

    out1 = filter.denoise_bilateral(img, sigma_range=0.1, sigma_spatial=20)
    out2 = filter.denoise_bilateral(img, sigma_range=0.2, sigma_spatial=30)

    # make sure noise is reduced
    assert img.std() > out1.std()
    assert out1.std() > out2.std()
Example #3
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)
                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
Example #4
0
def loop(imgFiles):
	for f in imgFiles:
		img = img_as_float(data.load(os.path.join(inputDir,f)))
		startTime = time.time()
		img = filter.denoise_bilateral(img, sigma_range=0.1, sigma_spatial=3)
		io.imsave(os.path.join(outputDirg,f), img)
		print("Took %f seconds for %s" %(time.time() - startTime, f))
Example #5
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
lena = lena[220:300, 220:320]

noisy = lena + 0.6 * lena.std() * np.random.random(lena.shape)
noisy = np.clip(noisy, 0, 1)

fig, ax = plt.subplots(nrows=2, ncols=3, figsize=(8, 5))

plt.gray()

ax[0, 0].imshow(noisy)
ax[0, 0].axis('off')
ax[0, 0].set_title('noisy')
ax[0, 1].imshow(denoise_tv_chambolle(noisy, weight=0.1, multichannel=True))
ax[0, 1].axis('off')
ax[0, 1].set_title('TV')
ax[0, 2].imshow(denoise_bilateral(noisy, sigma_range=0.05, sigma_spatial=15))
ax[0, 2].axis('off')
ax[0, 2].set_title('Bilateral')

ax[1, 0].imshow(denoise_tv_chambolle(noisy, weight=0.2, multichannel=True))
ax[1, 0].axis('off')
ax[1, 0].set_title('(more) TV')
ax[1, 1].imshow(denoise_bilateral(noisy, sigma_range=0.1, sigma_spatial=15))
ax[1, 1].axis('off')
ax[1, 1].set_title('(more) Bilateral')
ax[1, 2].imshow(lena)
ax[1, 2].axis('off')
ax[1, 2].set_title('original')

fig.subplots_adjust(wspace=0.02, hspace=0.2,
                    top=0.9, bottom=0.05, left=0, right=1)
Example #7
0
lena = lena[220:300, 220:320]

noisy = lena + 0.6 * lena.std() * np.random.random(lena.shape)
noisy = np.clip(noisy, 0, 1)

fig, ax = plt.subplots(nrows=2, ncols=3, figsize=(8, 5))

plt.gray()

ax[0, 0].imshow(noisy)
ax[0, 0].axis('off')
ax[0, 0].set_title('noisy')
ax[0, 1].imshow(denoise_tv_chambolle(noisy, weight=0.1, multichannel=True))
ax[0, 1].axis('off')
ax[0, 1].set_title('TV')
ax[0, 2].imshow(denoise_bilateral(noisy, sigma_range=0.05, sigma_spatial=15))
ax[0, 2].axis('off')
ax[0, 2].set_title('Bilateral')

ax[1, 0].imshow(denoise_tv_chambolle(noisy, weight=0.2, multichannel=True))
ax[1, 0].axis('off')
ax[1, 0].set_title('(more) TV')
ax[1, 1].imshow(denoise_bilateral(noisy, sigma_range=0.1, sigma_spatial=15))
ax[1, 1].axis('off')
ax[1, 1].set_title('(more) Bilateral')
ax[1, 2].imshow(lena)
ax[1, 2].axis('off')
ax[1, 2].set_title('original')

fig.subplots_adjust(wspace=0.02, hspace=0.2,
                    top=0.9, bottom=0.05, left=0, right=1)
Example #8
0
import os, sys
from skimage import io
from skimage import filter

kidney_image = io.imread("color_img.bmp")
print kidney_image.shape

# estimate the noise in the image


# io.imshow (kidney_image) #have to set display to make this work


# do a test denosing using a total variation filter
kidney_image_denoised_tv = filter.denoise_tv_chambolle(kidney_image, weight=0.1)
io.imsave("kidney_image_denoised_tv.bmp", test_image_denoised_tv)

# do a test denosing using a lateral filter to preserve edges
kidney_image_denoised_lateral = filter.denoise_bilateral(kidney_image, sigma_range=0.05, sigma_spatial=15)

# save the denoised image
io.imsave("kidney_image_denoised_lateral.bmp", test_image_denoised_lateral)
Example #9
0
def bilateral(ubyte_frame):
    return img_as_ubyte(denoise_bilateral(img_as_float(ubyte_frame), sigma_range=0.3, sigma_spatial=15, win_size=10))