简体   繁体   English

有没有办法在同一图像opencv C ++中同时具有灰度像素和rgb像素?

[英]Is there a way to have both grayscale and rgb pixels on the same image opencv C++?

I need to be able to work with images where some regions are grayscale while others are kept on the RGB format. 我需要能够处理某些区域为灰度而其他区域保持为RGB格式的图像。 I don't want to convert an image into a grayscale since it will lose the channels and will become simply one channeled, is there a way to keep the RGB channels of some pixels on the picture and turn the others into a grayscale? 我不想将图像转换为灰度图像,因为它会丢失通道并仅变成一个通道,有没有办法保持图像上某些像素的RGB通道并将其他像素变为灰度?

NO. 没有。

I see two solutions to this: 我看到两种解决方案:

  1. Have both a gray ( Mat1b ) and a rgb ( Mat3b ) image, and work on the image you need. 同时具有灰色( Mat1b )和rgb( Mat3b )图像,然后处理所需的图像。
  2. Have a single rgb ( Mat3b ) image, and set r,g,b channels to the same gray value where you need. 拥有一张rgb( Mat3b )图像,并在需要的地方将r,g,b通道设置为相同的灰度值。 In this way you can mimic to have a mixed gray/rgb image. 这样,您可以模拟具有混合的灰度/ RGB图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM