DSPRelated.com
Forums

How to decide good 2D filter size for image filtering?

Started by lucy November 26, 2004
Hi all,

I am trying to design a 2D low pass filter that filters some image.

I have decide the cutoff frequency to be 0.2, in terms of normalized 
frequency in [0, 0.5].

I decided to use Butterworth low pass filter and 7th order. I generate the 
frequency response using the "lowpassfilter" function as attached below, 
then by using "fwind1" I got an 2D impulse response of the filter with a 
11x11 hanning window applied.

So the 2D time domain impulse response of the filter is 11x11.

Now I have a question: it seems the decision of choosing 11x11 filter size 
is completely arbitary. After experimenting I found the smoothing effect is 
too local(i.e., smoothing only on 11x11 pixels is too small, maybe I need to 
involve more pixels such as 31x31... etc.)

My question is whether this choice of window size is completely arbitrary 
and hueristic, or it has some thoeritical derivation depending on some 
parameters of the filter...?

My problem is that I don't what should be the theoratical value of the 
window size...

Any thoughts?

--------------------------------------------
N=342;

H = lowpassfilter([N, N], 0.2, 7);
%The filter spectrum is normalized into [-0.5, 0.5]

h = fwind1(H,hanning(11));

--------------------------------------------

function f = lowpassfilter(sze, cutoff, n)

    if cutoff < 0 | cutoff > 0.5
 error('cutoff frequency must be between 0 and 0.5');
    end

    if rem(n,1) ~= 0 | n < 1
 error('n must be an integer >= 1');
    end

    %  Original code [rows, cols] = sze was not accepted by Matlab
    rows = sze(1);
    cols = sze(2);

    % X and Y matrices with ranges normalised to +/- 0.5
    x =  (ones(rows,1) * [1:cols]  - (fix(cols/2)+1))/cols;
    y =  ([1:rows]' * ones(1,cols) - (fix(rows/2)+1))/rows;

    radius = sqrt(x.^2 + y.^2);
        % A matrix with every pixel = radius relative to centre.

    %  Original code fftshifted the filter before output.  Since
    %  imFFT and imIFFT already shift, the output should remain 
low-centered.
    f = 1 ./ (1.0 + (radius ./ cutoff).^(2*n));   % The filter

--------------------------------------------



"lucy" <losemind@yahoo.com> wrote 

> I am trying to design a 2D low pass filter that filters some image. > > I have decide the cutoff frequency to be 0.2, in terms of normalized > frequency in [0, 0.5].
OK.
> I decided to use Butterworth low pass filter and 7th order. I generate the > frequency response using the "lowpassfilter" function as attached below, > then by using "fwind1" I got an 2D impulse response of the filter with a > 11x11 hanning window applied.
11 points seems VERY small... especially since the Butterworth filter is a) non-minimum phase and b) 7th order IIR.
> So the 2D time domain impulse response of the filter is 11x11. > > Now I have a question: it seems the decision of choosing 11x11 filter size > is completely arbitary. After experimenting I found the smoothing effect is > too local(i.e., smoothing only on 11x11 pixels is too small, maybe I need to > involve more pixels such as 31x31... etc.)
One way to decide your filter size is to figure out what size features you want to "smear".
> My question is whether this choice of window size is completely arbitrary > and hueristic, or it has some thoeritical derivation depending on some > parameters of the filter...?
There are many ways to choose the filter size. One is suggested above. Another is look at the filter response you want (Butterworth) and see how close the filter that fwind1 produces is to the originally-specified Butterworth response. Ciao, Peter K.