I am at the moment trying to implement a contra harmonic filter,to remove the pepper noise from an image. But the implementation of it seems a bit incorrect, and I am not sure what is wrong.
void ContraHarmonic(Mat src, Mat dst, int kernel, double P)
{
cout << "got it" << endl;
Mat temp = src.clone();
//copyMakeBorder(temp,temp,kernel-1,kernel-1,kernel-1,kernel-1,BORDER_CONSTANT,Scalar(0,0,0));
for(int row = kernel/2; row < temp.rows - kernel/2-1; row++)
{
for(int col = kernel/2; col < temp.cols - kernel/2-1; col++)
{
double den=0,num=0;
for(int i = -(kernel/2); i <= (kernel/2) ; i++)
{
for(int j = -(kernel/2) ; j <= (kernel/2); j++)
{
den += pow(temp.at<float>(row+i,col+j),P);
num += pow(temp.at<float>(row+i,col+j),P+1);
}
}
dst.at<float>(row,col) = num/den;
}
}
dst.convertTo(dst,CV_8U);
}
The output i receive from it point at something being wrong with it.. I am not sure whether the implementation is incorrect, or the programming isn't done correctly. This is the output i receive.. Which point at something being wrong.
--Updated--
Updated with the answer provided and the image looks like this