在其中显示单个通道的颜色(不是灰度)

发布于 2025-02-08 07:22:55 字数 977 浏览 0 评论 0原文

我可以成功将BGR映像转换为CMYK,并且我得到了大小的数组(高度,宽度,4)4是C,M,M,Y和K频道,范围从0到1。

在我拆分该cmyk数组之后,我有4个大小的数组(高度,宽度)表明我的量每个像素的k。

如果我只想显示c(青色)频道的频道,我不能使用cv.imshow('cyan',c),因为它给了我一个灰度图像,正如预期的。

因此,我如何在青色中显示c频道/数组,其基于c array的“饱和度”的正确量? < br> 或者,我如何获得灰度图像以显示青色的,每个像素的青色中的“饱和”?

编辑:

我的目标是将BGR图像拆分为4个通道(C,M,Y和K),我应该使用每个像素来给我颜色的量(青色,洋红色,黄色或黑色),以全颜色表示图像,在白色背景上 /strong>(正如打印机一样)。

示例:

此图像:

​> “

那些4'Channel's堆叠/在白色背景上的堆叠/涂漆将提供完整的彩色图像。
因此,我希望能够生成这4张图像,并有一种方法来了解每个像素所需的每种颜色(青色,洋红色,黄色,黑色)的数量(用于白色表面上的添加色)

I can successfully convert a BGR image to CMYK and I get a array of size (height, width, 4), the 4 being the C, M, Y and K channels, ranging from 0 to 1.

After I split that CMYK array, I have 4 arrays of size (height, width) that indicates me the amount of C, M, Y and K for each pixel.

If I want to show only the C (cyan) channel for exemple, I cannot use cv.imshow('Cyan', C) because it gives me a grayscale image, as expected.

So, how can I show the C channel/array in cyan, with the correct amount of "saturation" based on the C array ?
Or, how can I get that grayscale image to show cyan, with the same "saturations" in cyan for each pixel ?

EDIT:

My goal is to split an BGR image into 4 channels (C, M, Y and K) that give me the amount of color (cyan, magenta, yellow or black) I should use for each pixel to represent the image, in full colours, on a white background (as a printer would do it).

Exemple:

This image:

full color image

Would be split like this:

cmyk channels split

Those 4 'channels' stacked/painted on a white background would give the full colour image.
So I would like to be able to generate those 4 images and to have a way to know the quantity of each color (cyan, magenta, yellow, black) needed for each pixel (for additive coloring on white surface)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

痴情换悲伤 2025-02-15 07:22:55

进入CMYK后,您将没有饱和。为此,您需要HSV并分开S通道。然后,如果需要在Python OpenCV中,可以通过将蓝色和绿色通道设置为诸如255的固定值。

输入:

“

import cv2
import numpy as np

# read image
img = cv2.imread("barn.jpg")

# convert to HSV and get S channel
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
s = hsv[:,:,1]

# make 3 equal channels, then colorize with cyan (blue = green = 255)
s_cyan = cv2.merge([s,s,s])
s_cyan[:,:,0] = 255
s_cyan[:,:,1] = 255

# write results to disk
cv2.imwrite("barn_saturation_cyan.jpg", s_cyan)

# show results
cv2.imshow('s_cyan', s_cyan)
cv2.waitKey(0)
cv2.destroyAllWindows()

结果:

如果通过“饱和”,您只是指“强度”,则可以通过将青色与CMYK图像分开并进行相同的蓝色=绿色= 255在将单个通道图像转换为3个相等的通道后,使CMYK CYAN通道着色。

Once you go to CMYK, you do not have saturation. For that you need HSV and separate the S channel. You can then colorize the S channel with cyan if you want in Python OpenCV by setting the blue and green channels to some fixed values such as 255.

Input:

enter image description here

import cv2
import numpy as np

# read image
img = cv2.imread("barn.jpg")

# convert to HSV and get S channel
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
s = hsv[:,:,1]

# make 3 equal channels, then colorize with cyan (blue = green = 255)
s_cyan = cv2.merge([s,s,s])
s_cyan[:,:,0] = 255
s_cyan[:,:,1] = 255

# write results to disk
cv2.imwrite("barn_saturation_cyan.jpg", s_cyan)

# show results
cv2.imshow('s_cyan', s_cyan)
cv2.waitKey(0)
cv2.destroyAllWindows()

Result:

enter image description here

If by "saturations" you just mean "intensities", then you can colorize the CMYK cyan channel, by separating cyan from your CMYK image and do the same colorization of setting blue = green = 255 after converting the single channel image to 3 equal channels.

三生一梦 2025-02-15 07:22:55

这是两种用蓝色颜色在Python/OpenCV中(灰度)青色通道着色的方法。

