I have been using minMaxLoc to compute the maximum value of the data obtained by running a laplacian filter over a grayscale image. My simple intention is to roughly estimate the sharpness. I encountered a confusing situation, which I have discussed here.
The max value obtained from the minMaxLoc function was like 1360, 1456,450 etc for a set of images.
Laplacian(src_gray,dst,ddepth,kernel_size,scale,delta,BORDER_DEFAULT);
minMaxLoc(dst,&min,&estimate,&minLoc,&maxLoc,noArray());//Estimate is the max value
Now I just tried to compute the average to have a better idea of the spread of the sharpness in the image. Note that DST is the Mat variable holding data from the Laplacian.
Size s = dst.size();
rows = s.height;
cols = s.width;
total = 0;
max = 0;
for(int k=0;k<rows;k++)
{
for(int l=0;l<cols;l++)
{
total = total + abs(dst.at<int>(k,l));
}
}
average = total/(rows*cols);
There are 2 baffling results I obtained. The average value I obtained, was not only greater than the max value obtained from minMaxLoc, but also was at times negative, when tried over a set of images. sample Average values where 22567, at times -25678.
The occurrence of negative was even more baffling as am using the abs() to get the absolute value of the laplacian results.
To get a proper understanding, I calculated the max value by myself and then the average values :
Size s = dst.size();
rows = s.height;
cols = s.width;
total = 0;
max = 0;
for(int k=0;k<rows;k++)
{
for(int l=0;l<cols;l++)
{
if(abs(dst.at<int>(k,l))>max)
{
max = abs(dst.at<int>(k,l));
}
total = total + abs(dst.at<int>(k,l));
}
}
average = total/(rows*cols);
surprisingly, I found the max value to be in 8 digits.
This is why I got confused. What is the max value given from the minMaxLoc function? And why is the abs() in total, not working and why am I getting -ve average values.?
Please forgive me if am missing something in the code, but this is slightly confusing me. Thanks for your help in advance.
I think you should use .at< uchar > instead of int (considering image to be grayscale) otherwise the value will overflow!