My algorithm for scaling a bitmap b of size w1 × h1 to a bitmap of size w2 × h2:
- scale b to a bitmap b1 of size lcm(w1, w2) × lcm(h1, h2) using nearest-neighbor scaling algorithm;
- partition b1 to a grid that have w2 columns and h2 rows where all columns have the same width and all rows have the same height;
- set the color of every pixel in b1 to the average color of the pixel’s belonging grid cell;
- scale the modified b1 to a bitmap b2 of size w2 × h2 using nearest-neighbor scaling algorithm;
- The bitmap b2 is the result of this algorithm.
The algorithm above is not the most efficient one to get the result. I only use it to describe the effect of the scaling algorithm (and I can do it in Photoshop instead of writing a program). Is there a known algorithm that produces the same result as mine?
2
Answers
I found a detailed description here: http://entropymine.com/imageworsener/pixelmixing/.
The problem with your algorithm is that it will take a lot of memory. As an example, if you scale from a size of 11×11 to 13×13, the least common multiple (lcm) of 11 and 13 is 143. You will therefore create a 143×143 image, and then reduce it to 13×13.
As an alternative, have a look at “bilinear interpolation”: https://en.wikipedia.org/wiki/Bilinear_interpolation (this article also gives other methods in the “See also” section).