Human eyes are much more sensitive to gray/brightness than to color when observing images, human eyes are more sensitive to warm and cold colors than to General colors. After a lot of tests, people have obtained an empirical formula to explain how the human eyes recognize brightness:
Gray = red * 0.3 + green * 0.6 + blue * 0.1
The right side has a more similar formula because the human eyes are most sensitive to Green:
Gray = green
The gray effect of the image can be achieved by removing the red and blue values in each pixel of the image:
VaR bitmap: bitmapdata = new bitmapdata ();
...
For (var I: uint = 0; I <bitmap. width; I ++ ){
For (var j: uint = 0; j <bitmap. height; j ++ ){
VaR color: uint = bitmap. getpixel (I, j );
Color = color <16> 24;
Color = color <16 | color <8 | color;
Bitmap. setpixel (I, j, color );
}
}
Then think about the wood carving effect. The wood carving looks only two colors. Therefore, you can give a decomposition value during grayscale processing. If the value is greater than this value, it will be displayed in black, otherwise it will be completely white. You can modify the code:
VaR bitmap: bitmapdata = new bitmapdata ();
...
For (var I: uint = 0; I <bitmap. width; I ++ ){
For (var j: uint = 0; j <bitmap. height; j ++ ){
VaR color: uint = bitmap. getpixel (I, j );
Color = color <16> 24;
Color = color <16 | color <8 | color;
If (color> 128) color = 0xff;
Else color = 0;
Bitmap. setpixel (I, j, color );
}
}
Then let's look at the sharpening effect. Sharpening is a few adjacent pixels. You can add the difference between the current pixel and the surrounding pixel. You can multiply the difference value by a value, for example, 0.3 -- the value is the sharpening coefficient.
The image softening principle is the same as sharpening, but it does not mean to reflect the difference, but to reduce the difference. It replaces the current vertex with the average values of the surrounding vertices.
Then it spreads, that is, the watercolor effect. A simple method is to replace the random points around the current point. So think of a certain style of watercolor effect-it requires a very complicated processing method.
VaR bitmap: bitmapdata = new bitmapdata ();
...
VaR rate: Number = 0.2; // Diffusion Coefficient
For (var I: uint = 1; I <bitmap. Width-1; I ++ ){
For (var j: uint = 1; j <bitmap. Height-1; j ++ ){
If (math. Random ()> rate) continue;
VaR II: uint = I + (math. Random ()> 0.5? 1:-1 );
VaR Jj: uint = J + (math. Random ()> 0.5? 1:-1 );
Bitmap. setpixel (I, j, bitmap. getpixel (II, JJ ));
}
}
For me, the most difficult thing to understand is the principle of relief effect: Subtract two adjacent pixels and add 127 as the new value. What theory is this based on?