JuliaImages / JuliaImages/ImageSegmentation.jl
Troubles using watershed algorithm
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 45
- Forks
- 22
- PR merge metrics
- No merged PRs in 30d
Description
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:

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
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the watershed pipeline on slice 17 and compare it with the first slice, using the provided distance transform, local maxima, markers, and mask steps as checkpoints. Inspect how the intermediate results affect the final labels and document a concrete cause or reproducible improvement for the segmentation output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- computer-vision
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100