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

@unpack error using contour_topology.jl #25

Open
fdecarpentier opened this issue Aug 6, 2020 · 4 comments
Open

@unpack error using contour_topology.jl #25

fdecarpentier opened this issue Aug 6, 2020 · 4 comments

Comments

@fdecarpentier
Copy link

Hi,

Thanks for this very nice package.
I'm trying to reproduce your example of contour drawing:

using ImageComponentAnalysis, TestImages, ImageBinarization, ImageCore, AbstractTrees, Parameters
img = Gray.(testimage("blobs"))
img2 = binarize(img, Otsu())
components = label_components(img2, trues(3,3), 1)
tree = establish_contour_hierarchy(components)
# Iterate over all DigitalContour's in the tree.
for node in PostOrderDFS(tree)
    @unpack id, is_outer, pixels node.data # See Parameters.jl for "@unpack"
    @show id, is_outer, pixels
end

And I get this error:

ERROR:` MethodError: no method matching @unpack(::LineNumberNode, ::Module, ::Expr, ::Expr)
Closest candidates are:
  @unpack(::LineNumberNode, ::Module, ::Any) at C:\Users\fdeca\.julia\packages\UnPack\1IjJI\src\UnPack.jl:92
Stacktrace:
 [1] include_string(::Function, ::Module, ::String, ::String) at .\loading.jl:1088

I belive that it is due to the fact that @unpack belives that "pixels node.data" are two different Expr.
I have no idea how Parameters.jl works...

Thank you for your time,
Best regards,

Félix

@zygmuntszpak
Copy link
Owner

zygmuntszpak commented Aug 7, 2020

Thanks for raising the issue. It turns out that I forgot a simple = . It should be

 @unpack id, is_outer, pixels = node.data # See Parameters.jl for "@unpack"

It turns out that the @unpack macro is now also available in a standalone package UnPack.jl.
Hence, if you do that package to your environment via

] add UnPack

then the following code snippet will run.

using ImageComponentAnalysis, TestImages, ImageBinarization, ImageCore, AbstractTrees, UnPack
img = Gray.(testimage("blobs"))
img2 = binarize(img, Otsu())
components = label_components(img2, trues(3,3), 1)
tree = establish_contour_hierarchy(components)
# Iterate over all DigitalContour's in the tree.
for node in PostOrderDFS(tree)
    @unpack id, is_outer, pixels = node.data # See Parameters.jl  or UnPack.jl for "@unpack"
    @show id, is_outer, pixels
end

Note that the @unpack macro is just a convenient short-hand for writing something like:

id = node.data.id
is_outer = node.data.is_outer
pixels = node.data.pixels

I see that you must be using the master branch. Apologies for not tagging a new release in such a long time. I did a bunch of clean-up since the last release. At the moment I am working on an implementation of Fourier Descriptors so that one can reason about the shape of a connected component based on its contour. Once that is finished I was planning to update all the documentation, give lots more examples and tag a new release.

@fdecarpentier
Copy link
Author

Thank you for your answer!
I'm still a bit confused about how this works but I think this package is great and unique!

@zygmuntszpak
Copy link
Owner

Thanks for the kind words. Please could you elaborate on what you meant by "how this works". Were you referring to @unpack, or how to extract knowledge about the topology of a connected component from the tree representation?

I still need to write some documentation for the concept of the contour hierarchy, but a good place to start to get the basic idea is to at the OpenCV example. I haven't implemented any convenience functions for grabbing information about where a component sits in the hierarchy. The OpenCV example talks about different "contour retrieval modes". I'm not sure that any of those constitute the best approach for representing the information, and hence I have just exposed the tree to the end-user so that they can decide what information they want to extract and how.

@fdecarpentier
Copy link
Author

Actually I'm more interested in drawing the contour than hierarchy.

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