Topic: Accuracy of resize filters

First, I think this is a great app. I keep going to it to do all sorts of things that mainstream picture processing apps just can't do (profile line, fourier transform, photometric intensity callibration).

But just now I'm wondering if the image resizing is working? My "acid test" is a zone plate image with a gamma of 2.2 (not quite sRGB but a lot closer than ignoring gamma altogether). Analyzer is the the only photo app I use that is capable of doing a "gamma correct" resize (which usually means shrink), the feature that brought me to it in fact - and the gamma part seems to work. I noticed more artifacting in pictures reduced by Analyzer than say Irfanview, and put this down to just the way it is when done properly, maybe from the camera's response. I generally aim to resize by factors of 2 or at least an integer multiple (eg 1/3).

But in recent days I've noticed that images reduced in Analyzer then expanded to their original size (eg 2:1 or 3:1) don't expand anywhere near as cleanly than if the intial shrink is done in Irfanview (Lancosz). Also by turning the display gamma down on the 50% scaled zone plates (to see the level envelope) shows that pretty much nothing except the straight nearest neighbour pixel resize works as expected. Wiener filters seem very soft and identical to each other, bicubic doesn't seem to filter out any HF at all, sinc does something even weirder. Few if any other image processing apps pass this test very well (and they don't even deal with gamma) so it's hard to compare and maybe just the way these filters work - but I do know for example that the Polyview library "sinc" resize does give a brick-wall cutoff (a square in the centre of the zone plate with everything around it filtered out). I'm not after that as I know frequency domain filtering isn't everything, but I am always looking for a really good way to shrink images with a minimum of information loss and visible aliasing.

A lot of this grew from discovering my (then) way favourite photo prog - Thumbsplus - was horribly broken in the image resize department. Despite using the Polyview library for most things (like jpeg save, which is really good), they seem to do their own completely broken thing for resizing. I questioned, I sent examples, I asked on their forums (newsgroups) - they ignored me and deleted my posts! They since fixed parts of it so it kind of works now, but it left me with a bit of a complex. Hence this ramble. I may have time for that, but not doing in-depth verification - so I was wondering if anybody else has noticed this?

Re: Accuracy of resize filters

Thank you for bringing this to my attention. I must admit that I never really thought about it as I have focused most on the upsampling algorithms where I think that the Wiener filtering methods are some of the best that exist.

The current reduce algorithm is fairly simple and something I did many years ago. For scaling 50%-100% it uses simple bilinear resampling, and below 50% it just computes the average of the pixels that are removed. This works fairly well for reducing by an integer factor as you say, but it will produce artefacts for other values. This is also true when the Wiener methods are selected because the Wiener filtering is only used when enlarging.
Do you know of any good reduce algorithms? I will definetely look at Lanczos if you say it works better. If it is not too complicated to implement I will include it in the next version.

Michael Vinther

> software developer <

3

Re: Accuracy of resize filters

Aha! That would be why then. I think it is a common thing - even universal maybe. For example Thumbsplus "resample" filters in jumps of factors of 2, ie 50%-100% get lowpass filtered by what I assumed was some unknown kernel to always 50% cutoff frequency, 25-49% to 25% etc. Of course reducing a photo to 50% gave a result identical to "nearest neighbour", they since included 50% in the 25-49% bracket which helped but still messy. I had been relying on Irfanview's Lancosz resize but it looks identical to your Wiener (that came out wrong!) so maybe I can't vouch for any particular method after all. All my recent experience is probably based on various bilinear approaches with proprietary tricks like sharpening after resize? A general lack of gamma-correct processing adds even more confusion.

But downsampling is all I ever want to do - reducing pictures for the web, for emails, including in reports etc. I rarely upsample any more, I guess digital camera photos are now so big, and moderately competent upsampling is built into pretty much every display device or software you run across these days. Only downsampling causes information loss and/or unrecoverable aliasing, so if anything that's the one that needs to be done right.

My background is (or was) in theoretical image processing, so I don't have any feel for how algorithms like bilinear behave. Lancosz is apparently very good, it's 'just' an FIR filter of a sinc function itself windowed with sinc, which sounds like it would be just as applicable to downsampling as upsampling. If a filter kernel is computed for each resampling size (eg 50% cutoff for 50% resize), then I expect it would work really well - would be great to see it implemented.

I could email you some examples of those zone plates if you want.

Re: Accuracy of resize filters

