O'Reilly logo

OpenCV with Python By Example by Prateek Joshi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating a vignette filter

Using all the information we have, let's see if we can create a nice vignette filter. The output will look something like the following:

Creating a vignette filter

Here is the code to achieve this effect:

import cv2 import numpy as np img = cv2.imread('input.jpg') rows, cols = img.shape[:2] # generating vignette mask using Gaussian kernels kernel_x = cv2.getGaussianKernel(cols,200) kernel_y = cv2.getGaussianKernel(rows,200) kernel = kernel_y * kernel_x.T mask = 255 * kernel / np.linalg.norm(kernel) output = np.copy(img) # applying the mask to each channel in the input image for i in range(3): output[:,:,i] = output[:,:,i] * mask cv2.imshow('Original', ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required