用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;
}
*/
如果你做图像方面的,不妨看看《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;
}
*/
彩色图像的熵是怎样计算的,是只计算亮度分量的熵,还是RGB三个分量分别计算熵然后求平均?
关于彩色图像RGB分量的疑问.
彩色显示器的彩色由三个基色R、G、B合成而得到,如果R、G、B三色分别用8位表示,则显示器可显示的颜色数大约
有一幅RGB图像,怎样计算R分量大于200的像素的比例,求程序!
发生三相对称短路时,短路电流中包含有A正序分量B负序分量C零序分量D其他分量
在RGB模式的图像中每个像素的颜色值都由R、G、B这3个数值来决定,每个数值的范围都是0到255.当R、G、B数值分别为
PS:对于RGB模式的彩色图像,要表示最白,则其每一种颜色分量的值分别为( )
在matlab中,二为图像常用设置选项,r,g,b,w,k表示什么?
从射电望远镜观察的图像和光学望远镜观察出的图像是一样的吗?都是彩色的吗?
一般情况下,为什么不能对彩色图像RGB分量进行直方图均衡来增强对比度
怎样从血液中分离出B淋巴细胞?
在一恒温恒容密闭容器中,A、B气体可建立如下平衡:2A(g)+2B(g)⇌C(g)+3D(g)现分别从两条途径建立平衡: