<pre name="code" class="html">#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cv.h>
#include <highgui.h>
int _tmain(int argc, _TCHAR* argv[])
{
IplImage *img = cvLoadImage("D:\\lena.bmp",CV_LOAD_IMAGE_COLOR);
cvShowImage("src", img);
IplImage* rImg=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,1);
IplImage* gImg=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,1);
IplImage* bImg=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,1);
IplImage* rImg1=cvCreateImage(cvGetSize(img),img->depth,3);
IplImage* gImg1=cvCreateImage(cvGetSize(img),img->depth,3);
IplImage* bImg1=cvCreateImage(cvGetSize(img),img->depth,3);
cvSplit( img, bImg, gImg, rImg, 0);
//0初始化很重要
cvZero(bImg1);
cvZero(gImg1);
cvZero(rImg1);
cvMerge(bImg, 0, 0, 0,bImg1);
cvMerge(0, gImg, 0, 0,gImg1);
cvMerge(0, 0, rImg, 0,rImg1);
cvShowImage("r", rImg1);
cvShowImage("g", gImg1);
cvShowImage("b", bImg1);
cvWaitKey(0);
}