JuliaImages / ImageSegmentation.jl

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

prune_segments - ERROR: MethodError: no method matching add_vertices!(::SimpleWeightedGraph{Int64, Float64}, ::Int64) #86

Closed chris-revell closed 2 years ago

chris-revell commented 2 years ago

I'm trying to run some examples from the documentation, such as the following:

using ImageSegmentation, TestImages
img = testimage("camera")
seg = fast_scanning(img, 0.1)
seg = prune_segments(seg, i->(segment_pixel_count(seg,i)<50), (i,j)->(-segment_pixel_count(seg,j)))

Unfortunately this returns the following error:

ERROR: MethodError: no method matching add_vertices!(::SimpleWeightedGraphs.SimpleWeightedGraph{Int64, Float64}, ::Int64)
Closest candidates are:
  add_vertices!(::LightGraphs.AbstractGraph, ::Integer) at /Users/christopher/.julia/packages/LightGraphs/IgJif/src/core.jl:45
Stacktrace:
 [1] region_adjacency_graph(s::SegmentedImage{Matrix{Int64}, ColorTypes.Gray{Float64}}, weight_fn::ImageSegmentation.var"#12#13")
   @ ImageSegmentation ~/.julia/packages/ImageSegmentation/MX8ga/src/core.jl:109
 [2] prune_segments(s::SegmentedImage{Matrix{Int64}, ColorTypes.Gray{Float64}}, is_rem::var"#1#3", diff_fn::var"#2#4")
   @ ImageSegmentation ~/.julia/packages/ImageSegmentation/MX8ga/src/core.jl:221
 [3] top-level scope
   @ REPL[4]:1

Any ideas as to what might be going on here?

Julia version 1.6.4 on macOS 12.0.1.

johnnychen94 commented 2 years ago

Can you checkout to #85 and see if it works?

chris-revell commented 2 years ago

Thanks for getting back to me. Can I switch branch if I installed with Pkg, or do I need to install the repo manually?

johnnychen94 commented 2 years ago

(@v1.7) pkg> add ImageSegmentation#jc/compat

See also: https://pkgdocs.julialang.org/v1/managing-packages/#Adding-packages

If a branch (or a certain commit) of Example has a hotfix that is not yet included in a registered version, we can explicitly track that branch (or commit) by appending #branchname (or #commitSHA1) to the package name:

chris-revell commented 2 years ago

I was literally just coming back to say I had figured out how to install the branch with pkg. Unfortunately, doing so gives the following error:

(@v1.6) pkg> add ImageSegmentation#jc/compat
    Updating git-repo `https://github.com/JuliaImages/ImageSegmentation.jl.git`
    Updating registry at `~/.julia/registries/General`
   Resolving package versions...
ERROR: Unsatisfiable requirements detected for package ImageCore [a09fc81d]:
 ImageCore [a09fc81d] log:
 ├─possible versions are: 0.7.0-0.9.3 or uninstalled
 ├─restricted to versions 0.9 by ImageSegmentation [80713f31], leaving only versions 0.9.0-0.9.3
 │ └─ImageSegmentation [80713f31] log:
 │   ├─possible versions are: 1.6.0 or uninstalled
 │   └─ImageSegmentation [80713f31] is fixed to version 1.6.0
 └─restricted by compatibility requirements with Images [916415d5] to versions: 0.7.0-0.8.22 — no versions left
   └─Images [916415d5] log:
     ├─possible versions are: 0.17.3-0.24.1 or uninstalled
     ├─restricted to versions * by an explicit requirement, leaving only versions 0.17.3-0.24.1
     └─restricted by compatibility requirements with ImageMorphology [787d08f9] to versions: 0.18.0-0.24.1 or uninstalled, leaving only versions: 0.18.0-0.24.1
       └─ImageMorphology [787d08f9] log:
         ├─possible versions are: 0.1.0-0.3.0 or uninstalled
         ├─restricted to versions 0.2.6-0.3 by ImageSegmentation [80713f31], leaving only versions 0.2.6-0.3.0
         │ └─ImageSegmentation [80713f31] log: see above
         └─restricted by compatibility requirements with Images [916415d5] to versions: 0.1.1-0.2.12, leaving only versions: 0.2.6-0.2.12
           └─Images [916415d5] log: see above
johnnychen94 commented 2 years ago

Yeah... We're currently having a hard time with Images compatibility. Maybe you can temporarily remove Images or use this branch https://github.com/JuliaImages/Images.jl/pull/971

Both PRs are ready but I need to make sure people want to see that happen.

chris-revell commented 2 years ago

The branches you have specified for Images and ImageSegmentation appear to solve the problem with prune_segments 👍 Thanks very much for the help.

johnnychen94 commented 2 years ago

Okay. Then I think we should release both versions recently.

johnnychen94 commented 2 years ago

With Images v0.25 and ImageSegmentation v1.7 released, it should work now.