Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
cpaniaguam opened this issue Jul 5, 2023 · 1 comment
Open

Comments

@cpaniaguam
Copy link

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 😕.

@johnnychen94
Copy link
Member

johnnychen94 commented Jul 12, 2023

Currently, only se generated from strel_diamond and strel_box have optimized implementation.

To address this, we'll need to:

  1. implement a strel_ball function that generates SEBall (CRef: strel: more shape generators #75)
  2. provide an optimized extreme_filter implementation for SEBall

Unfortunately, I don't have the time to work on this, but if there's a PR for this, I'd be happy to review and merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants