Ask Your Question
0

using inpainting function

asked 2018-12-17 14:39:03 -0600

Allaye gravatar image

updated 2018-12-17 16:03:34 -0600

am having an image with a red line on it, the mask i created was not able to located the red line, can anyone help me the solution, i want to know how to specify the region of the image i want to concentrate on... thanks in advance

int main()

{

Mat img = imread("Lennared.jpg");

Mat mask, inpainted;

 //inRange(img, Scalar(0, 0, 250), Scalar(0, 0, 255),mask);

//mask = Mat::zeros(img.size(), img.type()); // creating a mask image 

mask = img.clone(); // cloning the same image and putting it into mask

 cvtColor(mask, mask, CV_RGB2GRAY);

threshold(mask, mask, 100 ,255, CV_THRESH_BINARY);

inpaint(img, mask, inpainted,3,CV_INPAINT_TELEA);

for (int key = 0; 27 != key; key = waitKey())

{
    switch (key)

    {

    case 'm': imshow("image mask", mask);

        break;

    case 'i': imshow("inpainted image", inpainted);

        break;

    default: imshow("original", img);

    }
}

return 0;

}

this is the image

image description

edit retag flag offensive close merge delete

Comments

there is an example here and without your code we cannot help you

LBerger gravatar imageLBerger ( 2018-12-17 15:38:47 -0600 )edit

can you take another look at the example code ? you cannot use your image as a mask, but have to manually specify (eg, by drawing with the mouse) regions in a black uchar image, where inpainting on the original should be applied.

berak gravatar imageberak ( 2018-12-18 00:06:50 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-12-20 15:39:06 -0600

Allaye gravatar image

updated 2018-12-20 16:06:22 -0600

Mat img = imread("Lennared.jpg");

Mat mask, inpainted;

cvtcolor(img,mask,CV_BRG2GRAY);

inrange(img, Scalar(10,10,200), Scalar(40,40,255),mask); // make sure your targeted color is between the range you stated

inpaint(img,mask, inpainted,3,CV_INPAINT_TELEA);

for( int key =0 ; 23 !-key; key=waitKey())
{
    switch (key)
{
   case 'm' : imshow("maskimage", mask)
break;
case 'i ': imshow("inpainted image", inpainted)
break;
default : imshow("original" img);


}


}
return 0;

since am i trying to detect the red color in the image, i have to pass the scalar value of the red color, that from a lower range to a higher range all inclusive... That should give you the perfect mask image for use in the inpaint function, hope this help everyone else ..

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-12-17 14:39:03 -0600

Seen: 381 times

Last updated: Dec 20 '18