Skip to content

[Performace] Dilation with strel much slower than matlab with disk se #127

@cpaniaguam

Description

@cpaniaguam

I exported a strel from matlab using strel

>> se = strel('disk', 50)

se = 

strel is a disk shaped structuring element with properties:

      Neighborhood: [99×99 logical]
    Dimensionality: 2

I import this strel (kind of tricky to build from scratch) into Julia and do the recommended conversions

(temp) pkg> st
Status `\temp\Project.toml`
  [787d08f9] ImageMorphology v0.4.4

julia> using ImageMorphology

julia> se_mask = centered(make_disk50_se());

julia> se_offsets = strel(CartesianIndex, se_mask);

julia> se
99×99 OffsetArray(::BitMatrix, -49:49, -49:49) with eltype Bool with indices -49:49×-49:49:
(rest of output suppressed)

Then I do the benchmarking with a very simple image

>> bw = zeros(500, 500);
>> bw(125:250, 125:250) = 1;
>> f = @() imdilate(bw, se);
>> timeit(f)

ans =

    0.0268

>> timeit(f)

ans =

    0.0259

>> 
julia> bw = zeros(Bool, 500, 500);

julia> bw[125:250, 125:250] .= true;

julia> @time ImageMorphology.dilate(bw, se);
  1.713545 seconds (31 allocations: 736.844 KiB)

julia> @time ImageMorphology.dilate(bw, se);
  1.731762 seconds (31 allocations: 736.844 KiB)

In my use case with a much larger and much more complex image Matlab does this work in about 0.11 seconds, while Julia takes close to 300 seconds 😕.

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