fill inside a boundary

18 views (last 30 days)
azarm
azarm on 8 Jun 2011
Hello everyone,
i have two frames of images with time delay. i specified a boundary in first frame around an object. So i have the position of the boundary. I want to fill inside the boundary with values from the second frame. any idea?

Accepted Answer

Alex Taylor
Alex Taylor on 8 Jun 2011
Hi Azarm,
A good way to solve this problem will be to obtain a logical image that represents the boundaries of the first frame. Once you have this logical image, you can use logical indexing to fill the region inside the boundary with specified values.
a = rand(200);
% Create a logical image that defines a rectangular boundary.
mask = false(size(a));
mask(10:100,10:100) = true;
% Assign a fill value of 40 to all pixels within the boundary
a(mask) = 40;
figure, imagesc(a)
I'm not sure whether you have the Image Processing Toolbox. If you do, you might be interested in looking at the function poly2mask.
doc poly2mask
This function is useful in moving from X,Y definitions of boundaries to a logical image representation of the mask.
  2 Comments
azarm
azarm on 8 Jun 2011
tnx Alex,
poly2mask is what i need!
azarm
azarm on 15 Jun 2011
Hi,
there are more than one region (Boundary) in an image. so i make a loop over them and for each region, i fill inside with poly2mask. When i reach the last region (last count in the loop), poly2mask gives zero as result!!! any idea why it happens?!

Sign in to comment.

More Answers (1)

Sean de Wolski
Sean de Wolski on 8 Jun 2011
M = imfill(BoundaryImage,'holes'); %Assuming boundary is connected. Else use poly2mask
I1(M) = I2(M); %Set mask portion of first image to that of second.
If you don't want to fill the boundary itself:
M = xor(BoundaryImage,imfill(BoundaryImage,'holes'));

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!