2
$\begingroup$

Initial image:

enter image description here


Target image:

enter image description here


My personal attempt was as follows, but I didn't completely clean it up. In the context, "image" refers to the initial image.

image = Import["https://i.sstatic.net/pBRwlXEf.png"];
grayImage = ColorConvert[image, "Grayscale"];
threshold = 0.5;
binaryImage = Binarize[grayImage, threshold];
smallObjectsRemoved = Opening[binaryImage, 2];
Show[image, Image[smallObjectsRemoved]]

enter image description here

$\endgroup$

2 Answers 2

4
$\begingroup$

You can use DeleteSmallComponents.

img = Import["https://i.sstatic.net/pBRwlXEf.png"];
ColorNegate@DeleteSmallComponents[ColorNegate@Binarize[img], 100]

enter image description here

$\endgroup$
1
  • $\begingroup$ This is maybe better: neg = ColorNegate@ image; ColorNegate@ ImageMultiply[neg, Dilation[DeleteSmallComponents@ Binarize@ neg, 1]] (boundaries of lines less affected according to ImageDifference[]). (+1) $\endgroup$
    – Michael E2
    Commented Aug 2 at 16:31
4
$\begingroup$

Another option is to select the smallest component by Circularity

img = Import["https://i.sstatic.net/pBRwlXEf.png"];
ColorNegate@
 SelectComponents[ColorNegate@Binarize@img, "Circularity", 1]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.