Last modified: 2013-09-27 18:10:34 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T26889, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 24889 - ImageMagick thumbnails have moiré problems
ImageMagick thumbnails have moiré problems
Status: NEW
Product: MediaWiki
Classification: Unclassified
File management (Other open bugs)
unspecified
All All
: Low normal (vote)
: ---
Assigned To: Nobody - You can work on this!
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2010-08-21 12:15 UTC by Adam Cuerden
Modified: 2013-09-27 18:10 UTC (History)
7 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments
Sample scale-downs using ImageMagick & gimp (266.60 KB, image/png)
2011-09-15 22:55 UTC, Brion Vibber
Details
Some frequency spectra (206.73 KB, image/png)
2011-12-01 13:12 UTC, Tim Starling
Details

Description Adam Cuerden 2010-08-21 12:15:48 UTC
We use a lot of historic media, for obvious reasons. Unfortunately, engravings, a very common type, often have large numbers of not-quite-horizontal lines. 

This results in bad thumbnailing at times. For example:

http://upload.wikimedia.org/wikipedia/commons/thumb/1/16/Rajpoots_2.png/310px-Rajpoots_2.png 

is not a very good thumbnail of http://upload.wikimedia.org/wikipedia/commons/1/16/Rajpoots_2.png

Is there anything that can be done?
Comment 1 Adam Cuerden 2010-08-21 12:17:48 UTC
Note that image may be a good test: MOST thumbnails have some sort of Moiré in the sky.
Comment 2 Derk-Jan Hartman 2010-08-21 12:36:29 UTC
Sure, if we start scaling each image by hand, picking the best algorithm.

All is a trade off between speed, quality and sharpness. And the bigger the image, the worse the effects can be of course.

See also: http://www.imagemagick.org/Usage/resize/#filter

Specifically: http://www.imagemagick.org/Usage/resize/#best_filter
Comment 3 Adam Cuerden 2010-08-28 10:15:26 UTC
Ah, well. Figured it was going to be something like that. ~~~~
Comment 4 Derk-Jan Hartman 2010-09-23 18:56:20 UTC
http://commons.wikimedia.org/wiki/File:Rajpoots_2-scaled.tif

Another example for people who will want to work on this and test scaling routines.
Comment 5 Brion Vibber 2011-09-15 22:55:29 UTC
Created attachment 9065 [details]
Sample scale-downs using ImageMagick & gimp

Adding a Gaussian blur on the original image before scaling seems to work wonders for this engraving; a 10x10 blur in Gimp for 310px or a 2x2 blur for 1600px both come out looking fairly smooth.

Blurring may however be relatively slow, especially on large images; it's probably not the best idea to turn it on as a default.


However.... I notice I actually get very good results using ImageMagick's '-resize' mode instead of '-thumbnail'. By default -resize applies a Mitchell filter; I can also apply '-filter Gaussian' which looks not quite as sharp.

The -filter option seems to be ignored by -thumbnail; or if it is applied it looks like it happens after a much more primitive resampling which'll be what gives us the heavy moire:

http://www.imagemagick.org/Usage/resize/#thumbnail


Of course part of the reason we use -thumbnail is probably because it's fast because it doesn't do all that filtering at full resolution. :P

Being able to flip particular images into the slower, more filtered scaling may actually be useful -- I suspect a simple on/off will be sufficient. But I don't know what performance impact it'll have; very large source images with high contrast are the target group, but very large source images are the exact ones that are slow and use lots of memory to resize. :(
Comment 6 Brion Vibber 2011-11-30 15:47:36 UTC
Notes from VIPS scaler test on this image:
http://lists.wikimedia.org/pipermail/wikitech-l/2011-November/056705.html
Comment 7 Tim Starling 2011-12-01 13:12:22 UTC
Created attachment 9589 [details]
Some frequency spectra

A comparison showing the issue in the frequency domain. 

The left image is the frequency spectrum of the source (VIPS im_fwfft + im_scaleps). Note the strong peaks on the X and Y axes representing the engraving pattern. 

The middle image has a 10px block average applied, like what VIPS im_shrink uses. Note the notches in the response which suppress part of the engraving pattern. 

The right image used a 10px radius Gaussian filter like what Brion used in one of his comparison images. Note the circular symmetry in the central area and rapid falloff out of the pass band.

If you're reducing the image far enough that the engraving pattern will generate Moire fringes, you need to use a filter which will strongly attenuate the part of the frequency spectrum where the engraving pattern is located.
Comment 8 Bawolff (Brian Wolff) 2013-09-27 18:10:34 UTC
Interestingly enough, vips appears to give better results for that test case - https://test.wikipedia.org/wiki/Special:VipsTest?file=Rajpoots_2.png&width=640&sharpen=0

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links