/Warming-Effect

Warming Effect with Python

Primary LanguagePython

Warming Effect

Here we are with another filter effect Warming Effect.
In this session you will know about how to utilize and build lookup_table,splitting RGB channels,
applying mapping to channels & merging channels.
As we are manipulating warming effect hecnce we have to work with Only red & blue channels,
we don't need to distort green channel.
This is an important project to sharpen your skills on openCV.

Tools and Languages:

OpenCV

VS Code

pip

Python


Installation

Use the package manager pip to install cv2 and numpy.

pip install cv2
pip install numpy

Import

Use import keyword to import modules.

import cv2
import numpy as np

Reading image from file

img = cv2.imread("cat.png")

Steps to be followed:

1.First create a copy of the image to work on.
2.Set original x & y-axis values.
3.Create and set Lookup Table of both channels.
4.Split the channels.
5.Apply Lookuptable-mapping into both channels.
6.For desired output merge the channels.

Step-1:

result = np.copy(image) #stored into result variable

Step-2:

#Original x-axis values
originalValues = np.array([0, 50, 100, 150, 200, 255])
#changes Y-axis values for red and blue channel
redValues = np.array([0, 80, 150, 190, 220, 255])
blueValues = np.array([0, 20, 40, 75, 150, 255])

Step-3:

#create lookup table for red channel
allValues = np.arange(0, 256)
redLookupTable = np.interp(allValues, originalValues, redValues)

#create lookup table for blue channel
blueLookupTable = np.interp(allValues, originalValues, blueValues)

Step-4:

#split into channels
B, G, R = cv2.split(result)

Step-5:

#apply mapping to red channel
R = cv2.LUT(R, redLookupTable)
R = np.uint8(R)

#apply mapping to blue channel
B = cv2.LUT(B, blueLookupTable)
B = np.uint8(B)

Step-6:

#mege the channels
result = cv2.merge([B, G, R])

Now we are going to apply windows to display images.

Windows are used to manipulate out-put screen or screens to be displayed.

#create windows to display images
cv2.namedWindow("image", cv2.WINDOW_NORMAL)
cv2.namedWindow("result", cv2.WINDOW_NORMAL)

Comparing original vs grayscale

cv2.imshow("image", image)
cv2.imshow("result", result)
cv2.waitKey(0)
cv2.destroyAllWindows()

Images

Original png Warmed

Developed by

Ashish ku. Behera