softened, desaturated images when resized in imagemagick

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?".
Post Reply
torsoboy

softened, desaturated images when resized in imagemagick

Post by torsoboy »

I use imagemagick every day, but I can't figure out how to make resized images come out as crisp and colorful as the originals :(

All of our images have an sRGB profile, and here is an example of the code I am using:

convert -size 640x480 'filename.jpg' -resize 640x480 profile "*" -quality 100 -auto-orient 'newfilename.jpg'

or sometimes:

convert -size 640x480 'filename.jpg' -scale 640x480 profile "*" -quality 100 -auto-orient 'newfilename.jpg'

The images tend to come out soft and somewhat desaturated (colors aren't as vibrant).

Any ideas on how to fix that? I would like the images to look as close to the originals possible.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: softened, desaturated images when resized in imagemagick

Post by anthony »

Any form of resizing (except sample) will merge multiple colors together. This tends to make the colors softered, and de-saturate the image. On the other hand edges tend to look sharper.

It is the nature of the beast.

For more information of resizing images see
http://www.imagemagick.org/Usage/resize/

You may for example like to experiment with Gaussian filters and the 'blur' option to make images sharper looking.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
torsoboy

Re: softened, desaturated images when resized in imagemagick

Post by torsoboy »

When the images are resized using photoshop, the images come out crisp and colorful, so I don't think that supersaturation or softening of the images is something that should just be accepted or expected from imagemagick.

Also, you are saying that I should use a blurring effect to make the images sharper? That seems counter-intuitive... could you elaborate a little bit on that please?

If anyone else has any comments or suggestions, I would love to hear them.

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

Re: softened, desaturated images when resized in imagemagick

Post by fmw42 »

perhaps the best thing would be for you to provide an example of our original and degraded images and the command line you used to generate the result, because IM usually does a better job or resizing and image than PS
torsoboy

Re: softened, desaturated images when resized in imagemagick

Post by torsoboy »

The command I am using is in my first post, and I will try to get an example later.

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

Re: softened, desaturated images when resized in imagemagick

Post by fmw42 »

Problem probably lies in the use of a profile and perhaps is not the best thing or not applied with the correct profile(s). Sorry I am no expert on the use of profiles, but there have been many posts in this forum about using them. So perhaps you should search the forum and see what you find.

I am also puzzled by your use of profile "*". According to http://www.imagemagick.org/script/comma ... hp#profile, you must specify either - or + before the word "profile". So I am not sure what you are trying to do here, add or remove a profile? But note from that page:

"It is important to note that results may depend on whether or not the original image already has an included profile. Also, keep in mind that -profile is an "operator" (as opposed to a "setting") and therefore a conversion is made each time it is encountered, in order, in the command-line"

As Anthony said, you also have a choice of resizing filters and ways of controlling the nodes in order to adjust the blurring so that it will be less blurring and more sharp. That was what he was trying to tell you. See his posts. http://www.imagemagick.org/Usage/resize/#filter_blur and http://www.imagemagick.org/Usage/resize/#photoshop

I am not sure if auto-orient adds another resample to the process, which may case further softening.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: softened, desaturated images when resized in imagemagick

Post by anthony »

torsoboy wrote:When the images are resized using photoshop, the images come out crisp and colorful, so I don't think that supersaturation or softening of the images is something that should just be accepted or expected from imagemagick.
Photoshop does not just resize images, it also 'unsharps' the image to make edges sharper after resizing! IM does not do this as it leaves it up to you if that is what you want. See
IM Resize vs other Programs
http://www.imagemagick.org/Usage/resize/#photoshop
Also, you are saying that I should use a blurring effect to make the images sharper? That seems counter-intuitive... could you elaborate a little bit on that please?
Asctually YES! the gaussian filter has an expert contral called Filter Blur. whcih can reduce or expand the amount of bluring produced by that filter (which is actually rather over blurred for good reason) See
Filter Blur Expert Option
http://www.imagemagick.org/Usage/resize/#filter_blur

Another counter-intuitive method, the 'unsharp' filter sharpens images but creating a more blurred version of the image!!!! Weird but true. It basically subtracts the blurred image from the original to make a sharper version... which is why it is called Un-Sharp!

Sorry I don't really have a good example of this as I don't have a good idea on how to explain it and the effects of the controls on actual images. I do know however that this method of sharpening is very commonly used, and what Photoshop applies after resizing. What I do have is more of a place-holder for future expansion in IM examples
http://www.imagemagick.org/Usage/convolve/#sharpen

NOTE Anyone like to contribute to IM examples, this is a good area to do so. Come on show us your knowleadge and help the rest of us 8)
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: softened, desaturated images when resized in imagemagick

