AncientBrit wrote:>Gary
The problem I have is that my maths is useless so any decimation or interpolation I carry out is largely by trial and error.
I would be interested in a general algorithm for low pass filtering (decimating) when I am downsampling a web cam image.
Taking a practical example with the web cam, I take a pixel, give it an arithmetic weight of say 3 and add in nearby pixels each with a weighting of 1.
Sum the whole lot and divide by 7.
This certainly gives me some form of average but I would like to refine the technique.
Any pointers, suggested reading etc ("Filters for those with limited Maths" etc) greatly appreciated.
Kind Regards,
Graham
Aah but thats what I mean, are you down sampling for image resizing or down sampling for conversion into an NBTV audio stream?, surprisingly there is a difference in approach.
If image resizing, the three main approaches I use are nearest pixel (more or less your averaging approach), bilinear, and bicubic - although recently I have become interested in Lanczos which is a windowed sinc (not sync!) approach, and, of course, there are many other filters as well.
The basic difference in the three I mention is the trade-off between the reduction in pixellation and the amount of blurring.
Now, the question is, do you want to re-invent the wheel and code up one or all of these yourself (not particularly difficult) or use a freely available library? I recommend the latter because you get a lot of additional functionality as well, but if you are doing it as a purely intellectual exercise then maybe you would prefer to do your own, in any case these libraries include source code so tend to be a source of instruction as well. The other reason for doing your own is for speed, as I have done for The Big Picture!, but that is only because I wanted to do full screen video and that meant DirectX, or, in my case, assembly language.
If you decide on using a library you may need a DLL (all of the libraries I am familiar with, e.g. CxImage, are C++ oriented because that is what I use). If you wish to go with a library I am familiar with I could easily knock up a DLL for you so you can use it from VB if necessary.
If you want to code it yourself I can certainly provide you with algorithms.
On the other hand if we are talking about down sampling to audio then this becomes more of a standard sample rate conversion problem, indeed this has been my approach for creation and playback usually to and from 48 kHz and 44.1 kHz. In this case there is, as far as I am aware (as I have alluded to in another thread) no generic solution other than the usual sample rate conversion approach of interpolation/decimation and filtering. The problem is is that a filter has to be designed for each different resampling requirement. Also, it is always necessary to find an integer multiple of the two rates - not always easy.
Interpolation is merely adding zeroes between samples before FIR filtering to the original rates cut-off frequency, decimation is merely throwing away samples after FIR filtering. So the major task is to come up with a FIR filter. This I have discovered to be a bit of an art since you want the frequency restricting (anti-aliasing) performance of audio filters with smoothing (anti-ringing) performance of video filters. This becomes a compromise, and, as Klaas has shown me with his approach for he and Vic's colour system, can be relatively simply implemented with a 15 coefficient FIR filter designed by a Cosine windowed Sinc function, and which has a much slower roll-off than you would normally use for audio.
(It can also be done in a more technically correct way by using a very high order filter that incorporates brick wall roll-off with very low ripple but this runs into CPU performance problems when coded by hand - unless in assembly - and appears to be unnecessary).
In the case of the above mentioned colour system I resize the source video to 288 x 441 pixels using image cropping and resizing techniques, FIR filter to 10kHz, and decimate to 44.1kHz whilst serialising to audio.
I can elaborate on these methods if they relate to what you are wanting to do.
Cheers,
Gary