方法1:从CMYK Colorspace获取青色通道。将灰度通道转换为3个通道,并设置为255

方法2的蓝色和绿色通道:从CMY Colorspace获取CYAN通道作为浮点。创建相同维度和类型的“红色”图像。然后将两者乘以255,然后将结果转换为UINT8。请注意,红色是青色的补充,而反相则可以补充它。我使用了来自CMY的青色,因为它会产生更接近您显示的结果。请参阅CMY和CMYK在 https://en.wikipedia.org/wikipedia/cmykimekcy_cmmy_cmmy_model < /a>

import cv2
import numpy as np

#Method 1

# read cyan image from CMYK separation as grayscale
gray = cv2.imread("skyline_cyan.jpg", cv2.IMREAD_GRAYSCALE)
hh, ww = gray.shape[:2]

# colorize with cyan
gray3 = cv2.merge([gray,gray,gray])
result1 = gray3.copy()
result1[:,:,0] = 255
result1[:,:,1] = 255

# write results to disk
cv2.imwrite("skyline_cyan_result1.jpg", result1)

# show results
cv2.imshow('grayscale cyan from cmyk', gray)
cv2.imshow('result1', result1)
cv2.waitKey(0)
cv2.destroyAllWindows()


# Method 2

# read cyan image from CMY separation as float grayscale
gray = cv2.imread("skyline_cyan2.jpg", cv2.IMREAD_GRAYSCALE).astype(np.float32)
hh, ww = gray.shape[:2]

# create red color image as float
red = np.full((hh,ww,3), (0,0,255), dtype=np.float32)

# multiply gray3 with cyan
gray3 = cv2.merge([gray,gray,gray])
result2 = cv2.multiply(gray3, red)/255
result2 = result2.astype(np.uint8)
result2 = 255 - result2

# write results to disk
cv2.imwrite("skyline_cyan_result2.jpg", result2)

# show results
cv2.imshow('grayscale cyan from cmy', gray.astype(np.uint8))
cv2.imshow('result2', result2)
cv2.waitKey(0)
cv2.destroyAllWindows()

输入(cmmyk):

”在此处输入图像说明“

通过方法1:

input(cmmy):

​:

的结果,这是从CMYK着色的结果。

为了完整性,这是使用方法2: “在此处输入图像说明”

Here are two ways to colorize the (grayscale) cyan channel in Python/OpenCV with a cyan color.

Method 1: Get cyan channel from CMYK colorspace. Convert grayscale channel to 3 channels and set the blue and green channels with value of 255

Method 2: Get the cyan channel from CMY colorspace as float. Create a "red" image of the same dimensions and type. Then multiply the two and divide by 255, invert and convert the result to uint8. Note that red is the complement of cyan and inverting complements it back. I used cyan from CMY, since it produces a result closer to what you show. See the difference of cyan from CMY and CMYK at https://en.wikipedia.org/wiki/CMYK_color_model

import cv2
import numpy as np

#Method 1

# read cyan image from CMYK separation as grayscale
gray = cv2.imread("skyline_cyan.jpg", cv2.IMREAD_GRAYSCALE)
hh, ww = gray.shape[:2]

# colorize with cyan
gray3 = cv2.merge([gray,gray,gray])
result1 = gray3.copy()
result1[:,:,0] = 255
result1[:,:,1] = 255

# write results to disk
cv2.imwrite("skyline_cyan_result1.jpg", result1)

# show results
cv2.imshow('grayscale cyan from cmyk', gray)
cv2.imshow('result1', result1)
cv2.waitKey(0)
cv2.destroyAllWindows()


# Method 2

# read cyan image from CMY separation as float grayscale
gray = cv2.imread("skyline_cyan2.jpg", cv2.IMREAD_GRAYSCALE).astype(np.float32)
hh, ww = gray.shape[:2]

# create red color image as float
red = np.full((hh,ww,3), (0,0,255), dtype=np.float32)

# multiply gray3 with cyan
gray3 = cv2.merge([gray,gray,gray])
result2 = cv2.multiply(gray3, red)/255
result2 = result2.astype(np.uint8)
result2 = 255 - result2

# write results to disk
cv2.imwrite("skyline_cyan_result2.jpg", result2)

# show results
cv2.imshow('grayscale cyan from cmy', gray.astype(np.uint8))
cv2.imshow('result2', result2)
cv2.waitKey(0)
cv2.destroyAllWindows()

Input (C from CMYK):

enter image description here

Colorized by method 1:

enter image description here

Input (C from CMY):

enter image description here

Colorized by method 2:

enter image description here

For completeness, here is the result of colorizing cyan from CMYK using method 2:

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文