Blurring and sharpening images
Blurring and sharpening are image processing operations used to enhance the input images.
How to do it...
- Import the Computer Vision package -
cv2
:
import cv2 # Import Numerical Python package - numpy as np import numpy as np
- Read the image using the built-in
imread
function:
image = cv2.imread('image_6.jpg')
- Display the original image using the built-in
imshow
function:
cv2.imshow("Original", image)
- Wait until any key is pressed:
cv2.waitKey(0)
- Execute the pixel level action with the blurring operation:
# Blurring images: Averaging, cv2.blur built-in function # Averaging: Convolving image with normalized box filter # Convolution: Mathematical operation on 2 functions which produces third function. # Normalized box filter having size 3 x 3 would be: # (1/9) [[1, 1, 1], # [1, 1, 1], # [1, 1, 1]] blur = cv2.blur(image,(9,9)) # (9 x 9) filter is used
- Display the blurred image:
cv2.imshow('Blurred', blur)
- Wait until any key is pressed:
cv2.waitKey...