title: Python 3D image segmentation find local peaks in distance map for watershed
body: <p>I am trying to segment 3d tomographs of porous networks in python. I am able to calculate the distance map with <code>ndimage.distance_transform_edt</code> and the peaks with <code>feature.peak_local_max</code>. when I apply the watershed algorithm a get an acceptable result, but the markers of the peaks are not located at the visible peaks, see image, of the distance map</p>
  
  <p>Thanks in advance</p>
  
  <p><a href="https://i.stack.imgur.com/6Yhxu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6Yhxu.png" alt="enter image description here"></a></p>
  
  <p>Here the code a is the image</p>
  
  <pre><code>D = ndimage.distance_transform_edt(a)
  localMax = feature.peak_local_max(D, indices=False, min_distance=50,
              labels=a)
  localMax2 = feature.peak_local_max(D, indices=True, min_distance=50,
              labels=a)
  
  markers = ndimage.label(localMax, structure=np.ones((3,3,3)))[0]
  labels = morphology.watershed(-D,markers,mask=a)
  </code></pre>