Blur image using GaussianBlur operatorΒΆ

[1]:
import torch
import torchgeometry as tgm

import cv2
[2]:
# read the image with OpenCV
image = cv2.imread('./data/lena.jpg')[..., (2,1,0)]
print(image.shape)

img = tgm.image_to_tensor(image)
img = torch.unsqueeze(img.float(), dim=0)  # BxCxHxW
(512, 512, 3)
[3]:
# create the operator
gauss = tgm.image.GaussianBlur((11, 11), (10.5, 10.5))

# blur the image
img_blur = gauss(img)

# convert back to numpy
image_blur = tgm.tensor_to_image(img_blur.byte())
[4]:
import matplotlib.pyplot as plt
%matplotlib inline

# create the plot
fig, axs = plt.subplots(1, 2, figsize=(16, 10))
axs = axs.ravel()

axs[0].axis('off')
axs[0].set_title('image source')
axs[0].imshow(image)

axs[1].axis('off')
axs[1].set_title('image blurred')
axs[1].imshow(image_blur)
[4]:
<matplotlib.image.AxesImage at 0x7f3d4f396160>
_images/gaussian_blur_4_1.png