Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image downscale algorithm

Is someone know which alogirhtm(s) Microsoft used in Paint to downscale picture?

I'm trying to develop a little software (for personnal use) to downscale a lot of pictures (in Java). After using the "builtin" java functions as NearestNeighbor, Bilinear and Bicubic, with poor result quality... I've used Lanczos algorithm which give far better results but without reaching MS Paint results :/

Note: Paint version used is the one of Windows 7, the Lanczos implementation I've used is the one of the Millie project LanczosResamplePlugin.java and the builtins java are from Graphics2D :

    g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
    g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);

If someone have an idea to reach the same quality result, it will be helpfull (for my resulting pictures, and also for my knowledges).

Some results here:

(I'm not posting NN, bilinear and bicubic results which give really poor quality results)

Bellow a landscape (found on google image). Original file size is 1680x1050, and the grass is really sharpen in original file (so Paint result seems to be better than Lanczos).

Original image can be view here : landscape-wallpaper-11a.jpg

Lanczos result:

Lanczos landscape

vs Paint Result:

Paint landscape

Another picture bellow (personnal picture), with some text. You can notice that in Lanczos result the text is less readable (less sharpen) than in Paint result. Moreover, between the black title text and the red area with white text, in Lanczos result there are some noise, which does not exist in Paint result. And at the bottom, the url on the paper is completly blur / unreadable on first result, and it's readable on Paint result.

Lanczos result:

Lanczos cheese

vs Paint Result:

Paint chesse

I'm firsly suppose that MS use 2 algorithms: 1 to downscale and a 2nd pass to sharpen the resulting picture? But as the bottom url in last example is still readable, it may be not resulting from a sharpening of downscaled result...?

Thanks

Edit

Ok, I'm a little bit stupid... the noise on pictures is due to jpeg compression quality (which I have no set in my Java code when saving picture).

Here below is the result in png, so witout noise. But result is still not readable as paint one.

Lanczos cheese png

Lanczos cheese png

like image 977
Alexxx Avatar asked Aug 07 '15 08:08

Alexxx


2 Answers

MSPaint uses bilinear interpolation then sharpens the image with a convolution kernel:

0.0, -0.125, 0.0

-0.125, 1.5, -0.125

0.0, -0.125, 0.0

ImageMagick command:

magick image.png -scale 512 -morphology Convolve "3x3: 0.0, -0.125, 0.0 -0.125, 1.5, -0.125 0.0, -0.125, 0.0" image_resized.png
like image 92
skenera Avatar answered Nov 06 '22 15:11

skenera


Ok I'm thinking I've got it!

In fact there are no magic in MS Paint (win7). It must used the well known Lanczos algorithm to resize image down (and up?), which seems to be the best general resampling algorithm (it seems that in XnView, in where we can choose the resampling algorithm, it's the default option).

So, I've found 2 other java implemtenations which each give differents results:

Original image : landscape-wallpaper-11a.jpg

  1. Lanczos from Milli project here landscape Lanczos 1

  2. Lanczos from "atyou" japanese blog here landscape Lanczos 2

  3. Lanczos from "zattonaka" japanese blog here landscape Lanczos 3

  4. Algo (Lanczos?) from MS Paint Win7 landscape MS Paint

My second result set from one of my personnal picture:

  1. From Milli project here cheese Lanczos 1

  2. From "atyou" japanese blog here cheese Lanczos 2

  3. From "zattonaka" japanese blog here cheese Lanczos 3

  4. Algo (Lanczos?) from MS Paint Win7 cheese MS Paint

The result in item list 3 seems to be the closest one to Paint result (but not same). It have sharp well readable text (second test) and sharp grass as in original image (first test).

Moreovoer, as said before (edit part of my question), the noise was due to jpeg compression when saving. Results above here, are in PNG, and so do not suffer to jpeg artefact compression.

like image 45
Alexxx Avatar answered Nov 06 '22 14:11

Alexxx