The method of C # Digital Image processing

Source: Internet
Author: User

In this paper, we introduce the 3 methods of C # processing digital Image by color image grayscale, the bitmap class, BitmapData class and graphics class are 3 important classes of C # processing images.

Bitmap as long as the objects that are used to process images defined by pixel data, the main methods and properties are as follows:

GetPixel method and SetPixel method, gets and sets the color of the specified pixel of an image.

PixelFormat property that returns the pixel format of the image.

Palette property, Gets or uses the color palette of the origami image.

The Height property and width property, which returns the heights and widths of the image.

The LockBits method and the Unlockbits method are used to lock and unlock the bit image element in the memory of the system respectively.

The BitmapData object specifies the properties of the bitmap:

Height property, which is locked to the heights of the bitmap.

Width property, which is locked to a bitmap.

PixelFormat property, the actual pixel format of the data.

The Scan0 property, the first byte address of the locked array.

Stride Properties, stride, also called scanning width.

Grayscale of color image

The 24-bit color image is represented by 3 bytes per pixel, and each byte corresponds to the brightness of the R, G, and B components (red, green, and blue). When 3 components do not want to be simultaneously displayed as grayscale images. Here are three conversion formulas:

Gray (I,j) is the grayscale value of the converted grayscale image at (i,j) point. Since the human eye is different in color, the following conversion formula is available:

observed that the largest proportion of green, so the conversion of the direct use of G value as a result of conversion:

The 3 methods of image processing are: Extracting pixel method, memory method and pointer method respectively, they have their own characteristics.

Extract Pixel method

The Bitmap.getpixel and Bitmap.setpixel methods in GDI + are used.

if (bitmap!= null)
{
    Newbitmap = bitmap. Clone () as Bitmap;
    Color Pixel;
    int ret;
    for (int x = 0; x < Newbitmap. Width; x + +)
    {for
        (int y = 0; y < Newbitmap.) Height; y++)
        {
            pixel = newbitmap. GetPixel (x, y);
            ret = (int) (pixel. R * 0.299 + pixel. G * 0.587 + pixel. B * 0.114);
            Newbitmap. SetPixel (x, Y, Color.FromArgb (ret, ret, ret));
        }
    pictureBox1.Image = Newbitmap. Clone () as Image;
}

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.