I am trying to separate the CMYK channels from an RGB image to be used later. The question np.dstack() does not recreate original image in OpenCV is my earlier question using a test image. I decided to run it again with a different image and it returned some results and I don't know what's happening.
The issue with this is the results do not match the original image as they are supposed to.
Left: Original Image
Top Right: Result as .jpg
Bottom Right: Result as .tif
Code:
import cv2
import numpy as np
# Load image
bgr = cv2.imread('xpwallpaper.jpg')
# Make float and divide by 255 to give BGRdash
bgrdash = bgr.astype(np.float)/255.
# Calculate K as (1 - whatever is biggest out of Rdash, Gdash, Bdash)
K = 1 - np.max(bgrdash, axis=2)
# Calculate C
C = (1-bgrdash[...,2] - K)/(1-K)
# Calculate M
M = (1-bgrdash[...,1] - K)/(1-K)
# Calculate Y
Y = (1-bgrdash[...,0] - K)/(1-K)
# Combine 4 channels into single image and re-scale back up to uint8
CMYK = (np.dstack((C,M,Y,K))*255).astype(np.uint8)
cv2.imwrite("CMYK.jpg", CMYK)