fill inside a boundary
19 views (last 30 days)
Show older comments
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?
0 Comments
Accepted Answer
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.
More Answers (1)
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'));
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!