In [1]:
import numpy as np
import skimage
In [2]:
%load_ext watermark
%watermark -v -m -a "Lilian Besson (Naereen)" -p numpy,skimage -g
Let's import one of the example image, and blur all of it using skimage.filters.gaussian
.
In [9]:
from skimage import data, io, filters
image = data.astronaut()
In [10]:
def imshow(image):
io.imshow(image)
io.show()
In [11]:
imshow(image)
In [5]:
from skimage.filters import gaussian
In [12]:
filtered_img = gaussian(image, sigma=1, multichannel=True)
imshow(filtered_img)
In [13]:
filtered_img = gaussian(image, sigma=2, multichannel=True)
imshow(filtered_img)
In [17]:
image.shape
Out[17]:
In [71]:
def blur(image, x0, x1, y0, y1, sigma=1, imshowall=False):
x0, x1 = min(x0, x1), max(x0, x1)
y0, y1 = min(y0, y1), max(y0, y1)
im = image.copy()
sub_im = im[x0:x1,y0:y1].copy()
if imshowall: imshow(sub_im)
blur_sub_im = gaussian(sub_im, sigma=sigma)
if imshowall: imshow(blur_sub_im)
blur_sub_im = np.round(255 * blur_sub_im)
im[x0:x1,y0:y1] = blur_sub_im
return im
In [72]:
filtered_img = blur(image, 80, 180, 170, 270, sigma=1)
imshow(filtered_img)
In [76]:
filtered_img = blur(image, 80, 180, 170, 270, sigma=5)
imshow(filtered_img)
In [73]:
filtered_img = blur(image, 80, 180, 170, 270, sigma=10)
imshow(filtered_img)
In [74]:
filtered_img = blur(image, 80, 180, 170, 270, sigma=20)
imshow(filtered_img)