title: Segmenting image of multiple cells and splitting into single cells
body: <p>Say I have this image:
  <a href="https://i.stack.imgur.com/qxqxm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qxqxm.png" alt="Image of multiple cells" /></a></p>
  <p>Which can be obtained via</p>
  <pre><code>from skimage.data import human_mitosis
  image = human_mitosis()
  </code></pre>
  <p>I want to turn this image of multiple cells into multiple images for each individual cell through automatically cropping each single cell into its own image (ideally the size of the cropping is the same size/shape for each cell). So, for example, these would be some of the expected images:</p>
  <p><a href="https://i.stack.imgur.com/znUCj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/znUCj.png" alt="enter image description here" /></a> <a href="https://i.stack.imgur.com/LiV8C.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LiV8C.png" alt="enter image description here" /></a></p>
  <p>Although scikit has some code for segmenting cells, how do you use this segmentation (or some other potentially easier method) to separate single cells into their own images or objects?</p>
  <p>Here is some code for segmenting the cells (taken from scikit's tutorial with this image <a href="https://scikit-image.org/docs/dev/auto_examples/applications/plot_human_mitosis.html#sphx-glr-auto-examples-applications-plot-human-mitosis-py" rel="nofollow noreferrer">https://scikit-image.org/docs/dev/auto_examples/applications/plot_human_mitosis.html#sphx-glr-auto-examples-applications-plot-human-mitosis-py</a>):</p>
  <pre><code>import matplotlib.pyplot as plt
  import numpy as np
  from scipy import ndimage as ndi
  from skimage import (
      color, feature, filters, measure, morphology, segmentation, util
  )
  
  thresholds = filters.threshold_multiotsu(image, classes=3)
  cells = image &gt; thresholds[0]
  
  distance = ndi.distance_transform_edt(cells)
  
  local_max_coords = feature.peak_local_max(distance, min_distance=7)
  local_max_mask = np.zeros(distance.shape, dtype=bool)
  local_max_mask[tuple(local_max_coords.T)] = True
  markers = measure.label(local_max_mask)
  
  segmented_cells = segmentation.watershed(-distance, markers, mask=cells)
  
  fig, ax = plt.subplots(ncols=2, figsize=(10, 5))
  ax[0].imshow(cells, cmap='gray')
  ax[0].set_title('Overlapping nuclei')
  ax[0].axis('off')
  ax[1].imshow(color.label2rgb(segmented_cells, bg_label=0))
  ax[1].set_title('Segmented nuclei')
  ax[1].axis('off')
  plt.show()
  </code></pre>
  <p><a href="https://i.stack.imgur.com/VLR2p.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VLR2p.png" alt="enter image description here" /></a></p>