Ask Your Question
0

Trimap image use in OpenCV

asked 2017-01-21 03:18:29 -0600

RossFe92 gravatar image

Hello, I found The Oxford-IIIT Pet Dataset, which contains images of dogs and cats. For each image has a pixel level foreground-background segmentation (trimap) image. Searching the internet, I saw that trimap is an image with three colors (one for the background, one for the foreground and one for the not-classified region), but here the image is all black. It's a mistake or is correct so too? But above all I want to know if and how you can use it to get, given a normal image, a new image with the cat or dog on a black background. Thanks.

edit retag flag offensive close merge delete

Comments

"but here the image is all black." -- wait, you'll have to explain that.

is it a problem of importing / visualizing those images ?

could you add an example image, and the code you're using ?

berak gravatar imageberak ( 2017-01-21 03:28:43 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-01-21 03:36:29 -0600

berak gravatar image

updated 2017-01-21 04:21:05 -0600

assuming, those trimaps contain a single channel of [0,1,2] values, it's no wonder, that it looks "all black".

to visualize them, you could try to increase the contrast, e.g. like:

imshow("trimap", trimap*80);

to mask out the backgound, using those trimaps, you would build a mask, using the resp. label (let's assume, 0 for bg):

Mat mask = (trimap==0);
image.setTo(Scalar::all(0), mask); // paint black, where the mask is "on".
edit flag offensive delete link more

Comments

How then I can use it to get a picture with the cat or dog on a black background?

RossFe92 gravatar imageRossFe92 ( 2017-01-21 04:18:04 -0600 )edit

^^ please see edit

berak gravatar imageberak ( 2017-01-21 04:21:50 -0600 )edit

Thanks for your answer. I've tried but I've this error:

OpenCV Error: Assertion failed (mask.empty() || (mask.type() == CV_8U && size == mask.size)) in setTo, file /opt/OpenCV/opencv-3.0.0/modules/core/src/copy.cpp, line 473
terminate called after throwing an instance of 'cv::Exception'
  what():  /opt/OpenCV/opencv-3.0.0/modules/core/src/copy.cpp:473: error: (-215) mask.empty() || (mask.type() == CV_8U && size == mask.size) in function setTo
RossFe92 gravatar imageRossFe92 ( 2017-01-21 04:43:22 -0600 )edit

either your trimap is empty(), or it does not have the same size as image.

berak gravatar imageberak ( 2017-01-21 04:50:03 -0600 )edit

Unfortunately neither the image, the trimap and mask are empty and all three have the same size (600x400)...

RossFe92 gravatar imageRossFe92 ( 2017-01-21 04:56:58 -0600 )edit

trimaps/ Trimap annotations for every image in the dataset

    Pixel Annotations:

1: Foreground

2:Background

3: Not classified

read readme in annotations

LBerger gravatar imageLBerger ( 2017-01-21 05:08:49 -0600 )edit

I had already read, how should I edit the berak's answer then?

RossFe92 gravatar imageRossFe92 ( 2017-01-21 05:16:31 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-01-21 03:18:29 -0600

Seen: 2,333 times

Last updated: Jan 21 '17