The quality of re-sized image is not good

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
User avatar
plicatibu
Posts: 5
Joined: 2012-09-22T15:10:07-07:00
Authentication code: 67789
Location: Brazil

The quality of re-sized image is not good

Post by plicatibu » 2012-09-22T15:23:16-07:00

Hi, all.

I'm a brand new user if IM.

I usually have to convert an image to many different formats and dimensions.

I used to do it with Gimp and now I created a script that calls IM.

I'm having an issue that I'm pretty sure it's my fault but I could not find a solution. Images re-sized using Gimp look better than those re-sized by IM.

The command line I'm using:

Code: Select all

convert -filter Cubic -resize 640x480! -gravity center -extent 640x480 -format jpg sample.png outdir/sample-640x480.jpg
Bellow are both images. The first one was re-sized using Gimp. The second one was re-sized using IM.

Does any one have an idea about what I'm missing?

Thank you.

Image
Image re-zised by Gimp

Image
Image re-zised by IM

User avatar
fmw42
Posts: 25556
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: The quality of re-sized image is not good

Post by fmw42 » 2012-09-22T16:01:13-07:00

convert -filter Cubic -resize 640x480! -gravity center -extent 640x480 -format jpg sample.png outdir/sample-640x480.jpg
You chose a poor filter and you syntax is not proper but should work. In IM 6 the input image comes before the settings and the commands. You also do not need -format. That does not help in convert and is used mostly in mogrify

I presume this was a magnification (upsampling).

see
http://www.imagemagick.org/Usage/resize/
http://www.imagemagick.org/Usage/resize/#nicolas
viewtopic.php?f=22&t=21804
viewtopic.php?f=1&t=21850

Try something like

convert sample.png -filter Mitchell -resize 640x480! -gravity center -extent 640x480 outdir/sample-640x480.jpg

or for more sharpness but more artifacts, try

convert sample.png -filter RobidouxSharp -resize 640x480! -gravity center -extent 640x480 outdir/sample-640x480.jpg

or for lots of sharpness, but lots of jaggies and other artifacts try

convert sample.png -filter Catrom -resize 640x480! -gravity center -extent 640x480 outdir/sample-640x480.jpg

or

convert sample.png -filter Lagrange -resize 640x480! -gravity center -extent 640x480 outdir/sample-640x480.jpg


For less sharpness and less artifacts, if you are really picky, try one of Nicolas Robidoux's sigmoidal processing as per http://www.imagemagick.org/Usage/resize/#nicolas


P.S. GIMP and Photoshop use a cubic-convolution filter (probably Keys/Catrom), but add unsharp filtering (behind the scenes) to make it sharper afterwards. In IM you can do this with -unsharp, but if you chose the right filter and filter arguments, you can achieve something equivalent without the extra unsharp step.

User avatar
plicatibu
Posts: 5
Joined: 2012-09-22T15:10:07-07:00
Authentication code: 67789
Location: Brazil

Re: The quality of re-sized image is not good

Post by plicatibu » 2012-09-22T17:00:24-07:00

First of all I want to tahnk you for replaying.

I know absolutely nothing about image processing. I just want to re-size my images and get the best results, so 9% of everything you wrote is like Greek (or worse, Chinese) for me :D

Anyway I tried every command line samples and the best result was when I used Catrom filter.

I compared each image generated with Catrom filter and the images are almost as good as the images provided by Gimp (my script generates 72 images in gif, jpg and png).

As I don't have the knowledge to make them look at least as good as those provided by Gimp I'll use the Catrom filter. I think it solved my problem.

Thank you again.

User avatar
fmw42
Posts: 25556
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: The quality of re-sized image is not good

Post by fmw42 » 2012-09-22T17:08:27-07:00

The Catrom (Keys cubic convolution) is probably what GIMP and Photoshop use before adding some sharpening via unsharp masking.

So if you want to add some sharpening try

convert sample.png -filter Catrom -resize 640x480! -unsharp 0x1 -gravity center -extent 640x480 outdir/sample-640x480.jpg

