Max function and datatype

asked 2013-10-15 08:56:32 -0600

GiulSDU gravatar image

updated 2013-10-15 09:07:56 -0600

berak gravatar image

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?

edit retag flag offensive close merge delete

Comments

1

why is the return value of your maxFilter() function an integer in the first place ? it's value can never exceed an uchar

berak gravatar imageberak ( 2013-10-15 09:12:58 -0600 )edit

because..the value of my image go from 0 to 255...so i thought an integer would be enough..

GiulSDU gravatar imageGiulSDU ( 2013-10-15 09:15:46 -0600 )edit