MATLAB: Removal of noises at edges (2)

Image Processing ToolboxMATLABmorphologynoises

How can I get rid of the unwanted pixels circled in red in the image below?

Best Answer

Fill holes and then bwareafilt and then "and" the result with the original to get the holes back again.