Introduction to C # image processing--colormatrix

Source: Internet
Author: User

GDI + provides image and bitmap classes for storing and manipulating images. The Image and bitmap objects store the color of each pixel with a 32-digit number: red, green, blue, and Alpha 8 bits. The values for these four components are 0 to 255, where 0 indicates no brightness, and 255 represents the maximum brightness. The alpha component specifies the transparency of the color: 0 indicates full transparency, and 255 indicates total opacity.

Color vectors are in 4-tuple form (red, green, blue, alpha). For example, a color vector (0, 255, 0, 255) represents an opaque color that has no red and blue but green reaches the maximum brightness.

Another practice for representing colors is to use the number 1 to indicate that the brightness is maximized. By using this convention, the colors described in the previous paragraph can be represented by vectors (0, 1, 0, 1). When performing a color transformation, GDI + follows the practice of using 1 as the maximum brightness.

You can use the 4x4 matrix to multiply these color vectors to apply the linear transformation (rotation and scaling, etc.) to the color vector. However, you cannot use the 4x4 matrix for translation (nonlinearity). If you add a virtual 5th coordinate (for example, number 1) to each color vector, you can use the 5x5 matrix to apply any combination of linear transformations to the peace shift. A transformation consisting of a linear transformation followed by a translation is called an affine transformation.

For example, suppose you want to start with a color (0.2, 0.0, 0.4, 1.0) and apply the following transform:

Multiply the red component by 2.

Add 0.2 to the red, green, and blue components.

The following matrix multiplication will perform this pair of transformations in the order listed.

The elements of the color matrix are indexed in the order of the first column (starting from 0). For example, the third column of the fifth row of Matrix M is represented by m[4][2].

The 5x5 unit matrix (shown in the following illustration) is 1 on the diagonal and 0 in any other place. If you multiply the color vector by the unit matrix, the color vector does not change. An easy way to form a color transformation matrix is to start with the unit matrix and then make minor changes to produce the desired transformation.

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.