How to create an image manipulation effect similar to this website using opencv:
Using the following code:
import cv2
img = cv2.imread("./EZCUD.jpg")
img_blue = img.copy()
img_blue = cv2.cvtColor(img_blue, cv2.COLOR_BGR2HSV)
img_blue[:, :, 0] = 120
cv2.imwrite("./test.jpg", cv2.cvtColor(img_blue, cv2.COLOR_HSV2BGR))
Edit:
I managed to get a much better result by applying a gamma correction on the independent BGR channels after the HSV processing. I normalize the image to the range [0,1] and took square power in the RG channels and took the square root in the Blue channel.
This is the result:
With the following code:
import cv2
import numpy as np
img = cv2.imread("./EZCUD.jpg")
img_blue = img.copy()
img_blue = cv2.cvtColor(img_blue, cv2.COLOR_BGR2HSV)
img_blue[:, :, 0] = 120
img_blue = cv2.cvtColor(img_blue, cv2.COLOR_HSV2BGR)
img_blue = img_blue.astype("float")
img_blue /= 255
img_blue[:, :, 1:] = img_blue[:, :, 1:] ** 2
img_blue[:, :, 0] = img_blue[:, :, 0] ** (1 / 2)
img_blue *= 255
cv2.imwrite("./test.jpg", img_blue.astype("uint8"))
You can play around with these parameters until the result is closer to what you expected.
CodePudding user response:
You can try convert RGB to BGR by using cv2.cvtColor
or apply colormap with cv2.applyColorMap
import cv2
img = cv2.imread("car.jpg")
# First method
img_bgr = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
# Second method
img_ocean = cv2.applyColorMap(img, cv2.COLORMAP_OCEAN)
Here are example outputs for img_bgr
and img_ocean
. Hope it helps.
Edited: You can also try customize your own ColorMap