I've looked at these two algorithms, and the biggest difference seems to be in the output. `is_local_maximum` returns a Boolean array, while `peak_local_max` returns the indices of points corresponding to maxima (a la `np.sort` vs. `np.argsort`, though you cannot just pass the output of `peak_local_max` as indices).
On Mon, Nov 12, 2012 at 7:43 AM, Frank <pennek...@googlemail.com> wrote:Dear group,
I have some issues with the watershed algorithm implemented in scikits image. I use a global threshold to segment cells from background, but some cells touch and I want them to be split. Watershed seems the appropriate way to deal with my problem, however my particles are split in too many pieces. Is there a way to adjust the sensitivity of the watershed method?
Many thanks for any suggestion!
The code that I use looks like below. An example image that I want to process can be downloaded here: https://dl.dropbox.com/u/10373933/test.jpg
# packages needed to perform image processing and analysis
import numpy as np
import scipy as scp
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import scipy.ndimage as nd
import skimage
from skimage import io
from skimage.morphology import watershed, is_local_maximum
from skimage.segmentation import find_boundaries, visualize_boundaries
from skimage.color import gray2rgb
#read files jpeg file
image = mpimg.imread('c:\\test.jpg')
image_thresh = image > 140
labels = nd.label(image_thresh)[0]
distance = nd.distance_transform_edt(image_thresh)
local_maxi = is_local_maximum(distance, labels=labels, footprint=np.ones((9, 9)))
markers = nd.label(local_maxi)[0]
labelled_image = watershed(-distance, markers, mask=image_thresh)
#find outline of objects for plotting
boundaries = find_boundaries(labelled_image)
img_rgb = gray2rgb(image)
overlay = np.flipud(visualize_boundaries(img_rgb,boundaries) )
imshow(overlay)Hi Frank,Actually, I don't think the issue is in the watershed segmentation. Instead, I think the problem is in the marker specification: Using local maxima creates too many marker points when a blob deviates greatly from a circle. (BTW, does anyone know if there are any differences between `is_local_maximum` and `peak_local_max`? Maybe the former should be deprecated.)Using the centroids of blobs gives cleaner results. See slightly-modified example below.Best,-Tony# packages needed to perform image processing and analysisimport numpy as npimport matplotlib.pyplot as pltimport scipy.ndimage as ndfrom skimage import iofrom skimage import measurefrom skimage.morphology import watershedfrom skimage.segmentation import find_boundaries, visualize_boundariesfrom skimage.color import gray2rgb#read files jpeg fileimage = io.imread('test.jpg')image_thresh = image > 140labels = nd.label(image_thresh)[0]distance = nd.distance_transform_edt(image_thresh) props = measure.regionprops(labels, ['Centroid'])coords = np.array([np.round(p['Centroid']) for p in props], dtype=int) # Create marker image where blob centroids are marked Truemarkers = np.zeros(image.shape, dtype=bool)markers[tuple(np.transpose(coords))] = True labelled_image = watershed(-distance, markers, mask=image_thresh)#find outline of objects for plottingboundaries = find_boundaries(labelled_image) img_rgb = gray2rgb(image)overlay = visualize_boundaries(img_rgb, boundaries, color=(1, 0, 0))plt.imshow(overlay)plt.show()