How to implement the scaling algorithm in PS

Source: Internet
Author: User

---principle, realization---

This time to focus on the PS scaling problem, PS uses the scaling method is the nearest neighbor sampling interpolation (nearest neighbor interpolation) algorithm. But compared to the general proximity algorithm, what we have to do is to find this improved algorithm.

The following is a brief description of the general method of nearest neighbor sampling interpolation: Use the formula sx=dx* (SW/DW) to calculate the source pixels corresponding to the target pixel (see reference article 1). At first I also used this method, but the scaling results compared with PS, pixel insertion position is different, the main difference in PS is the median line is symmetrical on both sides. But along the symmetrical thinking of several methods, are not up to the requirements, Internet search also have no clue.

This situation reminds me of the problem of solving ant-line problems: from a simple simulation of the surface phenomenon of a mobile ant line to a careful observation, the flow of lines is only an external manifestation of a simpler and more efficient algorithm. Aware of this, try not to try again, trying to re-examine the problem from the definition, the goal is to find a convenient computing, simple form even aesthetic (symmetrical), preferably without division, can accurately describe the location of the algorithm.

For example, to re-describe the problem, a x 10 image, enlarge 130%, will generate a five X 13 image, because the same aspect magnification, only need to calculate a row of data, from 10 points to 13 points, more than 3 points, now the problem, Which 10 locations do you want to insert 10 pixels into 13 seats? At the same time, the extra 3 slots are filled with 10 of the pixels in each of them?

Imagine an interpolation algorithm that requires a pixel-by-pixel processing, combined with the above algorithm requirements-interpolation, step-by-step processing, symmetry, no division, and precise description-the idea that these things are not very similar to the features of the Bresenham algorithm? Is it possible to solve this problem with the Bresenham algorithm? A little excited, immediately hands-on, a drawing after deduction calculation, no accident really can, and have Bresenham keyword, also very easy to search for reference article 2.

Here is the basic idea, is to enlarge the pixel, the original 10 pixels, enlarged into 10 13x13 pixels, 13 pixels into 13 10x10 pixels, so that 13 "pixels" can be seamlessly filled into the space of 10 "pixels", and then by contrast to determine the corresponding pixels of the fill. At this point can be seen as a game, 10 length 13 of the large grid row, and then with 13 length of 10 small lattice fill, and finally make a contrast, small lattice to which large lattice of the part of more, to fill in which large lattice, if fall into the different large lattice of two parts of the same, which can be counted, But the next lattice is easy to calculate (see Figure 1 for a top thousand).

Figure 1

---codes and procedures (MASM32)---

Http://files.cnblogs.com/hhh2000/Zoom.zip


---reference articles---

1. High-quality fast image scaling the upper neighbor sampling interpolation and its speed optimization http://blog.csdn.net/housisong/article/details/1404896
A general nearest neighbor sampling interpolation algorithm

2. Fast image scaling processing based on Bresenham algorithm http://www.doc88.com/p-699581250411.html
The same algorithm, has the derivation, has the formula

3. Quick image scaling algorithms and code http://www.compuphase.com/graphic/scale.htm http://willperone.net/Code/ codescaling.php
Another Bresenham class algorithm with simpler but asymmetric form

How to implement the scaling algorithm in PS

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.