JuliaImages / Images.jl

An image library for Julia
http://juliaimages.org/
Other
536 stars 143 forks source link

Can't find iterate(::ColorTypes.RGB{Float64}) #1019

Open drdozer opened 1 year ago

drdozer commented 1 year ago

I am trying to load in some jpeg images (from a phone) and segment out the background. My code looks like this:

function segment(img)
    dims = size(img)
    half(x) = floor(Int, x / 2)
    mid = half.(dims)
    seeds = [(CartesianIndex(1, 1), 1), (CartesianIndex(mid...), 2)]
    segments = seeded_region_growing(img, seeds)

    segments
end

The images are loaded with load. I can view the images in pluto, so I know the data is good. The type of the image is Matrix{RGB{N0f8}} (alias for Array{RGB{Normed{UInt8, 8}}, 2}).

When I call seeded_region_growing I get this error:

MethodError: no method matching iterate(::ColorTypes.RGB{Float64})

Closest candidates are:

iterate(!Matched::Union{LinRange, StepRangeLen}) at range.jl:872

iterate(!Matched::Union{LinRange, StepRangeLen}, !Matched::Integer) at range.jl:872

iterate(!Matched::T) where T<:Union{Base.KeySet{<:Any, <:Dict}, Base.ValueIterator{<:Dict}} at dict.jl:712

...
_foldl_impl(::Base.MappingRF{typeof(abs2), Base.BottomRF{typeof(Base.add_sum)}}, ::Base._InitialValue, ::ColorTypes.RGB{Float64})@reduce.jl:56
foldl_impl(::Base.MappingRF{typeof(abs2), Base.BottomRF{typeof(Base.add_sum)}}, ::Base._InitialValue, ::ColorTypes.RGB{Float64})@reduce.jl:48
mapfoldl_impl(::typeof(abs2), ::typeof(Base.add_sum), ::Base._InitialValue, ::ColorTypes.RGB{Float64})@reduce.jl:44
var"#mapfoldl#259"(::Base._InitialValue, ::typeof(mapfoldl), ::Function, ::Function, ::ColorTypes.RGB{Float64})@reduce.jl:170
mapfoldl(::Function, ::Function, ::ColorTypes.RGB{Float64})@reduce.jl:170
var"#mapreduce#263"(::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, ::typeof(mapreduce), ::Function, ::Function, ::ColorTypes.RGB{Float64})@reduce.jl:302
mapreduce(::Function, ::Function, ::ColorTypes.RGB{Float64})@reduce.jl:302
var"#sum#266"(::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, ::typeof(sum), ::Function, ::ColorTypes.RGB{Float64})@reduce.jl:528
sum(::Function, ::ColorTypes.RGB{Float64})@reduce.jl:528
default_diff_fn(::ColorTypes.RGB{Float64}, ::ColorTypes.RGB{FixedPointNumbers.N0f8})@region_growing.jl:2
seeded_region_growing(::Matrix{ColorTypes.RGB{FixedPointNumbers.N0f8}}, ::Vector{Tuple{CartesianIndex{2}, Int64}}, ::ImageSegmentation.var"#20#24"{CartesianIndex{2}}, ::typeof(ImageSegmentation.default_diff_fn))@region_growing.jl:125
seeded_region_growing(::Matrix{ColorTypes.RGB{FixedPointNumbers.N0f8}}, ::Vector{Tuple{CartesianIndex{2}, Int64}}, ::Tuple{Int64, Int64}, ::Function)@region_growing.jl:64
seeded_region_growing@region_growing.jl:57[inlined]
segment(::Matrix{ColorTypes.RGB{FixedPointNumbers.N0f8}})@[Other: 6](http://localhost:1234/edit?id=4ec61cfa-a6f2-11ed-37bd-254322b3a083#)
Techmegh commented 1 year ago

using Watershed

function seeded_region_growing(img, seeds) labels = label_components(img) for seed in seeds labels[seed[1]] = seed[2] end return labels end

timholy commented 1 year ago

I can't replicate this error. In case it's dependent on the specific image, it would help to have one that reproduces it.