OpenCV分离RGB像素

#include<highgui.h>
#include<cxcore.h>
int main(){
	IplImage *img=cvLoadImage("Baboon.jpg",1);
	//void cvSplit( const CvArr* src, CvArr* dst0, CvArr* dst1, CvArr* dst2, CvArr* dst3 );
	//IplImage *r,*g,*b,*alpha;
	int num=3;
	int i=0;
	char *window[3]={"b","g","r"};
	char *name[3]={"b.jpg","g.jpg","r.jpg"};
	IplImage *subGrayImage[3];
	IplImage *subColorImage[3];
	for(i=0;i<3;i++)
	{
		subGrayImage[i]=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,1);  
		subColorImage[i]=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,3);  
	}
	cvSplit(img,subGrayImage[0],subGrayImage[1],subGrayImage[2],0);
	cvNamedWindow("example",1);
	cvShowImage("example", img);
	for(i=0;i<3;i++)cvZero(subColorImage[i]);
		
	cvMerge(subGrayImage[0],0,0,0,subColorImage[0]);
	cvMerge(0,subGrayImage[0],0,0,subColorImage[1]);
	cvMerge(0,0,subGrayImage[0],0,subColorImage[2]);
	for(i=0;i<3;i++){
		cvSaveImage(name[i],subColorImage[i],NULL);
	}
	for(i=0;i<3;i++){
		cvNamedWindow(window[i],1);
		cvShowImage(window[i], subColorImage[i]);		
	}		
	cvWaitKey(0);
	cvReleaseImage(&img);
	cvDestroyWindow("example");
	for(i=0;i<3;i++){
		cvReleaseImage(&subGrayImage[i]);
		cvReleaseImage(&subColorImage[i]);
		cvDestroyWindow(window[i]);
	}

}




参考:

http://blog.csdn.net/xiaowei_cqu/article/details/7558657


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值