C # drawing a digital image grayscale Histogram

Source: Internet
Author: User

A grayscale histogram is a grayscale function that describes the number of pixels in an image with the gray level. If the Cartesian coordinate system is used for representation, the x-axis is the gray level, and the y-axis is the probability of the occurrence of the gray level (number of pixels ).

Histogram distribution function:

 

Plot histogram Information

// Draw the coordinate system Graphics g = e. graphics; Pen curPen = new Pen (Brushes. black, 1); g. drawLine (curPen, 50,240,320,240); g. drawLine (curPen, 50,240, 50, 30); g. drawLine (curPen, 100,240,100,242); g. drawLine (curPen, 150,240,150,242); g. drawLine (curPen, 200,240,200,242); g. drawLine (curPen, 250,240,250,242); g. drawLine (curPen, 300,240,300,242); g. drawString ("0", new Font ("New Timer", 8), Brushes. black, new PointF (46,242); g. drawString ("50", new Font ("New Timer", 8), Brushes. black, new PointF (92,242); g. drawString ("100", new Font ("New Timer", 8), Brushes. black, new PointF (139,242); g. drawString ("150", new Font ("New Timer", 8), Brushes. black, new PointF (189,242); g. drawString ("200", new Font ("New Timer", 8), Brushes. black, new PointF (239,242); g. drawString ("250", new Font ("New Timer", 8), Brushes. black, new PointF (289,242); g. drawLine (curPen, 48, 40, 50, 40); g. drawString ("0", new Font ("New Timer", 8), Brushes. black, new PointF (34,234); g. drawString (maxPixel. toString (), new Font ("New Timer", 8), Brushes. black, new PointF (18, 34); double temp = 0; for (int I = 0; I <256; I ++) {temp = 200.0 * countPixel [I]/maxPixel; g. drawLine (curPen, 50 + I, 240, 50 + I, 240-(int) temp);} curPen. dispose ();

 

Global variable definition and assignment

        private System.Drawing.Bitmap bmpHist;        private int[] countPixel;        private int maxPixel;        public Grey_ScaleMapForm(Bitmap bmp)        {            InitializeComponent();            bmpHist = bmp;            countPixel = new int[256];        }

 

: DEMO

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.