remove unwanted black pixels from binary image
Show older comments
I have a binary image of a zebra fish. im trying to segment the fish but im getting the unwanted black pixels from the image. Im attaching two images- one with unwanted black pixels and one without unwanted black pixels.
5 Comments
Turlough Hughes
on 24 Feb 2020
Can you provide the original image and code you used to get your binary image?
Adam Danz
on 26 Feb 2020
In response to the comment posted as a flag: I would like to delete this question.
If you're seeking free help and consultation in this forum, and you benefit from someone volunteering their time to help you, removing the content of the question is disprespectful and selfish. The majority of help that others find in this forum is from questions and answers that have already been asked and ansered. When you remove the content of your quesiton, the forum becomes less useful.
If an answer below helped you, thank the contributor by accepting it and|or voting up the answer. If it wasn't helpful and you found a better solution, provide it. If you'd rather get private consultation, there are plenty of fee-for-service sites out there.
Your question can't be deleted.
Guillaume
on 26 Feb 2020
To add to what Adam said, note that editing your question away is not going to help. Mathworks will restore it to its original state.
Rena Berman
on 14 May 2020
(Answers Dev) Restored edit
Adam Danz
on 14 May 2020
Copy of question
I have a binary image of a zebra fish. im trying to segment the fish but im getting the unwanted black pixels from the image. Im attaching two images- one with unwanted black pixels and one without unwanted black pixels.

Answers (1)
Subhadeep Koley
on 24 Feb 2020
It is difficult to fill the binary image exactly as you want but twaeking the various parameters of the function bwmorph we can go pretty close. Perform the following operations on your binary image.
b = bwmorph(b, 'close', Inf);
b = imfill(b,'holes');
se = strel('line', 8, 30);
b = imerode(b, se);
b = bwmorph(b, 'majority', Inf);
figure; imshow(b);
Categories
Find more on Image Segmentation 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!