manatttta
manatttta

Reputation: 3124

OpenCV set pixels outside ROI as the nearest pixel value inside the ROI

I have an image with a non-rectangular ROI, defined by a binary mask image.

In OpenCV, how can I set the pixels OUTSIDE my ROI as the nearest pixel value INSIDE the ROI? Something similar to what is in cv::BORDER_REPLICATE, or something similar to what is done in cv::warp

Upvotes: 0

Views: 502

Answers (1)

herohuyongtao
herohuyongtao

Reputation: 50667

You can make use of cv::inpaint() by restoring the selected region region in an image using the region neighborhood.

In your case, that will be something like:

cv::inpaint(mat_input, 255 - roi, mat_output, inpaint_radius, cv::INPAINT_NS);

Upvotes: 1

Related Questions