My question might sound stupid but please understand i don't study in a university/college where a professor could give me decent help. I am self learning and its hardly been 3-4 months of coding for me. Hence i request patience from SO Users.
I am trying to code a simple filter function where i define a kernel
, a 3x3 2D Array. I create another matrix load
, where i would like to store the pixel values of my Image array. I face 2 Major problems. For the 1st problem i am completely confused and bewildered. I read this brilliant answer about How do I gaussian blur an image without using any in-built gaussian functions?, it mentions:
For pixel 11 you would need to load pixels 0, 1, 2, 10, 11, 12, 20, 21, 22.
you would then multiply pixel 0 by the upper left portion of the 3x3 blur filter. Pixel 1 by the top middle, pixel 2, pixel 3 by top right, pixel 10 by middle left and so on.
I would like to know for an IplImage
with 3 channels how do i store the corresponding pixels [as mentioned in the link above] in my load
matrix because what i am confused about is there are 3 values [R G B], so i am supposed to multiply what with what??
Also how to ensure that the Pixels do not go out of bounds? Since once we are near the edges of the image the pixel value might go out of bounds.
void filter(const IplImage *img)
{
unsigned char kernel[][3] = { 1, 2, 1,
2, 1, 2,
1, 2, 1 , };
unsigned char load[][3] = { 0 };
int rows=img->height,cols=img->width,row,col;
uchar* temp_ptr=0 ;
for( row = 0; row < rows; ++row)
{
for ( col = 0; col < cols; ++col)
{
CvPoint pt = {row,col};
temp_ptr = &((uchar*)(img->imageData + (img->widthStep*row)))[col*3];
}
}
}