How to identify a resampling filter

Discuss digital image processing techniques and algorithms. We encourage its application to ImageMagick but you can discuss any software solutions here.
Post Reply
Jason S
Posts: 103
Joined: 2010-12-14T19:42:12-07:00
Authentication code: 8675308

How to identify a resampling filter

Post by Jason S »

I'm interested in evaluating applications to figure out what image scaling algorithms they use, and how well those algorithms are implemented. So, I'm working on a little utility to help do that. It uses strategically-designed source images that you resize, then use it to analyze.

In part, it does what the im_profile script does, but it can also do another kind of analysis that works better when downscaling. I think my demonstration page about web browsers gives a good overview.

I'm open to suggestions or comments. Is there a better way to do this? Can anyone help make sense of some of the results? For example, can you explain this graph?
Image
Is it an error, or is Safari using an algorithm that I'm not familiar with?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to identify a resampling filter

Post by anthony »

That looks like a partial implementation of a even ordered Lagrange filter.

I say partial as it should have a second discontinuity at a distance of 1.5 from origin.

See Lagrange Filters
http://www.imagemagick.org/Usage/resize/#lagrange

Sorry about the weirdness that appears in the graphs of even ordered lagrange functions, Gnuplot seems to get confused, and I have been unable to get it to draw the graph correctly.

this is the code I use to extract some graphing data from ImageMagick. (Lagrange order 4 needs a support value of 2.5

Code: Select all

filter=Lagrange
support=2.5
convert -define filter:verbose=1 -define filter:support=$support -filter "$filter" null: -resize 2 null: > filter.dat

Note as you say you are generating this graph by resizing special test images, then there is a distinct possibility the graph is only rough estimate of the actual function. For example here is a triangle filter of a single pixel row image

Code: Select all

   convert xc: -bordercolor black -border 2x0 pixel_5.gif
  convert pixel_5.gif  -filter triangle -resize 300x  pixel_triangle.gif
 im_profile pixel_triangle.png plot_triangle.gif
 
Image
Image

Or for a guassian image with a support cut off of 1.5

Code: Select all

  convert pattern:gray5 -crop 5x1+0+3 +repage pixel_5.gif
  convert pixel_5.gif  -filter gaussian -define filter:support=1.25 \
          -resize 300x  pixel_gaussian.png
  im_profile pixel_gaussian.png plot_gaussian.gif
Image
The four 'jiggles' happen as individual pixels (black and white) enter and leave the filters support region.

If you repeat the above with a support of 1.5 the two top 'jiggles' merge and cancle each other out (black pixel enters while another black pixel leaves support region).

This 'cancellation' effect may be why the second discontinuity is not present in your graph. But that my own tests don't show it. I don't know enough about how you generate your graph.
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: How to identify a resampling filter

Post by anthony »

After having a look at your web site. You can see that most of the browsers use the very very simplistic bilinear interpolation (equivelent to triangle resize filter) for image display.

The stepping effects is caused by integer rounding effects' to limit the number of colors being generated (posterization, or multi-level thresholding) This may also be a limitation of your display! Some of the results also suggest the programmers did not care much about how this was done, but simply let it happen, causing a slight 'quantum shift' in the color.

Of course for larger resizes of images interpolation starts to alias badly, and thus needs a more proper resize function such as a windowed Sinc or approximation Without comparing actual numbers (relative peak values for example) which filter Mitchell, Cubic, Lagrange with odd order, etc is difficult to figure out. Most likely it is a common one.

The odd graph may actually even be a bug! But one that produces fairly reasonable results.

WARNING: Cubic is not actually one specific filter. It is a very very large family of filters, containing may sub-familys (Keys, Cardinal, B-spline) as well as specific well known filters, (Hermite, Catrom, Mitchell-Netravali, Spline). Be more specific than simply saying "Cubic".

Read the section on resize filters. And me know what you think. Be more precise on your page about exactly what you are doing to test browsers, and getting results.

Also remember display characteristics (such as sRGB colorspace handling), may also effect results for non-pure bitmap images, as resizing should be performed in linear RGB mode but displayed using sRGB or Gamma correction. Many programs do not do this!

See Human Color Perception
http://www.imagemagick.org/Usage/color_ ... perception
And Resize with Colorspace Correction
http://www.imagemagick.org/Usage/resize ... colorspace
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Jason S
Posts: 103
Joined: 2010-12-14T19:42:12-07:00
Authentication code: 8675308

Re: How to identify a resampling filter

Post by Jason S »

Oh, I definitely know about most of the things you're talking about. (Lagrange filters are an exception, maybe -- I know what they look like, but don't know the theory.)

There are indeed a lot of ways to get tripped up. I've found many of them by accident :).

I do plan to make some sort of a tutorial about how to use ResampleScope, and how to interpret the results. But if possible, I first want to make sure I'm not overlooking any really obvious issues, or completely reinventing the wheel.

I know this isn't very detailed, but here's how I tested the web browsers: Run "./rscope -gen", which creates an HTML file and some image files. View the HTML file in the browser, take screenshots, extract the images and save them to PNG files.

The utility is limited to analyzing fairly simple algorithms, but that's usually good enough. So far I haven't even had a need to add a way to compensate for gamma correction, though that could easily be done. If I end up with a generally smooth graph, whose integral is about 1.0, I'm inclined to think the analysis is correct.

I guess I'm mostly just testing the water here. I hope this utility will result in some bugs being reported and fixed, even though it's not always obvious whether something is a bug. Incidentally, I analyzed most of ImageMagick's filters, and found no problems at all.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to identify a resampling filter

Post by anthony »

Jason S wrote:Incidentally, I analyzed most of ImageMagick's filters, and found no problems at all.
That is good to know. It is very easy to make mistakes, and went through great pains to try and insure it was working correctly. I needed to as the filters are also at the core of the 'distort' operator using in a 1-pass cylindrical resampling.

Actually when I did look into the code I found that 'Blackman' filter which is a rather popular Windowed-Sinc filter (and others) was being used directly as a filter and not to Window the Sinc operator at all! That was a major mistake, which I am happy to say I fixed, while adding many more controls, and expanding the range of filters that was available.


After this Professor Nicholas Robidoux took things a step further, and with his help I was able to finally find the bug that was the source of a great deal of blurring by the distort operator (a single sign '+' instead of '-', Arrgghhh)

Nicholas when on to created single function polynomial functions to replace Sinc and Jinc which is now used in IM (along side the original trigonometric version) and is now involved with designing filters that feature smooth transitions from down-sampling Sinc type filters to completely different Up-Sampling Interpolative filters. Something that is important in image distortions where you can transition between them, across the same image.

Perhaps that is the key. It seems especially strange that this odd function modifies itself based on the scale factor applied. Could it be some type of filter that changes with the scaling factor that is being applied?
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply