Identifying and Binarizing Iron Filings in Low Resolution Images

I’m working on a project to identify and binarize iron filings (the elongated and clustered particles) in images, but I’m having trouble getting good results, especially with the low resolution of around 300x600 pixels. Many of the approaches I’ve tried produce strange outcomes at this resolution.

Here are some of the methods I’ve attempted so far.

img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cv2.imshow('gray', img)

clache = cv2.createCLAHE()
img = clache.apply(img)
# img = cv2.equalizeHist(img)
cv2.imshow('equalize', img)

img[img < 200] = 0
cv2.imshow('setzero', img)

kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (5,5))
img = cv2.morphologyEx(img, cv2.MORPH_TOPHAT, kernel)
cv2.imshow('tophat', img)

t, img = cv2.threshold(img, 177, 255, cv2.THRESH_BINARY)
cv2.imshow('threshold', img)

img = cv2.dilate(img, np.ones((3,3), np.uint8))
# cv2.imshow('dilate', img)

img = remove_isolated_pixels(img, 75)
# cv2.imshow('rip', img)

kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (5,5))
img = cv2.morphologyEx(img, cv2.MORPH_ERODE, kernel)
cv2.imshow('erode', img)

I’m hoping someone can provide suggestions for better techniques. I can share more sample images if needed.

The challenges I’m facing include:

  1. Accurately segmenting the iron filings from the background at low resolution.
  2. Preserving the elongated shapes and clustered distributions of the filings.
  3. Handling variations in lighting, contrast, and noise levels across different images.

If anyone has experience with similar tasks or can recommend effective algorithms/techniques for this problem, I’d really appreciate your input. My goal is to robustly identify and binarize the iron filings for further analysis.

Thank you in advance for your advice!

I have a picture with some irregular shapes (I can share the picture). I want to separate these shapes from the background and make them look black and white (binary).

But I don’t know how to start.
I tried some basic methods like thresholding and edge detection, but the results were not good. The shapes did not separate cleanly.

Any tips, code examples or guidance would be very helpful. Please let me know if you need more details about my images.
圖片1