JuliaImages / ImageSegmentation.jl

Partitioning images into meaningful regions
Other
47 stars 23 forks source link

Speed-up watershed segmentation using information from a binary image #34

Closed VPetukhov closed 4 years ago

VPetukhov commented 5 years ago

Following the example from the documentation, currently segmentation is performed on the whole image, and later it's filtered with the binary mask. Though, using mask during the segmentation would allow to significantly reduce computation time, avoiding computation for background pixels.

How about adding new optional parameter img_bin::Union{Array{Bool,2}, BitArray{2}, Nothing}=nothing to the function? So the interface will be changed from

watershed(img::AbstractArray{T, N}, markers::AbstractArray{S,N})

to

watershed(img::AbstractArray{T, N}, markers::AbstractArray{S,N}, img_bin::Union{AbstractArray{Bool,2}, BitArray{2}, Nothing}=nothing)

On my example, new function works 3.5 times faster. If you think it's fine, I will create a pull request.

timholy commented 4 years ago

This sounds reasonable to me! But perhaps it would be better to make it a keyword argument? Perhaps called mask or something?

VPetukhov commented 4 years ago

But perhaps it would be better to make it a keyword argument? Perhaps called mask or something?

Yep, perhaps it would be better. Thanks!