Stef
Stef

Reputation: 30579

ImageMagick resize without interpolation

I have a small pixel map original and want to resize it for better readability.

Using mogrify -resize 1600% I get an interpolated image: wrong.

What I'm trying to get is this: right.

Can this be done by ImageMagick or any other open source command line tool?

Upvotes: 27

Views: 11546

Answers (4)

Wolfgang Brehm
Wolfgang Brehm

Reputation: 1721

display -sample 400% worked for me.

"Change the image size simply by directly sampling the pixels original from the image. When magnifying, pixels are replicated in blocks. When minifying, pixels are sub-sampled (i.e., some rows and columns are skipped over)."

https://imagemagick.org/script/command-line-options.php#sample

Upvotes: 2

Rafael Toledo
Rafael Toledo

Reputation: 1054

To keep the original values of the input image and avoid any blend or bluriness, you can use -interpolate nearest-neighbor or -interpolate integer.

It only works along -interpolative-resize. Be aware that -resize does not work correctly with -interpolate. You can check here on the imagemagick docs.

e.g.

convert input.png -interpolate nearest-neighbor -interpolative-resize 1600% output.png

Upvotes: 0

Unapiedra
Unapiedra

Reputation: 16197

This worked for me:

convert input.png -interpolate Integer -filter point -resize "10000%" output.png

Explanation:

  • Interpolation method "Integer" just picks a nearest value.
  • Filter 'point' is also necessary, but I do not know why.

Upvotes: 13

Stef
Stef

Reputation: 30579

I finally found the solution: using -scale instead of -resize does the trick. It is 'hidden' under the heading Scale - Minify with pixel averaging, therefore I overlooked it at first, searching for magnification instead of minification.

Upvotes: 26

Related Questions