Change the 1. Try 0.5, 1, 1.5, 2 etc or any decimal value. Check those results and see what you get.

NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: The quality of re-sized image is not good

Post by NicolasRobidoux » 2012-09-22T18:09:30-07:00

@plicatibu: Could you post the small size image that you are enlarging?

User avatar
plicatibu
Posts: 5
Joined: 2012-09-22T15:10:07-07:00
Authentication code: 67789
Location: Brazil

Re: The quality of re-sized image is not good

Post by plicatibu » 2012-09-22T21:50:35-07:00

Hi.

The original image is bellow.

I really appreciate your support guys, but it's getting more complicated than I expected.

I receive many different images (file format, original dimensions and type of draw) because games I develop / sponsor) that I have to convert to a lot of predefined file formats and dimensions to submit the games to sites.

Gimp is more user friendly: I just ask him to re-size image and it always does a great job. I don't need to know anything about image processing. As a drawback I need to do it manually.

Will I have to adjust parameters every time? It's not practical for me. If that's case, I prefer to learn how to develop scripts for Gimp (fu scripts) and call it from command line.

Best regards.

Image

NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: The quality of re-sized image is not good

Post by NicolasRobidoux » 2012-09-23T03:40:34-07:00

plicatibu wrote:...
Will I have to adjust parameters every time? It's not practical for me. If that's case, I prefer to learn how to develop scripts for Gimp (fu scripts) and call it from command line.]
No. All you have to do is find a set of parameters which works well with your typical use(s), and then use those all the time.

NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: The quality of re-sized image is not good

Post by NicolasRobidoux » 2012-09-23T04:49:16-07:00

@plicatibu:
I'm still tweaking http://www.imagemagick.org/Usage/resize/#nicolas, which should see a major update within a week, but here are some quick suggestions, if your images tend to be more or less of the kind you show.

Check if your ImageMagick is compiled in HDRI:

Code: Select all

convert -version
If the output does not say "HDRI", I do not recommend using Catmull-Rom (obtained with convert {input} -filter catrom -resize {size}x{size}! {output}), which is likely to be the filter used by your version of GIMP. If you do have an HDRI ImageMagick (or are willing to install one), let me know and I'll modify my recommendations accordingly.

Note that the following recommendation takes into account that you are producing JPEGs, likely to be put on the web, so that file size matters. It also takes into account that this is some form of pixel art, and consequently that "ripples" are bad. (Look at the skin in your GIMP enlargement.) Warning: I'm using somewhat recent features of ImageMagick, so this may not work as well with your system as with mine.

Try this:

Code: Select all

convert wargame.png -define filter:window=Quadratic -define filter:lobes=3 -distort resize 640x480! -sampling-factor 2x2 -quality 89 wargame.jpg
which gives this
Image
Of course, my "aesthetic taste" is involved in this choice of method. If you want something sharper, for example, please let me know.

In any case, you may or may not think that this is better than what you get with your GIMP script. (BTW, if you use a GEGL-enabled version of GIMP and select the Lanczos filter when resizing, you actually get Lohalo, a filter I invented, instead. Lohalo would work really well with wargame.png. A version of Lohalo which only works well for enlarging or resizing mildly is found in VIPS (named Nohalo) and NIP2 (named Upsharp). I actually "owe" some additional programming to the GEGL people: Long promised versions of some of the methods found in ImageMagick. So, GIMP may resemble my recommendations more in the not to distant future.)

But here's the kicker:

Code: Select all

ls -al wargame-640x480-gimp.jpg wargame.EWAQuadraticJinc2x2Q89.jpg 
-rw-rw-r-- 1 nicolas nicolas 83094 2012-09-23 06:48 wargame-640x480-gimp.jpg
-rw-rw-r-- 1 nicolas nicolas 61841 2012-09-23 07:34 wargame.EWAQuadraticJinc2x2Q89.jpg
The version produced by the above IM command is more than 25% smaller.

There may be a better way of doing things with ImageMagick, but this is what I get out of 30 minutes of experimenting and a bit of back of the envelope reflection.
Last edited by NicolasRobidoux on 2012-09-23T06:16:03-07:00, edited 11 times in total.

Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: The quality of re-sized image is not good

