Showing results for 
Search instead for 
Did you mean: 
Honored Contributor I

How to Calculate Pixel Buffer Size for Varying Kernel Sizes

Hi everyone, 


I downloaded the Sobel filter design example for FPGA. This runs perfectly for a 3x3 kernel, however when i try to change this to a 5x5 or 7x7 kernel the output images are no longer as expected. I think I have pinpointed this problem to the pixel buffer in the code, shown below. 


// Pixel buffer of 2 rows and 3 extra pixels  

int pix_buff[2*COLS+3];  



// Initialise pixel buffer 

int count = -(2*COLS+3); 



while (count != iterations) { 

// Each cycle, shift a new pixel into the buffer. 

// Unrolling loop allows compiler to infer a shift register. 

# pragma unroll 


for (int i = 2*COLS+2; i > 0; --i) { 

pix_buff[i] = pix_buff[i - 1]; 

pix_buff[0] = count >= 0 ? frame_in[count] : 0; 



Basically, why is the buffer 2*COLS+3? I tried increasing this value, and the results vary significantly as I do so, which leads me to believe this is the issue at hand. have tried this with varying masks, and may I also note that the brightness tends to vary significantly with increases/decreases in the size of this buffer. 


If someone could show me how the 2*COLS+3 value was obtained, and how I may possibly calculate the necessary pixel buffer for 5x5 and 7x7 kernel sizes, so that I can begin to get meaningful results, that would be very helpful. I have attached two images to this thread, one with a pixel of buffer of approximately 10*COLS(dog772) which is much brighter and one for approximately 11*COLS(dog77) which seems to be closer to original image brightness. Note - these are supposed to be sharpening kernels of size 7x7, however I have similar issues with Sobel filter. 


Kind regards 

Tags (1)
0 Kudos
0 Replies