4. 把一幅彩色图像的R、G、B分量单独显示。

#include <cv.h>
#include <highgui.h> 

int main(void)
{
    IplImage* oo = cvLoadImage("6013202130.jpg", 1);
    IplImage * Red = cvCreateImage(cvGetSize(oo), 8, 1);
    IplImage * Green = cvCreateImage(cvGetSize(oo), 8, 1);
    IplImage * Blue = cvCreateImage(cvGetSize(oo), 8, 1);
    cvSetImageCOI(oo, 1);       //通道1 ,蓝色
    cvCopy(oo, Blue);   //复制到Blue
    cvSetImageCOI(oo, 2);       //通道2 ,绿色
    cvCopy(oo, Green); 
    cvSetImageCOI(oo, 3);       //通道3 ,红色
    cvCopy(oo, Red); 
    cvNamedWindow("Red", 1);
    cvNamedWindow("Green", 1);
    cvNamedWindow("Blue", 1);
    cvNamedWindow("oo", 1);
    cvShowImage("原图", oo);
    cvShowImage("Red", Red);
    cvShowImage("Green", Green);
    cvShowImage("Blue", Blue);
    cvWaitKey(0);
    cvReleaseImage(&Red);
    cvReleaseImage(&Green);
    cvReleaseImage(&Blue);
    cvReleaseImage(&oo);
    return 0;
}

posted @ 2016-05-06 12:38  张飞online  阅读(607)  评论(0编辑  收藏  举报