Only four steps are required to teach you how to implement the filter function.

Source: Internet
Author: User
Tags image processing library

Source Address: http://zihua.li/2014/06/implement-instagram-like-filters/

Filters play the role of giving charcoal and icing on the cake in the snow. An excellent filter can make it look special and eye-catching. Currently, almost all photo-related applications have the filter function, and there are few articles about the filter principle and implementation, for this reason, I wrote this article to systematically explain how filters are implemented.

What is filter?

A filter is an additional lens installed in front of a camera lens that filters out natural light for color and effect addition. Some digital image processing software (the most famous such as Adobe Photoshop) provides some specific preset tools to achieve the effect of camera filters, which are naturally referred to as "filters ". Software-implemented filters can simulate most lens filters, such as color temperature change filters (LB) and emphasizing filters. However, because they cannot reproduce the shooting environment, the software filters cannot restore information not contained in the photos, in addition, it is difficult to achieve the effect of a mirror and an ultraviolet filter (UV.

Filter Implementation steps

In terms of a simulated lens filter, the realization of a software filter is essentially a process of ing the colors in the photo. However, software filters do not end with this. complex software filters also need to add light changes (such as the LoMo effect), materials, and photo frames to photos, recently, the "haze removal" filter launched by meitu xiuxiu for domestic environmental problems is a manifestation of the complex software filter. However, the complex software filters are implemented in the following steps.

1. Color ing

The dark colors are reminiscent of old and simple colors. The light green colors make people feel soft and comfortable: color is the soul of a photo, and the most important step to implement a filter is color ing. Color ing refers to converting each color in the original photo into another color by some ing method. The most common and simplest method of ing is the look-up table method.

The principle of the look-up table method is to record a corresponding ing target color for each color in a table. When the look-up table method is used to map the color of a photo, you only need to traverse each pixel of the photo, then, find the target color corresponding to the pixel color in the table, and set the pixel as the target color. The premise of the lookup method is that the color ing has nothing to do with the surrounding color, that is, a color, regardless of the surrounding color or the location of the photo, the target colors must be the same.

The number of colors that RGB can represent is256*256*256 = 16,777,216If you want to record the ing results of each color, the color table requires more than 16 million records, which obviously cannot be applied to the actual project. To simplify the process, a record is usually used for each of the four similar colors.64 * 64 * 64 = 262,144Records.

Here, we use a benchmark color table first published by levzelensky as an example:

In the table above, 262,144 colors are divided into 8 blocks, each of which64 * 64The color of each grid is different. When performing color ing, first use the digital image processing software to apply a simulated filter to the baseline color table to generate a ing table (for example), and then for each pixel of the photo to be processed, find the position of the pixel color from the base color table, and then obtain the target color from the corresponding position of the ing table.

For the famous image processing library gpuimage on IOS/OS XGPUImageLookupFilter)Method to implement the above process.

2. Overlay Materials

Most simple filters can be implemented only by color ing. However, more steps are required for complex filters. The most typical one is the LoMo effect. To achieve the LoMo effect, in addition to color ing to make the color more colorful, you also need to add a four-byte dark angle for the photo. First, you need a dark corner material:

Stack the clip on the photo and apply the overlay hybrid algorithm.

You can select different hybrid algorithms based on different materials. For the material of the dark corner, overlay can bring the best effect. Another point is that there is no fixed rule for color ing first or adding materials first, and you need to select based on the actual effect. In terms of the LoMo dark corner, it is better to overlay the material first.

3. Apply Photo Frames

Strictly speaking, the photo frame is not part of the filter, but considering that a good photo frame can improve the color of the photo, I would like to mention it here. Different photo frames apply different methods. Some photo frames can be directly covered in the photo, while others need to be mixed with the photo according to a certain algorithm, the app photo frame is the simplest part of the entire filter. Similar to photo frames, photo decorations are similar. For example, a peach or custom text is not technically difficult to implement photo decorations, the only thing to remember is not to add Decorations to your filter. Otherwise, the filter will fall into the conventional style.

4. Repetition

The final filter effect may need to be implemented by repeatedly applying the above steps. For example, many Instagram filters can be completed only by applying a variety of materials. This process requires the designer to keep enough patience, 1.1 points to ponder, a good filter can be born.

 

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.