I am implementing a code to detect overlapping regions in a cell, as shown in the attachment. As you can see, the image is an overlapped version of two cells. My aim is to separate them. But I have got no clue whatsoever to do this. Can anyone help me

Dani AI

Generated

Good call by — watershed is often the right tool for separating touching cells, but it needs a marker-controlled pipeline to avoid oversegmentation. The practical workflow that usually works on brightfield/fluorescence cell images:

  1. Preprocess: denoise (Gaussian/median), normalize and binarize (Otsu or adaptive), then apply morphological open/close and remove_small_objects to get a clean mask.
  2. Seed extraction: compute the distance transform of the binary mask, suppress spurious peaks (h-maxima or smoothing), and find local maxima to serve as markers.
  3. Segmentation: run watershed using those markers on the negative distance map or the image gradient, with the original mask as a constraint.
  4. Postprocess: remove tiny regions, merge fragments by size/shape, or split by concavity if two nuclei remain fused.

A concise Python sketch using scikit-image:

from skimage import io, filters, morphology, segmentation, feature
from scipy import ndimage as ndi
img = io.imread('cells.png', as_gray=True)
img = filters.gaussian(img, sigma=1.0)
mask = img > filters.threshold_otsu(img)
mask = morphology.remove_small_objects(mask, 64)
dist = ndi.distance_transform_edt(mask)
local_maxi = feature.peak_local_max(dist, indices=False, footprint=np.ones((3,3)))
markers = ndi.label(local_maxi)[0]
labels = segmentation.watershed(-dist, markers, mask=mask)

Tuning tips: increase smoothing or the minimum peak distance to reduce seeds; use h-maxima to suppress small maxima; try watershed on the gradient when intensity varies. If heavy overlap persists, consider contour concavity splitting or an instance-segmentation network (U-Net / Mask R-CNN). For hands-on examples see the scikit-image watershed demo and the OpenCV watershed tutorial (scikit-image example, OpenCV tutorial).

the simplest way i could think of is to use watershed segmentation. it works almost perfectly, but sometimes it results in over segmentation...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.