Ask Your Question
0

Mat ROI boundary issue

asked 2015-12-11 00:56:47 -0600

Nbb gravatar image

updated 2015-12-11 04:36:11 -0600

Hello forum,

Given an image of size 100x100, I would like to set a region of size 3x3 to zero. I receive an error when the mid point is designated at (0,0) or the boundary. Can anyone help me on this ? Thanksimage description

Mat image = imread("box.jpg");

Point center = Point(0,0);

Point tl = center - Point(1,1);
Point br = center + Point (1,1);

Rect roi = Rect(tl, br);
Mat image_roi = image(roi);
image_roi.setTo(0);

I know it is an error because tl = (-1,-1). What should i include to ensure that the rectangle does not go out of bounds when center = (0,0) ie. roi = Rect(Point(0,0), Point (1,1))

or when center is at the boundary. How does the filter/convolution function in opencv work without going out of bounds ?

edit retag flag offensive close merge delete

Comments

Unless you provide any code...

LorenaGdL gravatar imageLorenaGdL ( 2015-12-11 02:46:34 -0600 )edit

I have added the code

Nbb gravatar imageNbb ( 2015-12-11 04:36:47 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2015-12-11 04:48:24 -0600

LorenaGdL gravatar image

copyMakeBorder() is the answer. You can add surrounding borders for your picture. In this case, as your "kernel" is 3x3, adding a 2pixel-border would do the trick (at most 2 pixels can be outside the picture). After processing the image, you can crop the extra border to get the image to its original size

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-12-11 00:56:47 -0600

Seen: 780 times

Last updated: Dec 11 '15