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

[WIP]Add skeletonization function #13

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Deepank308
Copy link

@Deepank308 Deepank308 commented Apr 14, 2019

Added skeletonization algorithm using medial-axis transform for binary images.
I will add documentation soon.

Please give suggestions for improving the API and performance, if any.
Ping @juliohm
Thank you!

Copy link
Member

@johnnychen94 johnnychen94 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some first-round comments here, it's just something I noticed, and I think it's more appropriate to let others review your code, they're more experienced and more qualified.
I didn't read the MedialAxis Skeletonization algorithm before, so I trust that you've written the algorithm procedure correct. Or could you give a reference to your implementation, so that I can have a look at? (I think it's quite an easy algorithm)


I haven't' reviewed others' codes before, so if there's anything I did not properly, please point it out :)

@@ -3,10 +3,15 @@ __precompile__()
module ImageMorphology

using ImageCore
using Images
Copy link
Member

@johnnychen94 johnnychen94 Apr 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's using ImageMorphology in Images.jl, and it will make package dependency complicate.

@timholy How do we deal with this problem in general? Can we directly copy Images.FeatureTransform module to ImageMorphology as temporary not-exported functions?
https:/JuliaImages/Images.jl/blob/bdfd044420fa6ffcd34760f804f0c3ce12186945/src/bwdist.jl

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@johnnychen94 another example where we find something implemented in Images.jl that could live somewhere else. We really need to reorganize concepts around and break Images.jl into smaller packages for reuse. Right now a bunch of functionality lives in the umbrella package, and that is suboptimal.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like @Deepank308 needs this function implemented and merged ASAP to continue his GSoC ImageTracking project.

@juliohm I guess we can copy these methods to FeatureTransform.jl (with comments) and remove it in the future, just like @zygmuntszpak does in https:/zygmuntszpak/ImageBinarization.jl/blob/6e0c81867eaef67b463fa5d52febfca4d0f6196a/src/integral_image.jl ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if copying/pasting helps @johnnychen94 , ideally we would start thinking more seriously about how to reorganize things. There is a lot of code living in the wrong place and we are just compromising the situation further by adopting multiple copies in submodules.

Copy link
Member

@johnnychen94 johnnychen94 Apr 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might need another two weeks to start the porting work. Let's see how it works then.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@johnnychen94 I don't need this function as of now in my implementations. I was just going through Skeletonization algorithm and found that Julia doesn't have it. So, I implemented and sent a PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, this PR might be pended until FeatureTransform being ported to a standalone module.

src/skeletonization.jl Outdated Show resolved Hide resolved
src/ImageMorphology.jl Outdated Show resolved Hide resolved
src/ImageMorphology.jl Outdated Show resolved Hide resolved
src/skeletonization.jl Outdated Show resolved Hide resolved
src/skeletonization.jl Outdated Show resolved Hide resolved
src/skeletonization.jl Outdated Show resolved Hide resolved
src/skeletonization.jl Outdated Show resolved Hide resolved
src/skeletonization.jl Outdated Show resolved Hide resolved
src/skeletonization.jl Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Apr 15, 2019

Codecov Report

Merging #13 into master will decrease coverage by 29.24%.
The diff coverage is 72.09%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master      #13       +/-   ##
===========================================
- Coverage     100%   70.75%   -29.25%     
===========================================
  Files           2        4        +2     
  Lines          44      106       +62     
===========================================
+ Hits           44       75       +31     
- Misses          0       31       +31
Impacted Files Coverage Δ
src/ImageMorphology.jl 100% <100%> (ø)
src/skeletonization.jl 71.42% <71.42%> (ø)
src/thinning.jl 57.57% <0%> (-42.43%) ⬇️
src/dilation_and_erosion.jl 83.33% <0%> (-16.67%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 43b3d0e...d4f8638. Read the comment docs.

@codecov
Copy link

codecov bot commented Apr 15, 2019

Codecov Report

Merging #13 into master will decrease coverage by 28.84%.
The diff coverage is 73.17%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master      #13       +/-   ##
===========================================
- Coverage     100%   71.15%   -28.85%     
===========================================
  Files           3        4        +1     
  Lines          62      104       +42     
===========================================
+ Hits           62       74       +12     
- Misses          0       30       +30
Impacted Files Coverage Δ
src/ImageMorphology.jl 100% <100%> (ø) ⬆️
src/skeletonization.jl 72.5% <72.5%> (ø)
src/thinning.jl 57.57% <0%> (-42.43%) ⬇️
src/dilation_and_erosion.jl 83.33% <0%> (-16.67%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 277925b...c3ef6bb. Read the comment docs.

```

# References
[1] http://homepages.inf.ed.ac.uk/rbf/HIPR2/skeleton.htm
Copy link
Member

@johnnychen94 johnnychen94 Apr 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a title to the reference item for clarity

also here are some thoughts on simplifying documentation of function with multiple methods.

JuliaImages/Images.jl#790 (comment)
JuliaImages/ImageBinarization.jl#25

It'll be great to hear thoughts from you.

Further documentation work can be done after codes being stable.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted. I will keep that in my mind if any other skeletonization algorithm will be implemented in future?

@Deepank308
Copy link
Author

I don't know the exact reason as to why AppVeyor test is failing. The test fails for julia-latest.
It is showing error :
ERROR: UndefVarError: versioninfo not defined
Any ideas?

@johnnychen94
Copy link
Member

johnnychen94 commented Apr 15, 2019

An upgrade on CI configuration is needed, #14

As for ERROR: UndefVarError: versioninfo not defined error, we need using InteractiveUtils; versioninfo()

@Deepank308
Copy link
Author

I was curious to compare the performance of the algorithm in Julia and Python(skimage). This is what I got :
I have compared for white rectangles over black background.

Image Size Rect dims Julia(in ms) Python(in ms)
(300, 300) (200, 200) 99ms 99ms
(300, 300) (100, 100) 44ms 97ms
(600, 600) (400, 400) 400ms 180ms

So, there is some serious need for performance improvements!! Please suggest if anyone has some ideas.
Thanks!

@johnnychen94
Copy link
Member

johnnychen94 commented Apr 15, 2019

according to my experiences:

  • decreasing unnecessary memory reallocation can always improve performance for most Julia codes -- use @btime from BenchmarkTools to check it -- that's why we use StaticArrays
  • check if the for-loops in corner_table_lookup and inner_skeleton_loop can be vectorized
  • the append! in compute_critical_indices changes memory in every iteration, pre-initializing with zeros(Bool, length(critical_index_array)) and cutting the tail after the for-loop might help.

not sure if any of it works, sorry that I don't have much time digging into the details at present. There might be more tips in performance tweaking.

@fweth
Copy link

fweth commented Oct 8, 2020

I wrote a simple grassfire transform algorithm which works also on non-binary images: https:/fweth/Julia/blob/master/grassfireTransform.jl

I experimented with rasterized vector graphics and found out that treating pixels with values < 1 as already displaying the 'true' distance to the border gives smoother results than first applying threshold to the rasterization.

@johnnychen94 johnnychen94 added this to the 0.4.x milestone Jun 16, 2022
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

Successfully merging this pull request may close these issues.

4 participants