I'm afraid it is not of much use (i think you both know more about images then i do...) but perhaps a little information.
http://home.hccnet.nl/david.dirkse/math … esize.html a bitmap resize algorithm
http://www.americaswonderlands.com/digi … lation.htm Digital Photo Interpolation Review
http://graphics32.org/wiki/
http://freeimage.sourceforge.net/
http://www.cpr.demon.nl/prog_wega2.html a viewer with also 7 filters, this is what i use to (batch) make pictures smaller for use in a wiki or e-mail.

Re: Accuracy of resize filters

I have added support for Lanczos filtering based on this article on Wikipedia:
http://en.wikipedia.org/wiki/Lanczos_resampling
- though I am not sure it is entirely correct.

You can try it here in this beta:
http://meesoft.com/Analyzer/BETA/ImageAnalyzer.zip
It is quite slow in this first version so I might optimize it later. I think that if you set Image gamma to 1 it gives the same results as Irfan View.

I have also updated the cubic and sinc methods to support correct gamma handling.

Michael Vinther

> software developer <

6

Re: Accuracy of resize filters

Oops I missed these replies.

For some reason I can't access meesoft.com to get the beta?

I did a bit more experimentation, and it seems to confirm my recent discovery that very few photo processing apps do any form of real downsampling. I don't think IrfanView Lancosz works either (unless it's using a "Lancosz1" filter). For years I have just assumed that when an app says it's using a filter for downsampling that it actually is, because the need is stronger for downsampling (aliasing etc). Now I can understand why it is generally not done, but it's been a bit of an eye-opener.

This is based on the zone plate 'workflow' described above, where the downsized result is heavily gamma adjusted or just thresholded to bring out the 'envelope' of the frequency response, which should be a clearly visible square or circle extending halfway to the edge even if the processing isn't gamma-correct. So far only PolyView and XnView so far have given the correct result (but gamma incorrect). When pre then post corrected for gamma, some of the results from these working Lancosz filters are amazing. This new Analyzer beta might do the first "correct" image resize I've seen in modern times!

