I've an input image (around 24 MP). Feeding such a large image to grabCut in OpenCV is time consuming, so first I want to downscale the image then I want to upscale the mask. So, in grabCut function I'm downscaling the image as follows:
//Downsampling
double c_ratio = 0.0;
double r_ratio = 0.0;
double ratio = 0.0;
bool donwSampled = false;
if (img.cols > 800 || img.rows > 600){
c_ratio = img.cols/800.0;
r_ratio = img.rows/600.0;
ratio = (c_ratio > r_ratio)?r_ratio:c_ratio;
printf("downscaled by: %f\n", ratio);
fflush(stdout);
resize( img, img, Size( img.cols/ratio, img.rows/ratio ),0,0,INTER_LANCZOS4);
resize( mask, mask, Size( mask.cols/ratio, mask.rows/ratio ),0,0,INTER_LANCZOS4);
donwSampled = true;
}
And the end of this function I'm upscaling as follows:
//Upsampling
if(donwSampled){
resize( img, img, Size( img.cols*ratio, img.rows*ratio ));
resize( mask, mask, Size( mask.cols*ratio, mask.rows*ratio ));
}
The input mask is as follows:
The output is this:
As one can see in the output image the little area around the brush are marked wrong both in foreground and background selection.