How can imfill a objects when they are in the edges of main image?
Show older comments
hi,
I have Two rectangles 200X300 and 300X100 in the edges as shown below. I need to imfill in side the objects edge shape only. I have try use the regular imfill but doesn't work with me. Could you please help me??

4 Comments
KALYAN ACHARJYA
on 26 Nov 2019
Edited: KALYAN ACHARJYA
on 26 Nov 2019
How you generated this image? imfill the shape with .....????
Mohammed Alammar
on 26 Nov 2019
Edited: Mohammed Alammar
on 26 Nov 2019
KALYAN ACHARJYA
on 26 Nov 2019
Edited: KALYAN ACHARJYA
on 26 Nov 2019
Please share the complete code, which generates attached figure.
Mohammed Alammar
on 26 Nov 2019
Accepted Answer
More Answers (2)
KALYAN ACHARJYA
on 26 Nov 2019
Edited: KALYAN ACHARJYA
on 26 Nov 2019
0 votes
Its because of white area touches the border. Apply imclearborder on binary image, then only apply imfill
Turlough Hughes
on 26 Nov 2019
You could put a border on the image with value 1, then run the filter and remove the border to get original dimensions:
I=padarray(testiamge,[1 1],1,'both');
test=edge(I,'canny');
outputs = imfill(test,'holes');
outputs([1 end],:)=[]; outputs(:,[1 end])=[];
imshow(outputs)
Also, this might also be an option depending on your requirements:
outputs=~testimage;
Categories
Find more on Images in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!