Max function and datatype
I am tryong to compute the max of a certain image, my function is:
int maxFilter(Mat img,int x,int y)
{
int max=0;
for (int j = x-1; j <= x+ 1; j++)
{
uchar* data = img.ptr<uchar>(j);
for(int i =y-1 ; i <= y+1; i++)
{
if (data[i]>=max)
max=data[i];
}
}
return max;
}
the problem is that i use the following code to access pixel: Mat padded; //loading the picture here//
for(int j = 1; j < padded.rows-1; j++)
{
uchar* data = padded.ptr<uchar>(j);
for(int i = 1; i < padded.cols-1; i++)
{
data[i]=maxFilter(padded,j,i);
}
}
the Image is a Mat with an uchar pointer, but the return value of my function is an integer, how can i fix it? do you know any type assignment tutorial?
why is the return value of your maxFilter() function an integer in the first place ? it's value can never exceed an uchar
because..the value of my image go from 0 to 255...so i thought an integer would be enough..