Instagram-style filters can be created using OpenCV image processing techniques. By adjusting color tones, brightness, contrast, and applying effects, you can design creative filters that transform normal images into stylish, social-media-ready visuals.
Converts the image into shades of gray, removing all colors.
import cv2
img = cv2.imread("photo.jpg")
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cv2.imshow("Grayscale Filter", gray)
cv2.waitKey(0)
cv2.destroyAllWindows()
Creates a warm, brownish look often seen in vintage photography.
import numpy as np
kernel = np.array([[0.272, 0.534, 0.131],
[0.349, 0.686, 0.168],
[0.393, 0.769, 0.189]])
sepia = cv2.transform(img, kernel)
cv2.imshow("Sepia Filter", sepia)
cv2.waitKey(0)
cv2.destroyAllWindows()
Inverts all colors to produce a negative photo effect.
negative = cv2.bitwise_not(img)
cv2.imshow("Negative Filter", negative)
cv2.waitKey(0)
cv2.destroyAllWindows()
Adjust brightness and contrast to enhance or darken an image.
alpha = 1.5 # Contrast control
beta = 50 # Brightness control
bright_contrast = cv2.convertScaleAbs(img, alpha=alpha, beta=beta)
cv2.imshow("Brightness & Contrast", bright_contrast)
cv2.waitKey(0)
cv2.destroyAllWindows()
Converts the photo into a cartoon-like image using edge detection and smoothing.
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
gray = cv2.medianBlur(gray, 5)
edges = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C,
cv2.THRESH_BINARY, 9, 9)
color = cv2.bilateralFilter(img, 9, 250, 250)
cartoon = cv2.bitwise_and(color, color, mask=edges)
cv2.imshow("Cartoon Effect", cartoon)
cv2.waitKey(0)
cv2.destroyAllWindows()
✅ In this lesson, you built an Instagram-like Image Filter App using OpenCV.
By combining filters such as grayscale, sepia, negative, brightness/contrast, and cartoon effects,
you can make creative filters for social media and photography applications.
👉 Next, we will learn about Image Stitching and Panorama Creation.
