Cvsplit function in opencv

Source: Internet
Author: User

1. function prototype:

void cvSplit(const CvArr* src,CvArr *dst0,CvArr *dst1, CvArr *dst2, CvArr *dst3);

In some cases, it is not convenient to process multi-channel images. In this case, you can use cvsplit () to copy each channel to multiple single-channel images. If necessary, cvsplit () the function copies each channel of SRC (source multi-channel image) to dst0, dst1, dst2, and dst3. The target image must match the source image in size and data type. Of course, it should also be a single-channel image.

If the source image has fewer than four channels (this often happens), the unnecessary target parameter passed to cvsplit () can be set to null.

The following procedure is the core part of the procedure for converting a multi-channel image to a single-channel image.

    Image1=cvLoadImage("DarkClouds.jpg",1);    RedImage=cvCreateImage(cvGetSize(Image1),IPL_DEPTH_8U,1);    GreenImage=cvCreateImage(cvGetSize(Image1),IPL_DEPTH_8U,1);    BlueImage=cvCreateImage(cvGetSize(Image1),IPL_DEPTH_8U,1);    cvSplit(Image1,BlueImage,GreenImage,RedImage,0);

Now we write a complete program to convert an image into a single channel image and display it.

#include "cv.h"#include "highgui.h"int main(void){IplImage *image1 = cvLoadImage("e:\\opencv\\image\\Fruits.jpg",1);IplImage *redImage = cvCreateImage(cvGetSize(image1),IPL_DEPTH_8U,1);IplImage *greenImage = cvCreateImage(cvGetSize(image1),IPL_DEPTH_8U,1);IplImage *blueImage = cvCreateImage(cvGetSize(image1),IPL_DEPTH_8U,1);cvSplit(image1,redImage,greenImage,blueImage,NULL);cvNamedWindow("hello",CV_WINDOW_AUTOSIZE);cvShowImage("hello",image1);cvWaitKey(0);cvShowImage("hello",redImage);cvWaitKey(0);cvShowImage("hello",greenImage);cvWaitKey(0);cvShowImage("hello",blueImage);cvWaitKey(0);return 0;}

Lab result diagram:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.