Jav*_*yer 0 c++ opencv image-processing
我已经将图像从RGB转换为B/W然后我想将其转换回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));
Run Code Online (Sandbox Code Playgroud)
在这里我将zoomedImage显示为黑白图像,在另一个动作中,我想将zoomedImage显示为RGB图像,这里的主要问题是我无法更改将要绘制的图像,因为我的代码的另一部分依赖于在这个序列中,我在另一个动作中写道:
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));
Run Code Online (Sandbox Code Playgroud)
但是zoomedImage仍然显示为B/W,我听说当真彩色图像转换为灰色时,它不能再作为真彩色图像返回,那么CV_GRAY2RGB做什么呢?
将RGB图像转换为灰度图像时,颜色信息会丢失,并且无法再次从灰度图像中恢复此信息.
当您尝试将黑白图像转换为RGB时,您只能制作3通道图像,但所有通道都包含相同的强度数据.因此,您将获得具有3个通道的灰度图像.而已.