Skip to content

Troubles using watershed algorithm #90

@DiegoPerezDones

Description

@DiegoPerezDones

Hello everyone,

I am having trouble using watershed function. I have followed the tutorials but still haven't been able to get an acceptable solution. I would be very greatful if anyone could give me some insights in what ccoul be happening here.

a = TiffImages.load("C://Users//i7//Desktop//imagenes_mario\\24_1.tif");

# convert to Gray to discard useless green and blue channels (all info is in red)
# and reshape since the color info is intercalated in the z dimension
b = reshape(Gray.(a), size(a)[[1,2]]..., 3, :)

#Select just the channels with cell nuclei
nuclei = b[:,:,3,:]
img = nuclei

#Obtain binary image based on a filters pipeline, it is not important how the pipeline actually works.
binary = processing_nuclei_multiThreading(nuclei,6)

#Invert binary image
binary_inv = binary .< 1

#For ease, we will aply our code just in one slice of the stack but bear in mind I do the same for each slice in a for loop
i = 17
dist = distance_transform(feature_transform(binary_inv[:,:,i]))
if sum(dist) != 0 #Here we asses if the slice if empty of objects.
        peaks = zeros(size(dist))
        peaks[findlocalmaxima(dist, window = (6,6))] .= 1
        markers = label_components(peaks)
        segments = watershed(dist, Int.(markers), mask = binary[:,:,i] .> 0, compactness = 1)
        labels[:,:,i] = p = labels_map(segments)
        IndirectArray(p .+1, distinguishable_colors(maximum(p)+1)) #This is just for print a coloured version of the labels.
    else
        labels[:,:,i] = img[:,:,i]
    end

So after all this pipeline, the final result of the segmentation is the next:
image

As you may see, the result is not terrible but could be improved. You should also take into account that, in this slice in particular, this is working quite fine in comparison with, for example the first slice. Any advices to improve the result?

Thank you all in advance! @tlnagy

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions