# Implementing a kernel convolution

Hi guys.. I am felling a bit stupid asking this question, but I can't seem to come around the issue. I am trying to implement a contra harmonic filter using the equation given here

http://masters.donntu.org/2007/kita/gett/library/eng.htm

But I seem to be stuck at implementing the Kernel part of the filter..

The way i've coded until now is using 4 for - loop , first two to interate through the image, and second two to iterate through the kernel..

```
Mat ContraHarmonic(Mat src, int kernel)
{
Mat output = src.clone();
for(int x = 0; x < src.rows; x++)
{
for(int y = 0; y < src.cols; y++)
{
for(int subX = 0; subX < kernel; subX++)
{
for(int subY = 0; subY < kernel ; subY++)
{
output.at<uchar>(x-1+subX,y-1+subY) = 255;
}
}
}
}
imshow("output",output);
waitKey(0);
return output;
}
```

I know that the formula isn't right at the moment.. But When run this piece of code.. I do not get an output.. I am bit unsure whether I am doing this right, or I am missing some thing.. How do i detect whether the kernel is within the image, and not partly outside?