세 개의 단일 채널 그림 을 얻 는 다른 방법

 
 
IplImage* src;
	src = cvLoadImage("C:\Users\xht\Desktop\open\ba.jpg");

	IplImage* imgRed = cvCreateImage(cvGetSize(src),8,1);
	IplImage* imgGreen = cvCreateImage(cvGetSize(src),8,1);
	IplImage* imgBlue = cvCreateImage(cvGetSize(src),8,1);

	cvSplit(src,imgBlue,imgGreen,imgRed,NULL);
	IplImage* img;
	img = cvLoadImage("C:\\Users\\xht\\Desktop\\open\\ba.jpg");

	cvNamedWindow("img");
	cvShowImage("img",img);

	IplImage* imgRed = cvCreateImage(cvGetSize(img),8,1);
	IplImage* imgGreen = cvCreateImage(cvGetSize(img),8,1);
	IplImage* imgBlue = cvCreateImage(cvGetSize(img),8,1);

	for (int y = 0 ;y < img->height;y++)
	{
		unsigned char* prow = (unsigned char*)(img->imageData + y * img->widthStep);
		//img->imageData        ,img->widthStep        ,*y    y    
		unsigned char* brow = (unsigned char*)(imgBlue->imageData + y * imgBlue->widthStep);
		unsigned char* grow = (unsigned char*)(imgGreen->imageData + y * imgGreen->widthStep);
		unsigned char* rrow = (unsigned char*)(imgRed->imageData + y * imgRed->widthStep);

		for (int x=0;x < img->width;x++)
		{
			brow[x] = prow[3 * x + 0] ;
			grow[x] = prow[3 * x + 1] ;
			rrow[x] = prow[3 * x + 2] ;
		}
	}

좋은 웹페이지 즐겨찾기