Image programming in actionscript3 games)

Source: Internet
Author: User

Total Directory: http://blog.csdn.net/iloveas2014/article/details/38304477

 

4.5.6 Effect of convolution on pixels

In the case of a small external force, the material will constantly spread evenly (including the solid can also spread, but the distance between the solid molecules is small, the gravity is large, therefore, we generally do not feel it. For example, after a coal wall is placed for a while, the wall will gradually become dark, haha, and even farther away.) We also know that external forces are affecting the world all the time. For example, a person may go high, and water may flow down. In sociology, we are also familiar with the immoral behavior of robbing the poor, the rich, and the poor. Therefore, the convolution matrix that processes the relationship between image pixels and achieves color distribution also has the ability to achieve uneven color distribution, that is, to enhance contrast and make the image clearer.

 

First, let's analyze how the fuzzy matrix blur the image. We assume that there is a 3*3 area in the image, and the color of the nine points inside is :.

 

Then, the contrast between pixel A in the center and any neighboring point is (a-B). Next we use the 3*3 fuzzy matrix to perform convolution for the center point, the result is (8B + a)/9. At this time, the contrast is changed to (8B + a)/9-B = A/9-B/9 = (a-B)/9, and the contrast is reduced by 8/9, after the result color is added to the value of the surrounding pixel, the convolution of the image becomes blurred.

 

In result formula (8B + a)/9, A and B are inherent colors of the image, so they cannot be modified. The denominator 9 is the divisor, make sure that it is equal to the sum of matrix elements, but do not modify it first. 8 is the sum of the eight points around the convolution matrix and can be modified at will, the coefficient 1 before a is equal to the element value in the middle of the matrix and can be modified. Therefore, we will focus on the coefficients before B and.

 

From the calculation process, the contrast is reduced because the proportion of B in the result of convolution is too high, leading to a reduction in contrast to the surrounding color B. Now the proportion of A and B in the result color is. We need to increase A or B, for example, to make B = 4, the result will be equal to (4B +) /5. The contrast with the surrounding pixel is increased from (a-B)/9 to (a-B)/5. At this time, the matrix should look like this:

 

(Allocate 4 evenly to eight neighboring points)

 

If the coefficient of B continues to decrease, the contrast will continue to increase until B = 0 and the result color is equal to a. It will not perform any conversion on the image and the contrast will not change. In this case, except the element in the middle of the matrix is 1, the other values are 0, that is, the non-transformation matrix we mentioned earlier.

 

According to this trend, if B <0, the result is the contrast enhancement matrix. Let B =-8, and the convolution matrix is equal. The code for implementing this matrix using a for loop is as follows:

 

VaR value: Number =-1; // whether the vertex is located in the center (for an even matrix, there are four such vertices, while the odd matrix has only one) if (math. ABS (matrixsize + 1) * 0.5-MATRIXx) <1 & math. ABS (matrixsize + 1) * 0.5-matrixy) <1) {value = 1 ;}

 

If the getconfilter (5, 0, false) filter is applied to the text, the result is 4.64.

 

 

Figure 4.64 contrast enhancement Matrix

 

We can see an effect similar to the relief stroke, but in general, the edge is still blurred. If we increase the matrixsize, the blur effect will become more obvious (Figure 4.65 ).

 

Figure 4.65 effect of setting matrixsize to 9

 

Is matrix A negative divisor? Let's calculate it.

 

