low pass filter coefficients

asked 2016-02-06 02:16:29 -0600

updated 2016-02-06 02:17:04 -0600

In MATLAB, there is a command fir1 that generates the filter coefficients but how to calculate low pass filter's coefficients in OpenCV? I need to use a low pass filter with 50th order, hamming window and cutoff frequency = 0.00000000001. Also, I can't use filter2D command because I'm doing 1D filtering just like low pass filtering of an audio signal (example).

edit retag flag offensive close merge delete

Comments

1

just curious, what are you trying to do ? (1d arrays are a rare thing in opencv)

how would you apply that fir filter ?

given 20 coefs, for each 'pixel', it's probably just the dot product of the last 20 values with the coefs array ?

berak gravatar imageberak ( 2016-02-06 02:38:35 -0600 )edit

I'm actually working on the stabilization of panoramic videos. The code is actually first written in MATLAB and now, I need to convert that code into OpenCV first in order to proceed further and do all my work in OpenCV for using its provided files later.

Now, actually, in MATLAB "fir1" command designs a filter and returns the filter coefficients. For that command the above mentioned parameters were used. When it is designed, then the "filter" command is used to apply the low pass filter on the data. For filter command, I've to pass the rows in data as vector (1 row and multiple columns), numerator as filter coefficients and denominator as 1. This gives me the filtered data as an output of 'filter' command

Ayesha Siddique gravatar imageAyesha Siddique ( 2016-02-06 03:11:20 -0600 )edit

can you give a (smallish) example, so folks here can try to reproduce it ?

berak gravatar imageberak ( 2016-02-06 03:16:48 -0600 )edit

Its just like filtering 1D voice signal. The filter will slide over the 1 D data and we continue storing the data for each filtering effect.

For example, if I have to first design a low pass filter (using hamming window cutoff frequency and order = 5 or length =5+1=6) then the "filt" command will generate the following six filter coefficients: [0.02877 0.14311 0.32811 0.3281 0.14311 0.02877] Now, if the size of my data is 26x26 then I should append some zeros in the output matrix (number of appended zeros will be equal to the filter length) and now, I will get the size of output matrix as 26x(26+6) or 26x32.

Ayesha Siddique gravatar imageAyesha Siddique ( 2016-02-06 04:17:07 -0600 )edit

For applying this filter, there will be a loop starting from 1 to 26. Inside this loop, "filter" command will be used that will take filter co-efficient as nominator, 1 as denominator and one row of 26x26 data). In this way, each row of 26x26 data will be processed and in this way, each row of the 26x26 data will be processed. The output will be stored in the rows of the output matrix (26x32), one after the other row, on each iteration of this loop.

Ayesha Siddique gravatar imageAyesha Siddique ( 2016-02-06 04:20:09 -0600 )edit
1

I don't think there's a function to calculate the coefficients, but the functions to apply it are there. A SepFilter2D with the vertical set to a 1x1 matrix containing 1 would likely be the best way. You can use the anchor parameter cv::Point(0,0) to set it all the way to the side (I think that's right, you'd want to test it.)

Tetragramm gravatar imageTetragramm ( 2016-02-06 16:57:28 -0600 )edit
1

About filter coefficients there is a library here Do you want to filter your video in time or space?

LBerger gravatar imageLBerger ( 2016-02-07 05:18:58 -0600 )edit

@LBerger in time..

Ayesha Siddique gravatar imageAyesha Siddique ( 2016-02-07 11:46:09 -0600 )edit
1

I f size image is 200X200 pixels and your filter is of size 5 it means you will have to filter 40000 signal of size 5. I will do it like this (gray image):

VideoCapture vid;
for (int i=0;i<6;i++)
    vid.read(m[i]);
Mat mFiltered=Mat::zeros(size(m[0])
for (int i=0;i<6;i++)
    mFiltered += coeff[i]*m[i];

May be you shoulduse an IIR filter

LBerger gravatar imageLBerger ( 2016-02-07 12:07:54 -0600 )edit