作业帮 > 综合 > 作业

用c++怎样从彩色图像中分解出R,G,B分量,并且分别保存

来源:学生作业帮 编辑:大师作文网作业帮 分类:综合作业 时间:2024/11/06 16:37:37
用c++怎样从彩色图像中分解出R,G,B分量,并且分别保存
用c++语言编程,怎样从一幅彩色图像中提取R,G,B三个分量并且分别保存?
用c++怎样从彩色图像中分解出R,G,B分量,并且分别保存
单单是图像的加载不是一两句代码就能搞定的.
如果你做图像方面的,不妨看看《Visual C++ 数字图像处理典型算法及实现》
推荐 opencv库,简单易学
例如使用opencv分离R,G,B三个分量有很多方法,如下:而且保存只需一个cvSave()函数.
#include
#include
int main(int argc,char** argv)
{
IplImage* src = cvLoadImage( argv[1],1 );
IplImage * RedChannel = cvCreateImage( cvGetSize(src),8,1);
IplImage * GreenChannel = cvCreateImage( cvGetSize(src),8,1);
IplImage * BlueChannel = cvCreateImage( cvGetSize(src),8,1);
IplImage * alphaChannel = cvCreateImage( cvGetSize(src),8,1);
cvSetImageCOI(src,1);
cvCopy(src,BlueChannel); //提取蓝色
cvSetImageCOI(src,2);
cvCopy(src,GreenChannel); //提取绿色
cvSetImageCOI(src,3);
cvCopy(src,RedChannel); //提取红色
cvNamedWindow( "RedChannel",1 );
cvNamedWindow( "GreenChannel",1 );
cvNamedWindow( "BlueChannel",1 );
cvNamedWindow( "lphaChannel",1 );
cvShowImage( "RedChannel",RedChannel );
cvShowImage( "GreenChannel",GreenChannel );
cvShowImage( "BlueChannel",BlueChannel );
cvShowImage( "lphaChannel",alphaChannel );
cvWaitKey(0);
cvReleaseImage( &RedChannel );
cvReleaseImage( &GreenChannel );
cvReleaseImage( & BlueChannel );
cvReleaseImage( & alphaChannel );
return 0;
}
/*#include
#include
int main(int argc,char** argv)
{
IplImage* src = cvLoadImage( argv[1],1 );
IplImage * RedChannel = cvCreateImage( cvGetSize(src),8,1);
IplImage * GreenChannel = cvCreateImage( cvGetSize(src),8,1);
IplImage * BlueChannel = cvCreateImage( cvGetSize(src),8,1);
IplImage * alphaChannel = cvCreateImage( cvGetSize(src),8,1);
cvCvtPixToPlane(src,BlueChannel,GreenChannel,RedChannel,NULL);
cvNamedWindow( "RedChannel",1 );
cvNamedWindow( "GreenChannel",1 );
cvNamedWindow( "BlueChannel",1 );
cvNamedWindow( "lphaChannel",1 );
cvShowImage( "RedChannel",RedChannel );
cvShowImage( "GreenChannel",GreenChannel );
cvShowImage( "BlueChannel",BlueChannel );
cvShowImage( "lphaChannel",alphaChannel );
cvWaitKey(0);
cvReleaseImage( &RedChannel );
cvReleaseImage( &GreenChannel );
cvReleaseImage( & BlueChannel );
cvReleaseImage( & alphaChannel );
return 0;
}
*/