我正在尝试使用Python提取CMYK图像的K通道。然而,结果是一个反向通道。以下是我使用的代码:
# Import Packages import numpy as np from PIL import Image # Define method def get_k_channel(filepath): # Read CMYK image img_cmyk = np.array(Image.open(filepath)) # Extract K channel # I also tried with [:, :, -1] slicing img_k = img_cmyk[:, :, 3] # Image to uint8 img_k = img_k.astype(np.uint8) # NumPy image to PIL object img_pil = Image.fromarray(img_k) # Mode L for grayscale images img_pil.mode = 'L' # Save image as TIF file img_pil.save('image_k_channel.tif')
下面是结果(反转)K通道。你知道我做错了什么吗?谢谢