我已经将图像从 RGB 转换为黑白,然后我想将其转换回 RGB,但我对此有疑问:
我的代码:
int width=zoomedImage->width;
int height=zoomedImage->height;
TempImage=cvCreateImage(cvSize(width,height),IPL_DEPTH_8U,1);
cvCvtColor(zoomedImage, TempImage,CV_RGB2GRAY);
cvThreshold( TempImage, TempImage,128,256,CV_THRESH_BINARY);
cvCvtColor( TempImage,zoomedImage,CV_GRAY2RGB);
this->pictureBox1->Image=(gcnew
System::Drawing::Bitmap(zoomedImage->width,zoomedImage->height,zoomedImage->widthStep,
System::Drawing::Imaging::PixelFormat::Format24bppRgb,(System::IntPtr)zoomedImage->imageData));
这里我将 zoomedImage 显示为黑白图像,在另一个操作中我想将 zoomedImage 显示为 RGB 图像这里的主要问题是我无法更改将作为我的其他部分绘制的图像代码取决于这个顺序,我在另一个 Action 中写道:
cvCvtColor( TempImage,zoomedImage,CV_GRAY2RGB);
this->pictureBox1->Image=(gcnew
System::Drawing::Bitmap(zoomedImage->width,zoomedImage->height,zoomedImage->widthStep,
System::Drawing::Imaging::PixelFormat::Format24bppRgb,(System::IntPtr)zoomedImage->imageData));
但是zoomedImage还是显示为B/W,我听说当一个真彩色图像被转换成灰色时,它不能再次作为一个真彩色图像返回,那么CV_GRAY2RGB是做什么的呢?
最佳答案
当您将 RGB 图像转换为灰度图像时,颜色信息会丢失,并且此信息无法再次从灰度图像中恢复。
当您尝试将黑白图像转换为 RGB 时,您只能生成 3 channel 图像,但所有 channel 都包含相同的强度数据。因此,您将获得具有 3 个 channel 的灰度图像。仅此而已。
关于c++ - OpenCV 从 B/W 转换为 RGB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10659294/