FPGA Intellectual Property
PCI Express*, Networking and Connectivity, Memory Interfaces, DSP IP, and Video IP

Average/Mean Filter

Altera_Forum
Honored Contributor II
1,800 Views

Hi, 

Can anyone provide me the HDL code for Average/Mean filter 

 

Thank you, 

 

-Amit
0 Kudos
7 Replies
Altera_Forum
Honored Contributor II
479 Views

Why not try writing it yourself? We can help you if you get stuck. You'll learn a lot more. 

 

Best Regards, 

Ola Bångdahl
0 Kudos
Altera_Forum
Honored Contributor II
479 Views

Hi, 

 

For (n) taps running average filter: 

1) design a delay line for (n) taps(shift register) 

2) put a subtractor at end of delay line(to subtract most recent input from oldest sample). 

3) use a feedback adder(integrator) on the subtractor output. Your filtered output is then the output of this integrator. 

 

Above recursive design only needs one subtractor and one adder and so is more resource efficient than having direct form for (n) additions.
0 Kudos
Altera_Forum
Honored Contributor II
479 Views

i believe the filter kaz is talking about is known as a cascaded integrator comb (CIC) filter if you want to do some more research on it. altera has a megacore that can help you design one. 

 

some additional specifications for your application would help. a simple averager could be the sum of 2 signals right shifted by 1 (or define the lsb as a fractional bit).
0 Kudos
Altera_Forum
Honored Contributor II
479 Views

Guys, 

I will be receiving 8bit of data as input. The very first 8bits will be my R(Red) component, 2nd 8bits my G component and 3rd 8bits my B component. 

Thus constituting my 1 pixel. 

Now say if my image size is 255x255. That means I will be receiving 255 Rs, 255 Gs and 255 Bs, thus completing my 1 row. 

Like wise when 3 rows get completed, I will have to calculate the Average by using 3x3 window. 

 

eg. 

 

R1_red1 R1_green1 R1_blue1 R1_red2 R1_green2 R1_blue2 R1_red3 ..  

 

R2_red1 R2_green1 R2_blue1 R2_red2 R2_green2 R2_blue2 R2_red3 ..  

 

R3_red1 R3_green1 R3_blue1 R3_red2 R3_green2 R3_blue2 R3_red3 ..  

 

Now, 

Avg = (R1_red1 + R1_red2 + R1_red3 +  

R2_red1 + R2_red2 + R2_red3 +  

R3_red1 + R3_red2 + R3_red3 ) / 9 

 

like wise for green and blue also. 

now, R2_red2 will be replaced by this Avg. and my this 3x3 window will move right to again calculte for same R1,R2 and R3 rows and for red2, red3 and red4 this time. 

when complete row is finished (till width of the pic) my 3x3 window will move 1 row down i.e calculation will be performed on R2, R3 and R4. 

 

This design I have to make it for Cyclone device and I have a deadline of 2 days.
0 Kudos
Altera_Forum
Honored Contributor II
479 Views

The 2D Median Filter from the Altera video and image processing suite basically can achieve the said function. The arithmetic operation itself is almost easy, but the data organisation isn't to my opinion. There are various possible variants, e. g. operating on a frame buffer or performing a stream conversion with only line buffers. You also didn't tell, if you intend a scaling operation with less output pixels or a filtering that keeps the image size.

0 Kudos
Altera_Forum
Honored Contributor II
479 Views

The Mega Cores from Altera video and image processing suite are not targeted for Cyclone device. They are for CycloneII and above. And I need to do it for Cyclone. 

Also, I don't require to do scaling operation. I will keep the image size.
0 Kudos
Altera_Forum
Honored Contributor II
479 Views

in that case i would start searching around for 2d convolution HDL, and if there isn't much out there start looking for matlab or c code and porting to HDL. 

 

i am not sure averaging over each r, g, and b is going to give the best results. you might want to compare converting from RGB to HSI and filtering the h, s, and i components or just the i component (and converting back to RGB) to filtering the individual RGB channels using matlab or c.
0 Kudos
Reply