Sorry, this content is no longer available

Ask Your Question
0

Resize boundaries of object

asked Dec 10 '13

tobix10 gravatar image

updated Dec 10 '13

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.

Preview: (hide)

Comments

Can you show your image ?

Haris gravatar imageHaris (Dec 10 '13)edit

Ok. Post edited.

tobix10 gravatar imagetobix10 (Dec 10 '13)edit

1 answer

Sort by » oldest newest most voted
2

answered Dec 11 '13

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.

Preview: (hide)

Question Tools

Stats

Asked: Dec 10 '13

Seen: 3,764 times

Last updated: Dec 10 '13