Hey Alex,

Do an imshow on your distance transform, ie `inv_dist`. You’ll see that it’s 
incorrect — it has the peaks outside of the bubbles. Then inv_peak has as the 
“maxima” the entire bubble — not good! So you should run your distance 
transform on `img_bin` rather than `inv_bin` and I think it’ll be a better 
result!

Juan.

On 6 Oct 2017, 1:00 AM +1100, Thomas Walter via scikit-image 
<scikit-image@python.org>, wrote:
> Hello Alex,
>
> the ultimate erosion coincides with the local maxima of the distance map (or 
> the local minima of the inverse distance map).
>
> In skimage, you can get these by:
>
> from skimage.morphology import extrema
> local_maxima = extrema.local_maxima(distance_map)
>
> peak_local_max is not equivalent to the UEP, but can be preferable in certain 
> situations.
>
> I did not check your example in practice as I do not have the image, but I 
> was a bit confused by the inversions, as you start by applying the threshold 
> the other way around.
>
> Best,
>
> Thomas.
>
> P.S.: The ImageJ description is not correct, which I have always found 
> disturbing. The Watershed algorithm is of course not limited to applications 
> to the inverse distance map.
>
>
> On 10/5/17 3:22 PM, Alexandre Fioravante de Siqueira wrote:
> > Dear all,
> > I am trying to write a that mimics the behavior of ImageJ's flooding 
> > watershed. This is how they describe it 
> > (https://imagej.nih.gov/ij/docs/menus/process.html#watershed):
> >
> > Watershed
> > Watershed segmentation is a way of automatically separating or cutting 
> > apart particles that touch. It first calculates the Euclidian distance map 
> > (EDM) and finds the ultimate eroded points (UEPs). It then dilates each of 
> > the UEPs (the peaks or local maxima of the EDM) as far as possible - either 
> > until the edge of the particle is reached, or the edge of the region of 
> > another (growing) UEP. Watershed segmentation works best for smooth convex 
> > objects that don't overlap too much.
> >
> > I tried to implement that (more or less), using the local minima (as 
> > pointed in https://www.mathworks.com/help/images/ref/bwulterode.html). Of 
> > course, there is something wrong :)
> >
> > from scipy.ndimage import binary_fill_holes
> > from scipy.ndimage.morphology import distance_transform_edt
> > from skimage.feature import peak_local_max
> > from skimage.filters import threshold_otsu
> > from skimage.io import imread
> > from skimage.measure import label
> > from skimage.morphology import disk, watershed
> > from skimage.util import invert
> >
> > import matplotlib.pyplot as plt
> >
> > image = imread('K90_incid4,5min_1.bmp')
> > img_bin = binary_fill_holes(image < threshold_otsu(image))
> >
> > inv_bin = invert(img_bin)
> > inv_dist = distance_transform_edt(inv_bin)
> > inv_peak = peak_local_max(-inv_dist, indices=False)
> > markers = label(peak)
> > labels = watershed(-distance, markers, mask=img_bin, watershed_line=True)
> >
> > plt.imshow(labels, cmap='nipy_spectral'), plt.show()
> >
> > We don't have a function for UEPs in skimage yet, right?
> > How could I implement this flooding watershed?
> > Thank you very much. Kind regards,
> >
> > Alex
> >
> > --
> > --------------------------------------------------
> > Dr. Alexandre 'Jaguar' Fioravante de Siqueira
> > Grupo de Cronologia - Sala 13
> > Departamento de Raios Cósmicos e Cronologia - DRCC
> > Instituto de Física "Gleb Wataghin" - IFGW
> > Unicamp - Universidade Estadual de Campinas
> > Rua Sérgio Buarque de Holanda, 777
> > Cidade Universitária Zeferino Vaz - CEP 13083-859
> > Campinas - SP - Brazil
> >
> > Phone: +55(19)3521-5362
> > Lattes curriculum: 3936721630855880
> > ORCID: 0000-0003-1320-4347
> > Personal site: programmingscience.org
> > Github: alexandrejaguar
> > Skype: alexandrejaguar
> > Twitter: alexdesiqueira
> > --------------------------------------------------
> >
> >
> > _______________________________________________
> > scikit-image mailing list
> > scikit-image@python.org
> > https://mail.python.org/mailman/listinfo/scikit-image
>
>
> --
> Thomas Walter
> 27 rue des Acacias
> 75017 Paris
> _______________________________________________
> scikit-image mailing list
> scikit-image@python.org
> https://mail.python.org/mailman/listinfo/scikit-image
_______________________________________________
scikit-image mailing list
scikit-image@python.org
https://mail.python.org/mailman/listinfo/scikit-image

Reply via email to