Color Images

Matplotlib expects the image to be in RGB format whereas OpenCV stores images in BGR format. Thus, for correct display, we need to reverse the channel order of the image in order to properly render the color of the image.

# Swap the Red and Blue color channels.
logo_img = logo_img[:, :, ::-1]

# Use cv2.IMREAD_UNCHANGED to read in a PNG with an alpha channel.
logo = "Pytorch_logo.png"
logo_img = cv2.imread(logo, cv2.IMREAD_UNCHANGED)

# Swap the Red and Blue color channels using: cv2.COLOR_BGRA2RGBA.
logo_img = cv2.cvtColor(logo_img, cv2.COLOR_BGRA2RGBA)

# Display the image.
plt.figure(figsize = (12, 12))

# Split the image into the B,G,R components.
img_bgr = cv2.imread('Emerald_Lakes_New_Zealand.jpg', cv2.IMREAD_COLOR)
b, g, r = cv2.split(img_bgr)

# Merge the individual channels into a BGR image.
imgMerged = cv2.merge((r, g, b))

# Change to HSV Color Space
img_hsv = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2HSV)

# Split the image into the H, S, V components.
h, s, v = cv2.split(img_hsv)

# Modify Individual Color Channels
h_new = h + 10
img_hsv_merged = cv2.merge((h_new, s, v))
img_rgb_merged = cv2.cvtColor(img_hsv_merged, cv2.COLOR_HSV2RGB)