1 | initial version |
Mat imcomplement(Mat I)
{
/*Result the complement of a given image*/
if(I.channels()==3)
{
for(int y = 0; y < I.rows; y++)
{
for ( int x = 0; x < I.cols; x++)
{
for(int i=0;i<3;i++)
I.at<Vec3b>(y,x)[i]=255-I.at<Vec3b>(y,x)[i];
}
}
}
else
{
for(int y = 0; y < I.rows; y++)
{
for ( int x = 0; x < I.cols; x++)
{
I.at<uchar>(y,x)=255-I.at<uchar>(y,x);
}
}
}
return I;
}