Post by Bonzo » 2012-09-23T04:54:21-07:00

One problem is you are using -resize 640x480! and it should be -resize 640x480
Width and height emphatically given, original aspect ratio ignored.
You are doing the same in Gimp.

NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: The quality of re-sized image is not good

Post by NicolasRobidoux » 2012-09-23T05:08:31-07:00

@Bonzo: I figured that's what he/she actually wanted.
But indeed I found it strange that he/she did not care about aspect ratio.

NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: The quality of re-sized image is not good

Post by NicolasRobidoux » 2012-09-23T05:17:29-07:00

@plicatibu:
Quick note: You can use my suggestion every time. It won't give awful results in any situation. All you have to do is replace the fields shown in red italics below, but everything else in the command stays exactly the same, every time:

convert input -define filter:window=quadratic -define filter:lobes=3 -distort resize widthxheight! -sampling-factor 2x2 -quality 89 output.jpg

Your input may be any format understood by ImageMagick (basically anything). Because I used JPEG specific commands, however, I assume your output image is .jpg.

Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: The quality of re-sized image is not good

Post by Bonzo » 2012-09-23T06:08:35-07:00

@NicolasRobidoux
I had assumed as he was using -extent as well the OP wanted to resize the image ( I can not see any good reason to distort it ) then pad it out to 640 x 480.

I think we need some input as the the actual output requied.

User avatar
plicatibu
Posts: 5
Joined: 2012-09-22T15:10:07-07:00
Authentication code: 67789
Location: Brazil

Re: The quality of re-sized image is not good

Post by plicatibu » 2012-09-23T10:34:37-07:00

Dear friends, really thank you all. You guys are very helpful.

@NicolasRobidoux

1) I ran the command

Code: Select all

convert.exe -version
and got the following:

Code: Select all

Version: ImageMagick 6.7.9-6 2012-09-13 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
Features: OpenMP
So there is no HDRI in this version (and I have no idea what is it :D )

2) don't convert only to jpg but for png and gif too.

3) Once my games are ready for submission, I need to submit it to sites in order to get it published. The point is that every site requests a thumbnail in a different format (some want gif files, some want jpg files and some want png files). Not only that, but the dimensions of the images varies on a site basis.

If the thumbnails submitted does not follow the site's requirements then the game is automatically rejected.

Here are the dimensions I need to generate:

Code: Select all

  DIMENSIONS = [
                "60x60",
                "70x59",
                "75x75",
                "80x70",
                "80x80",
                "100x75",
                "100x100",
                "120x85",
                "120x90",
                "140x140",
                "145x100",
                "160x160",
                "162x100",
                "180x135",
                "200x123",
                "200x160",
                "200x200",
                "250x180",
                "250x200",
                "300x200",
                "300x300",
                "390x255",
                "620x320",
                "640x480"
               ]
It will give me 3 file formats x 24 dimensions = 72 images.

@Bonzo I adapted the command I'm using from here.

But it has a problem for me: some images will show white background in the right/left or top bottom of the image as show bellow, what sites don't accept. That's the reason to use the ! to ignore aspect ratio.

Image


Artists are free to do whatever they want: brighter, darker images, more real, more like cartoons.. They just have to make it related to the theme of the game.
Bellow are some images I re-sized so you can have an idea how much they differ from each other.

Regards.

Image

Image

Image

Image

Image

Image

Image

Image

Image

Image

NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: The quality of re-sized image is not good

Post by NicolasRobidoux » 2012-09-23T10:47:43-07:00

If you want to do this automatically, I think that indeed you're stuck with "!".
-----
Ah! So it's mostly thumbnails and small versions that you produce.
Note that, in my book, your images are more or less of the same type.

NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: The quality of re-sized image is not good

Post by NicolasRobidoux » 2012-09-23T10:51:18-07:00

Could liquid rescale allow him to keep the aspect ratio while filling the space? http://www.imagemagick.org/Usage/resize/#liquid-rescale

Post Reply