Eye enlargement Algorithm for image beauty.

Source: Internet
Author: User

Currently, apps with various image effects on mobile phones are becoming increasingly popular, such as meitu xiuxiu, camare360, and beautify cameras, there are also some excellent ones in some specific directions, such as the magic camera. Almost all of these software provide a considerable number of face beautification functions. These basic functions absorb the interest of many hot-blooded girls and ugly girls. As a result, almost every 25-35 female friend I know knows meitu xiuxiu, while those who know Photoshop are slim. However, I recently heard from some friends that the image software on the mobile phone has passed the development stage and I don't know whether it is like this.

As the most fascinating part of the face, the eyes are naturally the beautification objects that software developers will not miss. Take cool images with extremely low running speeds as an example, he provides at least eye-magnified, redeye removal, dark circles, eye color, eye shadows, and many other eye-related beauty knives. As a matter of fact, there are a lot of flowers after some wonderful code speeches are made by the application developers, which is indeed a beauty artifact for many people.

However, these simple functions are sent to Baidu or Google search algorithms, and there is not much information to match. At least I have not found anything that can be used directly in practice.

This article shares some of my research results on eye scaling, which were conducted three years ago.

In general, eye scaling is a local distortion of an image. The liquefaction filter in Photoshop best reflects the soul of this algorithm. You can use one of the following methods to scale your eyes, as shown in:

(To save space, rotate)

Using this expansion tool, selecting the appropriate parameters can achieve very good results. However, if you only want to study the huge liquefaction Filter Algorithm for this functional area, it is extremely brave. Although currently, in open-source software, you can get code reference from gimp's iwarp code or a paint.net smudgle plug-in by decompiling, this process is quite painful, because I 've been suffering for once, I 'd like to share a simple way to achieve it, so that we can alleviate your pain.

During manual eye scaling, there are generally three parameters: center point, brush size, and intensity, which are represented by (pointx, pointy), radius, and strength respectively. For example, meitu provides the following user interfaces:

The center point is obtained by clicking the mouse. The size of the paint brush determines the range affected by the algorithm. Intensity affects the degree of eye enlargement.

My algorithms are implemented through the simple process shown in.

For pixels (x, y) at any position within the paint brush's radius, the ratio between the position and the radius is determined according to a linear formula based on the intensity setting value, select a position pixel from the straight line between pointx, pointy and (x, y) as the new pixel value. If the new position is located between two points (x1, y1), the eye is reduced, and is located on the extension line of the straight line (X2, Y2 in the figure), the eye is enlarged, which is expressed by a simple piece of code:

 

Left = IIF (pointx-radius <0, 0, pointx-radius) 'calculates the Boundary Value Top = IIF (pointy-radius <0, 0, pointy-radius) right = IIF (pointx + radius> = m_width, m_width-1, pointx + radius) Bottom = IIF (pointy + radius> = m_height, m_height-1, pointy + radius) powradius = radius * radius for Y = top to bottom offsety = Y-Pointy for X = left to right offsetx = x-pointx xy = offsetx * offsetx + offsety * offsety if XY <= powradius then' in the specified radius scalefactor = 1-XY/powradius scalefactor = 1-strength/100 * scalefactor 'according to this relationship, the position of the sampling point is calculated. posx = offsetx * scalefactor + pointx posy = offsety * scalefactor + pointy if posx <0 then' place out-of-bounds posx = 0 elseif posx> = m_width then posx = m_width-1 end if posy <0 then posy = 0 elseif posy> = m_height then posy = m_height-1 end if speed = y * m_stride + x * 3 Index = posy * m_stride + posx * 3 imagedata (speed) = imagedatab (INDEX) 'assign the value of the current vertex to the value of the sampling vertex imagedata (speed + 1) = imagedatab (index + 1) imagedata (speed + 2) = imagedatab (index + 2) end if next

 

I didn't provide the complete code, because people who really understand it can understand it by just a few words, and those who reach out to the party are not welcome here.

There are many improvements to the above Code. First, the above results will be somewhat unclear, just because the coordinates of the calculated sampling are actually floating point numbers, therefore, direct Integer Optimization will lead to large errors. A more reasonable approach is to use interpolation algorithms such as bilinear interpolation for computation and optimization. Second, the calculation formula of linear ing can also be adjusted. For example, the smaller the change of those pixels that move forward from the eyes, the larger the transformation.

The effect is as follows:

According to the above detailed written a test program: http://files.cnblogs.com/Imageshop/ZoomEyes.rar

* *************************** Basically, I do not provide source code, however, I will try to use text to clearly describe the corresponding algorithm or provide the reference documentation ************************

* ************************************ Because it depends on your own the effort and the effect written in practice are exactly what they are, people must rely on their own *******************

* ************************** Laviewpbt time: 2014.7.14 contact QQ: 33184777 reprinted. Please keep the information of this bank **********************

 

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.