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.
Use the package manager pip to install cv2 and numpy.
pip install cv2
pip install numpy
Use import keyword to import modules.
import cv2
import numpy as np
img = cv2.imread("cat.png")
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.
result = np.copy(image) #stored into result variable
#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])
#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)
#split into channels
B, G, R = cv2.split(result)
#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)
#mege the channels
result = cv2.merge([B, G, R])
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)
cv2.imshow("image", image)
cv2.imshow("result", result)
cv2.waitKey(0)
cv2.destroyAllWindows()