Fuzzy C-means clustering in ImageSegmentation.jl

338 views Asked by At

I am trying to cluster different regions of an image using Fuzzy C-means clustering with ImageSegmentation.jl

using ImageSegmentation, Images
fl = load("flower.jpg")
fuzzy_fl = fuzzy_cmeans(fl,3,2)

It gives an error like this:

MethodError: no method matching fuzzy_cmeans(::Base.ReshapedArray{Float64,2,ImageCore.ChannelView{Float64,3,Array{ColorTypes.RGB4{Float64},2}},Tuple{Base.MultiplicativeInverses.SignedMultiplicativeInverse{Int64},Base.MultiplicativeInverses.SignedMultiplicativeInverse{Int64}}})
Closest candidates are:
  fuzzy_cmeans(::Array{T<:Real,2}, ::Int64, ::Real; maxiter, tol, dist_metric, display) where T<:Real at /Users/asharma19/.julia/v0.6/Clustering/src/fuzzycmeans.jl:58
  fuzzy_cmeans(::AbstractArray{T<:ColorTypes.Colorant,N}, ::Any...; kwargs...) where {T<:ColorTypes.Colorant, N} at /Users/asharma19/.julia/v0.6/ImageSegmentation/src/clustering.jl:12

1) How should I input an image to this function? 2) Also, if it works fine, as the function does not return a SegmentedImage array, how should I display a segmented/clustered image after that?

2

There are 2 answers

2
juliohm On

The code works fine for me. You are probably taking a slice of the image manipulating it (e.g. views, transposes) before feeding it into the fuzzy_cmeans function. Something different than the code example you posted.

0
Akshay Sharma On

The function fuzzy_cmeans does not accept Array{ColorTypes.RGB4{FixedPointNumbers.Normed{UInt8,8}},2}.

The images need to be Array{ColorTypes.RGB{FixedPointNumbers.Normed{UInt8,8}},2} to be input in the function.

Although, it should not happen as the parameter type of the function is Colorant{T,N} which is the parent of AbstractRGB{T}.

The images usually are RGB4 (have some padding involved) so you need to convert them before using. (can use convert function of julia)