Image programming in actionscript3 games (20)

Source: Internet
Author: User

1.4.2 grayscale Calculation Method

Looking back at RGB, from a scientific point of view, they do have a brighter reason, because the total amount of color reflected by the following row of colors is twice that of the previous row.

For this reason, the author invented a "original" grayscale formula by himself:

 
Gray = (R + G + B)/3


Haha, it must be more accurate to express the gray scale with the total amount of color light! After I was complacent, I tried to use this self-developed law to convert the test image. The gray scale of the upper and lower color blocks really opened, but unfortunately it was adjacent to the left and right sides, the color blocks with distinct boundaries are still stuck in one piece (Figure 1.30 ).

 
Figure 1.30 "self-created" grayscale conversion

Obviously, the black and white photos generated by this method are difficult to reach the elegant hall, and the demarcation lines between the color blocks are all lost, and the same line of color is in our human visual system, and the brightness is also different. For example, the retina will think that the upper row of the green is brighter than the red and blue next to it, while the lower row of the pink is not adjacent to the yellow and light green eye.

A great invention-The grayscale psychology formula was born! It brings together the essence of cutting-edge disciplines such as optical physics, eye-vision optics, human psychology, and art appreciation. It integrates science and technology, art, and social science, it is one of the most amazing scenes in the history of Visual Science.

Grayscale psychology formulas are not complex. They describe the differences in the degree of visual stimulation of various colors in a simple way. They only use the simplest addition and multiplication to complete the entire gray-scale calculation process:

 
Gray = r * 0.299 + G * 0.587 + B * 0.114

R, G, and B are normalized to 0 ~ 1.

If you have read FL. motion. the code of the adjustcolor class must have a familiar feeling about this formula. The three coefficients in the formula are used in adjustcolor (the specific values may be slightly different ). In fact, adjustcolor uses grayscale to replace brightness. As for why, it is self-evident to see the above black-and-white image conversion result.

So that r = G = B = 1, the gray scale is just equal to 100%, so it is essentially a weighted average operation on the three values of RGB, G has the largest weight (generally referred to as the proportion), followed by red, and the smallest value in blue. Therefore, the psychology formula holds that green is the most eye-catching, And it is twice brighter than red. The stimulation of a little green light on the retina is equivalent to two red lights.

The above description is very similar to the visual perception, but as to how the specific value is calculated, I will not be able to study it.

I tried to use the grayscale psychology formula to perform grayscale conversion on Fig 1.27, which is more effective than my "original" Law (Fig 1.31 ).

 

Figure 1.31 grayscale conversion using psychology Formulas

So far, the relationship between brightness and gray scale has been quite clear. They are born to quantify the color and shade, and promote the progress of human spiritual civilization in the spirit of "people-oriented science and technology. Among them, the brightness focuses on the overall grasp, from the color category, brightness, brightness level three human perception attributes to describe the color value abstracted by mathematical science, the gray scale emphasizes the deep exploration of individual properties of things, and specifically makes up for the defect that the brightness Calculation Method in HSB mode is not consistent with the visual organ.

Now, no one will take black and white photos (except for those with a pure nostalgia), even if they really need to use black and white images (such as the recording scene of documentary films, the mourning day of the Wenchuan earthquake, etc.) will not take a special trip from the museum to start shooting with a 19 century factory black and white camera, instead, we chose to use Photoshop and other software to convert color images to gray. The gray-scale processing algorithm is derived from the preceding psychology formula.

In the field of art programming, grayscale is not only used to directly produce black and white effects (such as the disabling status of game buttons and the grayscale effect before the player's resurrection), but also widely used in image recognition and color adjustment, edge detection, light and shade preprocessing, model coloring, and other image processing technologies (the color mixing mode of Photoshop is a success example ). Its uniqueness makes the creation process of graphics traceable, so that art is no longer only in the hands of designers.
Next we will use the grayscale formula to match a set of relatively harmonious colors.

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.