Re: Filtering kernel width
- From: News Reader <no@xxxxxxxx>
- Date: Thu, 14 May 2009 17:16:45 +0200
mike3 schrieb:
On May 13, 5:33 am, News Reader <n...@xxxxxxxx> wrote:mike3 schrieb:
On May 13, 1:34 am, Lorenzo Gatti <ga...@xxxxxxxxx> wrote:Perhaps this will help youOn 13 Mag, 03:54, mike3 <mike4...@xxxxxxxxx> wrote:> Hi.But I thought the wider you make the "hump", the more "blurred" theI was wondering: in order to do antialiasing with a windowing functionAs large as you can afford to use. A perfect lowpass filter (with a
(see the thread I posted here earlier), how wide should the window be,
anyway?
bandwidth that depends on the desired resampling ratio) has a sinc
impulse response with infinite "tails"; it can only be implemented
exactly for periodic signals (the coefficients fold together).
Multiplying the ideal impulse response by a suitable windowing
function leaves a realizable filter of finite size: a larger window
gives a closer approximation, while different windowing functions give
different linear distortions.
picture
becomes when it is convoluted with the function as more pixels
contribute
to the average with bigger weights.
Well I didn't see a problem with performing the convolution, theAnd how do you apply it to a 2-dimensional picture, when it'sNo, you can perform filtering and convolution in any number of
a fundamentally 1-dimensional function?
dimensions. Read other textbooks.
question
was the suitable generalization of the windowing function itself. How
does one generalize, for example, Lanczos or Hamming windows to 2-dim?
http://www-sigproc.eng.cam.ac.uk/~jl/imageproc/4F8imageprocessing08_h...
Hmm. However it doesn't seem to really explain how many pixels you
should stick
under the central "hump". And what happens when you use say a more-
than-one-lobe
Lanczos filter that has negative values? Won't convolution with that
yield pixels
having negative color? What do you do with that?
<cite>"However it doesn't seem to really explain how many pixels you should stick under the central "hump""
Hey be careful here! You do NOT stick pixels under the central hump. What you do is to clamp the function, but you evaluate the function at integral values! E.g. you spread the gaussian function by using a larger sigma and NOT by putting more pixels under a sigma=1 gaussian!!!
Jup, negative Pixel values could happen in some cases. The way to go there is e.g. clipping at [0,1] resp. [0,255]. However, look at a filter
function. Do you see the maximum value? It's located at the center pixel and in most cases it's significantly larger than the rest of the function. In the end the sum of the wheighted pixel values will fall in [0,1] or [0,255] again.
Then 1D->2D. In many cases you can go from 1D to 2D (discrete) simply by a matrix multiplication. Assume a 1D binomial (not normalized) kernel with 3 entries:
B := [1 2 1]
Multiply it from the left by B^T and get
[1 2 1]
[2 4 2]
[1 2 1]
which is the 2D kernel (not normalized). However, a 1D convolution in one direction followed by a 1D convolution in the other direction will do the same job, will be easier to implement, and will be much faster!
Still cope with the window size?
Here the 2D Version for arbitrar(il:)y odd sizes:
int iImgWidth, iImageHeight, iKernelSize;
int iKS2 = iKernelSize / 2;
// for the outer loops you could use some slightly
// more sophisticated border handling ;)
for (int i=iKS2; i<iImgWidth-iKS2; i++) {
for (int j=iKS2; j<iImgHeight-iKS2; j++) {
float fAccu = 0;
for (int u=-iKS2; u<=iKS2; u++) {
for (int v=-iKS2; v<=iKS2; v++) {
fAccu += kernel[u+iKS2][v+iKS2]*image[i+u][j+v];
}}}}
Now simply implement it and use a single constant for your first test kernel (be it 1D or 2D), so you have a gold standard to compare with.
And don't forget to NORMALIZE!!!
Btw. ask yourself:
When I shrink an image by a factor of 2 should I use information from 100 pixels away, and when I shrink by a factor of 100 can a 2 pixel neighbourhood be large enough?
If you answer both questions with "NO" you're pointing in the right direction ...
Best
-- NR
.
- Follow-Ups:
- Re: Filtering kernel width
- From: mike3
- Re: Filtering kernel width
- From: Kaba
- Re: Filtering kernel width
- References:
- Filtering kernel width
- From: mike3
- Re: Filtering kernel width
- From: Lorenzo Gatti
- Re: Filtering kernel width
- From: mike3
- Re: Filtering kernel width
- From: News Reader
- Re: Filtering kernel width
- From: mike3
- Filtering kernel width
- Prev by Date: i dare you raytrace
- Next by Date: Re: Filtering kernel width
- Previous by thread: Re: Filtering kernel width
- Next by thread: Re: Filtering kernel width
- Index(es):
Relevant Pages
|