New thumbnails are not sharp
Closed, ResolvedPublic


Previously, whenever thumbnails were generated by ImageMagick, the sharpen option was used. This was especially helpful for small thumbnails of detailed images. It appears that this option may have recently been turned off judging by the softness of newly generated thumbnails.

New thumbnail (soft):

Cached old thumbnail (sharp):

This seems to have changed around the time of the recent ImageMagick update.

Version: unspecified
Severity: minor

bzimport set Reference to bz24857.
kaldari created this task.Via LegacyAug 18 2010, 5:32 PM
TheDJ added a comment.Via ConduitAug 19 2010, 3:11 PM

Perhaps syntax change in imagemagick commandline ?

kaldari added a comment.Via ConduitAug 19 2010, 5:57 PM

The correct current syntax is using the -unsharp option after the -thumbnail option. I think previously we were using a radius of 0.8 or something like that, so:
convert original.jpg -thumbnail 250x90 -unsharp 0.8 thumbnail.jpg

I have no idea if this is different than older syntaxes or what syntax we're using currently.

kaldari added a comment.Via ConduitAug 19 2010, 6:25 PM

Ah, looks like the old syntax was -sharpen (which is a much more logical name). Apparently they're using an unsharp masking algorithm to do the sharpening now, so they decided they had to change the option name while they were at it!

I've fixed it in r71304.

kaldari added a comment.Via ConduitAug 19 2010, 6:43 PM

Nevermind, we should be able to use -sharpen or -unsharp and they both should accept the parameter we're using (0x0.4). Hmm, back to the drawing board.

kaldari added a comment.Via ConduitAug 19 2010, 6:45 PM

reverted self in r71309.

kaldari added a comment.Via ConduitAug 19 2010, 7:08 PM

Maybe someone with command line access to our ImageMagick could do some tests and find out what's going on with it, i.e. test using 'convert -thumbnail' with -sharpen on and off, and then test it with -unsharp on and off, and see if there are any differences in the output files.

tstarling added a comment.Via ConduitAug 20 2010, 8:06 AM

The issue is an arbitrary change in SharpenImageChannel() made some time between ImageMagick 6.4.9 and 6.5.1. The relevant code changed from this:

alpha=exp(-((double) u*u+v*v)/(2.0*MagickSigma*MagickSigma));
kernel[i]=(double) (-alpha/(2.0*MagickPI*MagickSigma*MagickSigma));
if ((width < 3) || (u != 0) || (v != 0))

To this:

alpha=exp(-((double) u*u+v*v)/(2.0*MagickSigma*MagickSigma));
kernel[i]=(double) (-alpha/(2.0*MagickPI*MagickSigma*MagickSigma));

The result is that for a given sigma, images look more blurry in the new convert. Based on brief testing, to reproduce a result similar to the old 0x0.4 requires a sharpen parameter of approximately 0x0.8 in the new ImageMagick.

Both -unsharp and -sharpen exist in both versions, and have completely different implementations. Unsharp does not appear to have changed significantly, so it might be a candidate for version-independent operation in the next MediaWiki release. But for now I will just change our configuration to use 0x0.8 instead of 0x0.4.

kaldari added a comment.Via ConduitAug 21 2010, 12:47 AM

Nice sleuthing!

Gilles added a project: Multimedia.Via WebDec 4 2014, 10:44 AM
Gilles moved this task to Done on the Multimedia workboard.

Add Comment