At this time, the 8 points outside are equal to-1, so the result color is equal to (-8B + a)/(-7), contrast = (-8B + a)/(-7) -B = (B-a)/7, the contrast is still much weaker than the original (a-B. However, this contrast is reversed, so the colors of A and B are exchanged, and thus draw edges are formed.

 

The reason is that, after dividing the negative coefficient B by the negative divisor, a relatively large positive number is obtained. Therefore, the composition of B in the result color is still large.

 

It has been verified before. When B> 0, the contrast must be weakened. When B = 0, the contrast does not change. Now, even B <0 cannot increase the contrast, it seems that I can only make an article on.

 

The main contradiction is that the B coefficient is always the same as the divisor, so that B is always a positive number and cannot open the gap with. Therefore, we need to adjust the coefficient of A, such as 9, to obtain the Matrix. At this time, the divisor is equal to 1.
9 is equal to the number of matrix elements, but for a matrix with an even number of rows (such as 4*4), the central element contains four, therefore, the value of the central element cannot be equal to 4*4 = 16, but the sum of the peripheral elements must be calculated first:-1 * (4*4-4) =-12, then the sum of the central elements should be equal to 13, and then evenly distributed to 4 central elements, 13/4.

 

For an even matrix, the formula is (1 + (matrixsize * matrixsize-4)/4. Therefore, the core algorithm should be modified as follows:

 

VaR value: Number =-1; if (math. ABS (matrixsize + 1) * 0.5-MATRIXx) <1 & math. ABS (matrixsize + 1) * 0.5-matrixy) <1) {// whether the vertex is in the center (for an even matrix, there are four such vertices, while the odd matrix has only one) value = (matrixsize | 1 )? (Matrixsize * matrixsize): (1 + matrixsize * matrixsize-4)/4 );}


After modification, the running effect is shown in 4.66.

 

Figure 4.66 Effect of divisor correction

 

The opposite effect is indeed achieved with the fuzzy diffusion. The pixels on the edge are reduced in a circle, but it is not very obvious. It may be because the color is too simple, and such a change does not play a major role.

 

We try to enrich the color of the text. If we don't rely on the material, we can use the texture filter in Chapter 1 here, and fill the text with purple # 9966ff:

 

_main_txt.defaultTextFormat = new TextFormat("Microsoft YaHei", 80, 0x9966FF, true);var con:ConvolutionFilter = getConFilter(9, 0, false);var bev:BevelFilter = new BevelFilter(-17, 205, 0xFFCC00, 1, 0x660000, 1, 10, 10);_main_txt.filters = [bev];


 

If the convolutionfilter is not used, the running effect of the Oblique filter is 4.67.

 

Figure 4.67 fill texture with a filter

 

Apply the convolutionfilter to the texture-filled text, that is, append the con filter to the Bev, and get the 4.68 effect.

 

Figure 4.68 apply convolution filter to texture text

 

Many pixels are hollowed out, making it difficult for us to find out the rules. However, here we can change preservealpha to true. Because the text is rich in color, we can see the obvious effect without processing the alpha channel (Figure 4.69 ).

 

 

Figure 4.69 set preservealpha = true

 

Many pixels become white (this is not transparent, because preservealpha does not affect the alpha channel), which is quite strong in contrast to the texture, but seems a little overdone, leading to the disappearance of the background color of the text, so we can reduce the size of the matrix, such as 3*3 (Figure 4.70) or 5*5 (Figure 4.71 ).

Figure 4.70 3*3 effect of the sharpen Matrix
 

Figure 4.71 effect of the sharpening Matrix


Obviously, as the size of the matrix increases, the gap between colors is gradually opened, and the texture edge definition is constantly improved. Its function is opposite to fuzzy, in mathematics, it is usually called the fuzzy matrix back-convolution matrix, while in graphics, it is called sharpening.

 

In the sharpen matrix, the total number of matrix elements and divisor are equal to 1. In fact, there is also a special convolution matrix where the total number of matrix elements is equal to 0. At this time, I believe everyone can guess the approximate effect. If the contrast is weak, it will be black (when preservealpha = true ).

 

This matrix is, compared with the sharpening matrix, it is only because the value of the center point is 1 less, so the sum of elements is 0, making the image prone to black.

 

The format of getconfilter is adjusted:

 

value = (matrixSize | 1) ? (matrixSize * matrixSize - 1) : ((matrixSize * matrixSize - 4) / 4);


 

At this time, the divisor will be equal to 0, but you don't have to worry about it. In this case, Adobe will automatically Press 1 for processing.

 

The running effect is 4.72.

 

Figure 4.72 total matrix elements: 0

 

From this example alone, setting the total number of matrix elements to 0 does not seem very significant. In fact, after turning the color into pure black or pure white and removing the edge of the texture, we can use it to make sketch, relief, and other Photoshop filter effects. If it is used with the mixed mode, its creativity will be greatly enhanced.

 


 

Image programming in actionscript3 games)

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.