Recently, the effect of the new Haicheng filter is very popular. For this reason, Camera360 has also specially developed the corresponding app. Every day, the P chart is also scrambling. Today, I will decrypt it for you.
Let's take a look at the effect of my program implementation:
SOURCE image
Effect chart
I will explain in detail how to implement this filter effect in a program:
1. Sky detection and Segmentation
The most important filter in this filter is the division and replacement of the sky area. I will provide a reference for the division of the sky:
Sky detection by using tive context inference. Neurocomputing.2016
This article separates the sky based on training learning. The general process is as follows:
2. Sky MASK
After we get the precise segmentation area of the sky through 1, we need to binarization this area, black is not the sky area, White is the sky area, then a Gaussian filter of the proper radius is performed on the two-value graph, so that the border between the sky and the non-Sky is excessive, that is, the feathers in PS. The following figure is used as an example:
3. Sky fusion
Use the Mask in step 2 to combine the source image and the sky image. This step uses the normal mode in PS to combine the source image. The white area shows the sky image and the black area shows the source image; the following figure shows the sky image used here:
(C) sky images
The effect is as follows:
4. Color
This step is critical to color. If you need a cartoon of any style, you need to adjust the color of the style. Here I refer to the following styles (ps: // www.zhihu.com/question/29594460? From = groupmessage & isappinstalled = 1 "> Click to open the link ):
5. Halo
After coloring, we need to add a certain Halo to the image. In this step, we can directly use the Halo Template and mix it with the source image as a filter layer.
The Halo template used by myself is as follows:
The result of steps 4-5 is shown as follows:
The code for calculating the mixed color filter layers is as follows:
- Int ModeFilterColor (int basePixel, int mixPixel)
- {
- Int res = 0;
- Res = 255-(255-mixPixel) * (255-basePixel)/255;
- Return Math. Min (255, Math. Max (0, res ));
- }
6. Saturation and brightness adjustment
Finally, perform a simple adjustment of the saturation and brightness of the image to bring up a bright and fresh feeling. The adjustment steps are as follows:
The effect is as follows:
(G) Effect of xinhaicheng filter
If you need to enhance the border, you can perform an operation to illuminate the edge of the image before 1 to obtain the illuminating edge Image A. Then, let's talk about the superposition of A and the source image. The effect will be better.
The code for overlay processing is as follows:
- Int ModeOverlay (int basePixel, int mixPixel)
- {
- Int res = 0;
- Res = (basePixel <= 128 )? (MixPixel * basePixel/128): (255-(255-mixPixel) * (255-basePixel)/128 ));
- Return CheckRange (res );
- }
Finally, the logic code of the call is attached:
- Private void specialFilterToolStripMenuItem_Click (object sender, EventArgs e)
- {
- If (pictureBox1.Image! = Null)
- {
- // Obtain the image of the sky separated by 1.
- Bitmap sky = new Bitmap (Application. StartupPath + "\ sky.png ");
- // Obtain the Sky Mask image obtained from 2
- Bitmap mask = new Bitmap (Application. StartupPath + "\ mask_6.jpg ");
- // Sky fusion
- CurBitmap = SpecialFilter (srcBitmap, sky, mask );
- // Color and Halo
- Bitmap map = new Bitmap (Application. StartupPath + "\ map.png ");
- Bitmap light = new Bitmap (Application. StartupPath + "\ light.png ");
- CurBitmap = MapFilter (curBitmap, light, map );
- // Adjust the brightness and saturation
- Bitmap anMap = new Bitmap (Application. StartupPath + "\ anmap.png ");
- CurBitmap = AnMapFilter (curBitmap, anMap );
- PictureBox1.Image = curBitmap;
- }
- }
The above is the new Haicheng filter program implementation solution, the principle has been clearly written, you can try it!