# Discard circular/blob like structures from image

I have a binary image that looks like this:

And I would like to get rid off all the small structures and just keep what's on red:

Image erosion is an option that works well to remove the very small groups of pixels without affecting the red regions. Is there any other method that can be applied to keep only the elongated structures on my image?

You can calculate the area of each connected area in your image. Then, you throw away the smaller areas and only keep the biggest. See this example Python code:

import skimage.io as io
import numpy as np

from skimage.measure import regionprops, label
from skimage.color import label2rgb

bw = I[:,:,0]

bigger = np.zeros_like(bw)
labels = label(bw)

for R in regionprops(labels):
if R.area > 500:
# draw the region (I'm sure there's a more efficient way of doing it)
for c in R.coords:
bigger[c[0], c[1]] = 1

plt.imshow(bigger)


You can play around with the area threshold, e.g. by calculating a histogram of all areas and choosing the 3 biggest etc. And, you need to define the neighborhood of a pixel to belong to a connected region. In my case, it uses 8-neighborhood (i.e. if two pixels are connected at a corner, they belong to the same region). This is up to your application.

Additionally, you might throw away regions based on other criteria. E.g. if you want to throw away "circular" structures, you might throw regions away, where the area and perimeter are close to pi for example. Or, you look at the extent or orientation or whatever.