1

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 Answers2

0

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.

juliohm
  • 3,691
  • 2
  • 18
  • 22
  • Did you try it in Julia 0.6? I cannot get this working. Also it would be great if you can help me with the second question. – Akshay Sharma Mar 12 '18 at 07:12
  • The same image works for other algorithms perfectly. I have tried with original image too without any manipulation. Don't know what's wrong. – Akshay Sharma Mar 12 '18 at 07:37
0

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)