Here's my wish-list of image resize features of photo apps:
- Emphasis put on the real resampling based methods, with choice from the best filters (Lancosz 2 and 3 seem to be the most popular). Ideally with a variable frequency response because sometimes textbook bandlimiting doesn't look best, eg capturing the sparkle coming off fine bubbles - where no antialias filtering filtering at all (nearest neighbour) can look best. Also a choice of square (2 * 1D) and circular (2D) filter kernels.
- Most effort focussed on best looking downsize (decimation) results (web, email, digicam images into reports).
- Curve-correct, or at least gamma corrected processing. Most digicams compress the top end (whites) to prevent sudden white-outs and loss of colour (creating an "S" shaped gamma curve), so applying a straight gamma correction can make jaggies worse. Also sRGB is actually gamma 2.4 with a linear section at the low end, so some sort of support for curve mapping makes sense.
- At least 16 bit (ie 48 bit colour) processing with preservation of undershoots (negative values) and overshoots until final rendering to 8 bit. With the option to dither.
- Ability to lock resize to an integer multiple. Many photo apps let you put in 50% or something, but often they are slightly out (and 33% will never work), or resample with an inconsistent phase. Such integer resizes introduce minimum artifacts, are easier and faster to compute, and are more predictable (eg when resizing a graph with a 1-pixel grid it won't blur every 3rd line or something).
- Integration of rotation and resize to reduce processing steps that would each introduce artifacts.
- Fast or even real-time view, to allow experiments. Now that CPUs are capable of well in excess of 10 billion operations per sec, raw processing power shouldn't be the bottleneck (even if programming it is!).
- While I'm at it, some sort of jpeg save optimisation. Mentioned because it relates to any "region of interest" variable filtering that could be applied eg to the bubbles mentioned above; unfiltered image detail often looks ok with a lot of compresison noise added, while sharp edges on flat surfaces cause problems - so this is kind of related to filtering. At least the filtering always affects jpeg size, and size is usually the only reason for downsampling images these days.

Well, I think that should be enough for now!

Re: Accuracy of resize filters

Sorry, but the meesoft.com server is down. Apparently the company hosting it went bankrupt and now I am waiting to get the domain transfered to another host... Unfortunately I am not allowed to put files for download on the server hosting the forum.

IA now has Lanczos2 and Lanczos3 filters for resampling using square filters. One of them (don't remember which) gives the same result as IrFanView (when I set IA's gamma to 1). They work internally in floating point precision (32 bit per plane).

Michael Vinther

> software developer <

Re: Accuracy of resize filters

The download should be working again now.

Michael Vinther

> software developer <

Re: Accuracy of resize filters

Beautiful!

The beta tests out really well with my zone plate. It gives a similar result to downsizing with pre then post correcting for Gamma in Xnview, except without the loss in dark areas from it being in 8 bit. I still get nothing like I expect from Irfanview, perhaps I'm doing something wrong, or somehow using an old version (I did try updating it.)

I've noticed the beta does still struggle on integer ratio reduction (eg 50%) visible on a regular array of points (eg a white pixel every 4 H and V). At first I thought it was perfect, but that's because of the gamma-correct processing! Zoom it up and the you'll see the pixels spreading in different ways in different parts of the image. Most apps struggle with that and keeping the aspect ratio exact - probably because most image sizes can't be scaled down to nice integer values. Maybe they could be padded to a handy size first, something I should try with my test images. Anyway, this isn't really relevant for downsizing photos, only bitmap graphs and stuff for the web where you want the grid to look nice. For that a simple "average 2*2 pixels into 1" does a good job, but could be sharper.

Well I'd better get on with some work - many thanks for sorting out the downsize - I used it today to shink some photos for emailing, and the difference is quite noticeable.

Re: Accuracy of resize filters

Just a note on integer resizing: If you use the bilinear method it will replace each block of 2x2 pixels with their average in one pixel. With Lanczos the scaling is computed a bit differently which might explain the effect you see:
When scaling from e.g. a width of 1024 to 512 the position of the last pixel goes from 1023 to 511 because the first pixel is at position 0. This means that the internal pixel mapping factor is actually 511/1023 = 0.4995.

If you make your image with a white pixel every 4 H and V at 1023x1023 and resize it to 512x512 using Lanczos then you will get the result you expect because the internal scaling factor is 511/1022 = 0.5.

Tip: You can make IA generate such an image if you select File | New and set the parameters 1023, 1023, 8 bit grayscale, I(x,y) = ((x%4)+(y%4)=0)*255.

Michael Vinther

> software developer <

11

Re: Accuracy of resize filters

Wow, I didn't see the image creation function. Another example of the type of thing I mentioned in the first paragraph of my first post.

My way wasn't so tidy, taking a screenshot from this in freebasic...

screen 21

dim x as integer
dim y as integer

for x = 0 to 1279 step 4
    for y = 0 to 1023 step 4
        pset (x,y),15
    next
next

while inkey$="": wend

The 1023 -> 512 resize works, it is easy enough to paste an image into such an array to get it resized by exactly 50%. I suppose image size depends on whether you count the distance between samples (eg 1023-0=1023), or the total size including half a pixel on either side (1024) which would be the "size" if the image were tiled.

I did a little simulation (also in freebasic) to investigate what happens if the phase of the Lancosz filtering is altered so that new samples are computed from a kernel positioned at the centre of 2x2 blocks of pixels (like bilinear) rather than on top of some of the existing pixels. This does a better looking job at reducing pixel-wide grids on a graph, but still thickens the lines (though by an equal amount independent of where they are), and loses the efficiency advantages of the Lancosz kernels (which is otherwise full of 1s and 0s). I learnt a fair bit about Lancosz filters in the process... I also suspect this approach could cause overshoot problems (trying to interpolate between 2 full-brightness pixels implies there is an even higher peak between them, in a real downsampled/bandlimited image this situation can't occur, but when resizing "pre aliased" computer graphics it does).

Anyway, I have used IA's gamma correct Lancosz filters on quite a few images now and I'm continually pleased by the results, especially the difference it makes to "specular" highlights if that's the right word.

12

Re: Accuracy of resize filters

New, related question.

I'm just trying the batch processor, and don't know how to get the new Lancosz resize methods to work. I've tried variations on Resize(800,600,Lancosz) - and it just says "invalid resampling method". Maybe not implemented yet, but thought I'd ask!

Re: Accuracy of resize filters

It is not available until the release of the next version of IA which is hopefully within a few days.

Michael Vinther

> software developer <

14

Re: Accuracy of resize filters

I since realised batches are processed by a separate executable so my question was rather silly.

The new ver will be great - looking forward to it.

Re: Accuracy of resize filters

The batch processor has now been updated

Michael Vinther

> software developer <