如何从python中的图像集中识别CMYK图像

2024-05-15 13:19:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我在文件中有一个巨大的图像集。我正在尝试检查图像是否为RGB或CMYK格式

我正在尝试读取通道数,因为RGB将有3个通道,CMYK将有4个。但当我尝试对这两幅图像执行此操作时,我看到通道为3 下面是我试过的代码

import cv2
readImage = cv2.imread
readImage = cv2.imread(r"TestIMage")
h,w,bpp = np.shape(readImage)

请帮我做这个。我可以用其他方法检测CMYK和RGB图像


Tags: 文件方法代码图像import格式nprgb
1条回答
网友
1楼 · 发布于 2024-05-15 13:19:07

枕头库使检查图像模式变得非常容易

下面是一朵RGB花。使用枕头,您可以打开图像并查看图像的模式属性

from PIL import Image

rgbImage = Image.open("flower.jpg")
print(rgbImage.mode)

https://i.stack.imgur.com/nPGtkt.jpg

enter image description here

输出:

RGB

再次用CMYK花:

from PIL import Image

cmykImage = Image.open("cmyk_flower.jpg")
print(cmykImage.mode)

https://i.stack.imgur.com/fHxUct.jpg

enter image description here

输出:

CMYK

相关问题 更多 >