1

I am going through a median filter implemented in hls which can be found at https://cas.tudelft.nl/Education/courses/et4351/Median.pdf

This might be a silly question, but I am not able to understand how the first element of line buffer is getting filled. Here is the code

void top_median(pix_t in_pix[MAX_HEIGHT][MAX_WIDTH],
pix_t out_pix[MAX_HEIGHT][MAX_WIDTH],
short int height, short int width)
{
#pragma HLS INTERFACE ap_vld register port=width
#pragma HLS INTERFACE ap_vld register port=height
#pragma HLS INTERFACE ap_fifo depth=2 port=out_pix
#pragma HLS INTERFACE ap_fifo depth=2 port=in_pix
 short int r, c; //row and col index
 pix_t pix, med, window[KMED*KMED], pixel[KMED];
 static pix_t line_buffer[KMED][MAX_WIDTH];
#pragma HLS ARRAY_PARTITION variable=line_buffer complete dim=1
 L1:for(r = 0; r < height; r++) {
 #pragma HLS LOOP_TRIPCOUNT min=600 max=1080 avg=720
 L2:for(c = 0; c < width; c++)
 {
#pragma HLS LOOP_TRIPCOUNT min=800 max=1920 avg=1280
#pragma HLS PIPELINE II=1 
// Line Buffers fill
 for(int i = 0; i < KMED-1; i++)
 {
 line_buffer[i][c] = line_buffer[i+1][c];///<--- This part of the line buffer(How are the initial pixel values stored))
 pixel[i] = line_buffer[i][c];
 }
 pix = in_pix[r][c];
 pixel[KMED-1]=line_buffer[KMED-1][c]=pix;
 // sliding window
 for(int i = 0; i < KMED; i++)
 for(int j = 0; j < KMED-1; j++)
window[i*KMED+j] = window[i*KMED+j+1];
 for(int i = 0; i < KMED; i++)
 window[i*KMED+KMED-1] = pixel[i];
 // Median Filter
 med = median(window);
 if v( (r>=KMED-1)&&(r<height)&&
 (c>=KMED-1)&&(c<=width) )
 pix = med;
 else
 pix = 0;
 if(r>0 && c>0)
 // KKMED == 1 for 3x3 window
 // KKMED == 2 for 5x5 window
 out_pix[r-KKMED][c-KKMED] = pix;
 } // end of L2 loop
 } // end of L1 loop
} // end of function

Shouldn't the initial filling of the line buffer have a different logic like

linebuf[i][c]= in_pix[r][c];

I just dont understand how the values are being stored if you have logic like line_buffer[i][c] = line_buffer[i+1][c]; This makes sense once the line buffer is filled and you want to discard the oldest sample. Also I see that pixel value from the input is stored in

pix = in_pix[r][c];
 pixel[KMED-1]=line_buffer[KMED-1][c]=pix;

But this storage is happening after

 // Line Buffers fill
 for(int i = 0; i < KMED-1; i++)
 {
 line_buffer[i][c] = line_buffer[i+1][c];
 pixel[i] = line_buffer[i][c];
 }

What exactly is present in linebuf when r=0 and c=0

Can someone help me understand how exactly is this working? I have the same problem with understanding 2d convolution example in vivadohls.

Thanks in advance

0 Answers0