Skip to content

Commit

Permalink
feat: watershed2
Browse files Browse the repository at this point in the history
  • Loading branch information
cpaniaguam committed Nov 5, 2024
1 parent 333f44e commit e64ccf6
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/tilingutils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -584,3 +584,30 @@ function get_final(img, label, segment_mask, se_erosion, se_dilation)
final = sk_morphology.reconstruction(marker, mask)
return final
end

function watershed2(morph_residue, se=se_disk20())
# Task 1: Reconstruct morph_residue
task1 = Threads.@spawn begin
mr_reconst = reconstruct_erosion(morph_residue, se)
mr_reconst .= reconstruct(mr_reconst, se_disk20(), "dilation", true)
mr_reconst .= imcomplement(mr_reconst)
mr_reconst .= ImageMorphology.local_maxima(mr_reconst; connectivity=2) .> 0
end

# Task 2: Calculate gradient magnitude
task2 = Threads.@spawn begin
gmag = imgradientmag(histeq(morph_residue))
end

# Wait for both tasks to complete
mr_reconst = fetch(task1)
gmag = fetch(task2)

minimamarkers = Bool.(mr_reconst) .| segment_mask .| ice_mask
gmag .= impose_minima(gmag, minimamarkers)
cc = label_components(imregionalmin(gmag), trues(3, 3))
cc = label_components((gmag), trues(3, 3))
w = ImageSegmentation.watershed(morph_residue, cc)
lmap = labels_map(w)
return isboundary(lmap)
end

0 comments on commit e64ccf6

Please sign in to comment.