#include <cv.hpp> using namespace cv; int main( int argc, char** argv ) { Mat image; image = imread( "resource/lena.png", IMREAD_COLOR ); Mat OutputR( image.rows, image.cols, CV_8UC3, Scalar(0, 0, 0) ); Mat OutputG( image.rows, image.cols, CV_8UC3, Scalar(0, 0, 0) ); Mat OutputB( image.rows, image.cols, CV_8UC3, Scalar(0, 0, 0) ); int height = image.rows; int width = image.cols; for(int row = 0; row < height; row++) { for(int col = 0; col < width; col++) { OutputB.at<Vec3b>(row, col)[0] = image.at<Vec3b>(row, col)[0]; OutputB.at<Vec3b>(row, col)[1] = 0; OutputB.at<Vec3b>(row, col)[2] = 0; OutputG.at<Vec3b>(row, col)[0] = 0; OutputG.at<Vec3b>(row, col)[1] = image.at<Vec3b>(row, col)[1]; OutputG.at<Vec3b>(row, col)[2] = 0; OutputR.at<Vec3b>(row, col)[0] = 0; OutputR.at<Vec3b>(row, col)[1] = 0; OutputR.at<Vec3b>(row, col)[2] = image.at<Vec3b>(row, col)[2]; } } namedWindow("outr", WINDOW_NORMAL); imshow("outr", OutputR); namedWindow("outg", WINDOW_NORMAL); imshow("outg", OutputG); namedWindow("outb", WINDOW_NORMAL); imshow("outb", OutputB); waitKey(0); return 0; }
Results:



No comments:
Post a Comment