JuliaImages / ImageSegmentation.jl

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

Unable to use readme examples (except with ImageSegmentation dev'd). methoderror `iterate(::Gray{Float64})` #79

Closed anandijain closed 2 years ago

anandijain commented 2 years ago

I'm trying to follow these docs https://juliaimages.org/stable/pkgs/segmentation/

I tried starting a temp environment with Pkg.activate(;temp=true) to ensure it wasn't just my current environment causing issues, but the following code fails. (FFTW is just because I'm on m1, I don't think it is related to my issue).

using Pkg
Pkg.add(url="https://github.com/giordano/FFTW_jll.jl")
Pkg.add(["ImageCore", "ImageSegmentation"])
using Images, ImageSegmentation, ImageFiltering
img = rand(Gray, 1000, 1000)
seeds = [(CartesianIndex(126,81),1), (CartesianIndex(93,255),2), (CartesianIndex(213,97),3)]
segments = seeded_region_growing(img, seeds)

julia> segments = seeded_region_growing(img, seeds)
ERROR: MethodError: no method matching iterate(::Gray{Float64})
  ...
Stacktrace:

After deving ImageSegmentation itself, I was able to run those last 4 lines and get seeded_region_growing to work.

I vaguely suspect it has something to do with ColorVectorSpace, as this was the only thing that stuck out as having a lower version, but having a tough time figuring out whats wrong.

johnnychen94 commented 2 years ago

A working PR is #72

timholy commented 2 years ago

If you were using released versions of all packages, it should have worked. If you can replicate the problem, please post the output of Pkg.status() and possibly your Project.toml and Manifest.toml in a gist.

timholy commented 2 years ago

While it should work with released versions of packages, #80 also makes it possible to use the latest ColorVectorSpace/ImageCore etc. Hence I'll close this.

kforner commented 2 years ago

same error, using a fresh install of julia 1.6.3. Just followed the doc:

pkg> add Images ImageSegmentation TestImages

using ImageSegmentation, TestImages
img = testimage("camera")
seg = fast_scanning(img, 0.1)  # threshold = 0.1

julia> seg = fast_scanning(img, 0.1)  # threshold = 0.1
ERROR: MethodError: no method matching iterate(::Gray{Float64})
Closest candidates are:
  iterate(::Union{LinRange, StepRangeLen}) at range.jl:664
  iterate(::Union{LinRange, StepRangeLen}, ::Int64) at range.jl:664
  iterate(::T) where T<:Union{Base.KeySet{var"#s77", var"#s76"} where {var"#s77", var"#s76"<:Dict}, Base.ValueIterator{var"#s75"} where var"#s75"<:Dict} at dict.jl:693
  ...
Stacktrace:
  [1] _foldl_impl(op::Base.MappingRF{typeof(abs2), Base.BottomRF{typeof(Base.add_sum)}}, init::Base._InitialValue, itr::Gray{Float64})
    @ Base ./reduce.jl:56
  [2] foldl_impl(op::Base.MappingRF{typeof(abs2), Base.BottomRF{typeof(Base.add_sum)}}, nt::Base._InitialValue, itr::Gray{Float64})
    @ Base ./reduce.jl:48
  [3] mapfoldl_impl(f::typeof(abs2), op::typeof(Base.add_sum), nt::Base._InitialValue, itr::Gray{Float64})
    @ Base ./reduce.jl:44
  [4] mapfoldl(f::Function, op::Function, itr::Gray{Float64}; init::Base._InitialValue)
    @ Base ./reduce.jl:160
  [5] mapfoldl(f::Function, op::Function, itr::Gray{Float64})
    @ Base ./reduce.jl:160
  [6] mapreduce(f::Function, op::Function, itr::Gray{Float64}; kw::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Base ./reduce.jl:287
  [7] mapreduce(f::Function, op::Function, itr::Gray{Float64})
    @ Base ./reduce.jl:287
  [8] sum(f::Function, a::Gray{Float64}; kw::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Base ./reduce.jl:501
  [9] sum(f::Function, a::Gray{Float64})
    @ Base ./reduce.jl:501
 [10] default_diff_fn(c1::Gray{Float64}, c2::Gray{N0f8})
    @ ImageSegmentation ~/.julia/packages/ImageSegmentation/MX8ga/src/region_growing.jl:2
 [11] fast_scanning(img::Matrix{Gray{N0f8}}, threshold::Float64, diff_fn::typeof(ImageSegmentation.default_diff_fn))
    @ ImageSegmentation ~/.julia/packages/ImageSegmentation/MX8ga/src/fast_scanning.jl:92
 [12] fast_scanning(img::Matrix{Gray{N0f8}}, threshold::Float64)
    @ ImageSegmentation ~/.julia/packages/ImageSegmentation/MX8ga/src/fast_scanning.jl:66
 [13] top-level scope
    @ REPL[31]:1
johnnychen94 commented 2 years ago

Sorry for the inconvenience, we're still during the transition to ImageCore v0.9 stage. https://github.com/JuliaImages/Images.jl/pull/971

To follow the example, currently, you have to remove Images first (or activating a new environment) so that you can get the latest ImageSegmentation v1.6.0 version installed.