On the interpretation of three-channel and single-channel images

Source: Internet
Author: User

(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.

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.