Ask Your Question

Resize boundaries of object

asked 2013-12-10 03:54:41 -0500

tobix10 gravatar image

updated 2013-12-10 10:05:33 -0500

I have object's bounding rect and contour. I want to use a contour as a mask to enlarge boundaries of this object to the size of bounding rect. In other words if object with green boundary pixels fitted in rectangle is on black background I want to make black pixels green.

How to do that?

image description

This is image after thresholding and applying findContours. I want to use this contour as a mask to extract leaf from original image and expand its boundaries to fill rectangle. I need to perform texture calculations and don't want to have black pixels around.

edit retag flag offensive close merge delete


Can you show your image ?

Haris gravatar imageHaris ( 2013-12-10 05:47:55 -0500 )edit

Ok. Post edited.

tobix10 gravatar imagetobix10 ( 2013-12-10 10:06:21 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2013-12-10 23:20:20 -0500

Haris gravatar image

Ok, so you already found the contour and bounding rectangle, and you need to make the contour as mask, for this draw contour with thickness=CV_FILLED to a new Mat and later copy the object from your source image using OpenCV Mat::copyTo(OutputArray m, InputArray mask), here you should use contour as mask .

And next thing is fill your rectangle excluding the object. For this draw the rectangle to a new Mat with thickness-CV_FILLED which will fill your rectangle with scalar you provided. Now perform bitwise_xor operation between previously created contour and newly created rectangle image. Using the resultant mask you can fill the area between your contour and rectangle.

edit flag offensive delete link more

Question Tools


Asked: 2013-12-10 03:54:41 -0500

Seen: 3,019 times

Last updated: Dec 10 '13