Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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?

click to hide/show revision 2
retagged

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

berak gravatar image

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?