fill inside a boundary

22 次查看(过去 30 天)
azarm
azarm 2011-6-8
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?

采纳的回答

Alex Taylor
Alex Taylor 2011-6-8
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 个评论
azarm
azarm 2011-6-8
tnx Alex,
poly2mask is what i need!
azarm
azarm 2011-6-15
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?!

请先登录,再进行评论。

更多回答(1 个)

Sean de Wolski
Sean de Wolski 2011-6-8
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!

Translated by