RE: Artifacts when drawing scaled bitmaps (via gp:draw-image)
Hello again David,
Inspired by your last post I've been doing some research into this (actually rather fascinating) topic, and came across a nice little library called FreeImage (http://freeimage.sourceforge.net/). Its rescaling function offers a range of filter options (box, bicubic, Catmull-Rom, etc.), and I've been experimenting with it through the FLI. My initial tests have given some very pleasing results, and I'm confident that I can satisfactorily resolve this issue now. Many thanks again, David, for your helpful suggestions.
Of course I'm doing all this via an external library (actually C++), but it might be something I'd want to implement myself. So if you don't mind me asking, do you do this kind of thing entirely in Lisp or go through the FLI?
Regards,
Chris
CC: lisp-hug@lispworks.com
From: dbm@refined-audiometrics.com
Subject: Re: Artifacts when drawing scaled bitmaps (via gp:draw-image)
Date: Thu, 6 Jan 2011 11:04:43 -0700
To: relativeflux@hotmail.co.uk
Hello Chris,
I didn't mean to scare you off... As with so much of computer graphics, most of what you see is "smoke and mirrors". If you can carefully restrict the range of variations you wish to see, you could easily come up with a fast, inexpensive, method for shrinking images. For example, 2:1 or 3:1. The difficulties mostly arise from having to be open to all possible scalings.
But, for example, if you restricted the shrinkage to a factor of 3, then you can easily compute the low-pass filtered image as a fast convolution with a 1-2-1 kernel:
#2A((1 2 1) (2 4 2) (1 2 1))
And since you will be resampling every 3rd pixel in both rows and columns, you really only need to take every destination pixel, find which exact pixel in the source corresponds to it, then perform the convolution sum over the source pixels under the kernel centered at that source pixel, and record that sum as your new destination pixel. You might want to rescale the filtered value to account for the summation growth. Depends on what your pixels represent.
For color images, you need to do this for every color plane.
By restricting the options we are able to arrive at a very cheap, fast, solution.
The full-blown solution, for arbitrary shrinkage factors is more involved. It probably requires a 2-D FFT for low-pass filtering, taking care of edge effects since the FFT is a circular convolution, and then using bilinear interpolation in the destination to source mappings to decide what value to use in the destination bitmap.
Dr. David McClain
Chief Technical Officer
Refined Audiometrics Laboratory
4391 N. Camino Ferreo
Tucson, AZ 85750
phone: 1.520.390.3995