Post by anthony »

fmw42 wrote:I am not sure if auto-orient adds another resample to the process, which may case further softening.
No it doesn't it is a perfect 90 degree 'simple distortion or warping' basied on the EXIF setting found in the image. No blur or color mixxing is needed.

See Simple Image Warping, Rectangular Rotates
http://www.imagemagick.org/Usage/warping/#rect_rotates
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: softened, desaturated images when resized in imagemagick

Post by fmw42 »

NOTE Anyone like to contribute to IM examples, this is a good area to do so. Come on show us your knowleadge and help the rest of us
Blur Image for test.

A_original.jpg
Image

convert A_original.jpg -blur 0x3 A_original_blur3.jpg
Image

sharpen is just a gaussian type blurred image subtracted from the image to make an edge image (high pass filter), then equally blends that back with the original, so one has a high pass enhanced image.

convert A_original_blur3.jpg -sharpen 0x3 A_original_blur3_sharp3.jpg
Image

unsharp is more complex. It is similar. It takes the difference (edge result) as above, i.e. like sharpen BUT only blends some fraction or multiple of that with the original image, AND only if the difference is above a threshold. Thus unsharp 0x3+1+0 is basically the same as sharpen 0x3

convert A_original_blur3.jpg -unsharp 0x3+1+0 A_original_blur3_unsharp3_1_0.jpg
Image

compare -metric rmse A_original_blur3_sharp3.jpg A_original_blur3_unsharp3_1_0.jpg null:
164.661 (0.00251256)

The difference may be due to whether one uses a separable (gaussian) blur filter or not in one or the other but not both. Or it could be just some slight differences elsewhere in the IM implementation.

If one blends less with the original, one gets less sharpening.
convert A_original_blur3.jpg -unsharp 0x3+0.5+0 A_original_blur3_unsharp3_0p5_0.jpg
Image

If one blends more with the original, one gets more sharpening.
convert A_original_blur3.jpg -unsharp 0x3+2+0 A_original_blur3_unsharp3_2_0.jpg
Image

If one increases the threshold, then one gets less sharpening again.
convert A_original_blur3.jpg -unsharp 0x3+2+0.2 A_original_blur3_unsharp3_2_0p2.jpg
Image

Several of my scripts, binomialedge, gaussianedge, sharpedge use this blending concept (between the high pass filtered result and the original image) and a description is there with the scripts. The thresholding in my scripts is done differently and for a different purpose.
torsoboy

Re: softened, desaturated images when resized in imagemagick

Post by torsoboy »

Thank you for the replies! To blur an image in order to make it more sharp is definitely something that I wouldn't have thought up on my own, so I appreciate the information.

A lot of the techniques listed on the IM site as examples (and the examples given above) seem like they are kind of geared toward single images where you can look at the result and then change things up until that image looks its best. My particular scenario involves doing image resizing in bulk (about 50k images per day), and we can't go through each image individually. Does anyone have a command that they use for bulk image (photograph) resizing that they feel works great? I will start playing around with some images using the examples given above, but it seems like many other people have also done this in the past, and re-inventing the wheel might be an unwise use of my time if someone else has already done this same thing.

Thanks again!
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: softened, desaturated images when resized in imagemagick

Post by anthony »

You are right in that is the way that IM examples is geared. But that is the way people set up bulk image processing too..

They develop the scripts using the commands, and then run them over the files. If something does not work then they develop the script further or add handlers for specific types of images.

Resize with a specific fixed amount of unsharp, should work fine for the general case. But for better resizing images should also be gamma adjusted before and again after resizing. Also doing color reduction for GIF thumbnails after resizing is actually better done in YIQ colorspace for better handling of skin tones, but again few people do that either.

What is needed someone to write up how to put things together to produce a better image resizing script. ImageMagick provides the tools, IM Examples, provides the techniques, now we need to develop the application.

It seems that a section similar to one contributed by Wolfgang Hugemann for windows (still being added to), is also needed for UNIX. The closest we have for UNIX shell scripting is Batch Processing Alternatives.

Volunteers anyone?
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply