fill inside a boundary
조회 수: 19 (최근 30일)
이전 댓글 표시
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
채택된 답변
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.
추가 답변 (1개)
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'));
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!