How does Xin Haicheng (your name) implement filter effects? How to implement the filter effect with codes

Source: Internet
Author: User

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:

  1. Int ModeFilterColor (int basePixel, int mixPixel)
  2. {  
  3. Int res = 0;
  4. Res = 255-(255-mixPixel) * (255-basePixel)/255;
  5. Return Math. Min (255, Math. Max (0, res ));
  6. }  

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:

  1. Int ModeOverlay (int basePixel, int mixPixel)
  2. {  
  3. Int res = 0;
  4. Res = (basePixel <= 128 )? (MixPixel * basePixel/128): (255-(255-mixPixel) * (255-basePixel)/128 ));
  5. Return CheckRange (res );
  6. }  

Finally, the logic code of the call is attached:

  1. Private void specialFilterToolStripMenuItem_Click (object sender, EventArgs e)
  2.         {  
  3. If (pictureBox1.Image! = Null)
  4.             {  
  5. // Obtain the image of the sky separated by 1.
  6. Bitmap sky = new Bitmap (Application. StartupPath + "\ sky.png ");
  7. // Obtain the Sky Mask image obtained from 2
  8. Bitmap mask = new Bitmap (Application. StartupPath + "\ mask_6.jpg ");
  9. // Sky fusion
  10. CurBitmap = SpecialFilter (srcBitmap, sky, mask );
  11. // Color and Halo
  12. Bitmap map = new Bitmap (Application. StartupPath + "\ map.png ");
  13. Bitmap light = new Bitmap (Application. StartupPath + "\ light.png ");
  14. CurBitmap = MapFilter (curBitmap, light, map );
  15. // Adjust the brightness and saturation
  16. Bitmap anMap = new Bitmap (Application. StartupPath + "\ anmap.png ");
  17. CurBitmap = AnMapFilter (curBitmap, anMap );
  18. PictureBox1.Image = curBitmap;
  19.             }  
  20.         }  

The above is the new Haicheng filter program implementation solution, the principle has been clearly written, you can try it!

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.