(a): Single channel diagram,
Commonly known as grayscale, each pixel can only have a value to represent the color, its pixel value between 0 to 255, 0 is black, 255 is white, the median is some different levels of gray. (There are also 3-channel grayscale, 3-channel grayscale, only one channel has a value, the other two channels have a value of 0).
(b): three-channel graph, each pixel point has 3 values, so is 3 channels. There are also 4-channel graphs. For example, the RGB image is a three-channel picture, RGB color mode is a color standard industry, is through the red (R), Green (G), Blue (B) three color channels and their superposition to get a variety of colors, RGB is the red, green, blue three channels of color, This standard almost includes all the colors that human vision can perceive, and is one of the most widely used color systems. In summary, each point is represented by a value of three.
Here is a simple example to illustrate the difference between a three-channel picture and a single-channel picture
/********************************************************************************************************** * File Description : * Use a simple example to illustrate the meaning of the three-channel picture and the single channel * Development environment: * win7+vs2010+opencv2.4.8 * Time and place: * Shaanxi Normal University. 2017.1.24 * Author: * Lily ***********************************************************************************************************/# include<iostream> #include <opencv2\core\core.hpp> #include <opencv2\highgui\highgui.hpp> #
Include<opencv2\imgproc\imgproc.hpp> #include <opencv2\opencv.hpp> using namespace std;
using namespace CV;
int main () {//load a color picture and show Mat srcimage=imread ("G:\\image\\lenargb.png", 1);
Namedwindow ("Image", window_autosize);
Imshow ("Image", srcimage);
int nheight=srcimage.rows;
int nwidth=srcimage.cols;
Loading a grayscale image and showing that the same picture is used here just the last parameter of the Imread function is the same as the Mat grayimage=imread ("G:\\image\\lenargb.png", 0);
Namedwindow ("Grayimage", window_autosize);
Imshow ("Grayimage", grayimage); Basic information cout<< "Height of image" <<nheight<<endl;
cout<< "width of image" <<nWidth<<endl; cout<< "Number of channels in image" <<srcimage.channels () <<endl; Number of channels for color pictures cout<< "grayimage channels" <<grayimage.channels () <<endl;
The number of channels for grayscale images for (int i=0;i<nheight;i++) {for (int j=0;j<nwidth;j++) {srcimage.at<uchar> (i,j) = 0;
Grayimage.at<uchar> (I,J) = 0;
}} namedwindow ("Black picture after color image processing", window_autosize);
Imshow ("color image processing corresponding to black picture", srcimage);
Namedwindow ("Black image after grayscale image processing", window_autosize);
Imshow ("Black image after grayscale image processing", grayimage);
Cvwaitkey (0);
Cvdestroywindow ("Image");
Cvdestroywindow ("Grayimage");
Cvdestroywindow ("Color image processing after the black picture");
Cvdestroywindow ("Black image after grayscale image processing");
return 0;
}
Program results:
Understand the results of the operation well.