Images.jl icon indicating copy to clipboard operation
Images.jl copied to clipboard

Convert color image to gray scale

Open alexmulo opened this issue 10 years ago • 6 comments

Hello guys,

I'm trying to convert a color image to a gray scale using these commands:

mean(temp.data, 1)

and the output error is:

ERROR: MethodError:converthas no method matching convert(::Type{ColorTypes.RGB{Float32}}, ::Int64) This may have arisen from a call to the constructor ColorTypes.RGB{Float32}(...), since type constructors fall back to convert methods. Closest candidates are: ColorTypes.RGB{T<:Union{AbstractFloat,FixedPointNumbers.FixedPoint{T<:Integer,f}}}(::Any, ::Any, ::Any) call{T}(::Type{T}, ::Any) convert{C<:ColorTypes.Colorant{T,N}}(::Type{C<:ColorTypes.Colorant{T,N}}, ::ColorTypes.Colorant{T,N}) ... in fill! at multidimensional.jl:557 in mean at statistics.jl:31

And if I use this command:

convert(Image{Gray}, temp)

I get this output:

ERROR: UndefVarError: Gray not defined

do you have anay idea how can I solve the problem?

Thanks

alexmulo avatar Mar 02 '16 22:03 alexmulo

julia> using TestImages, Colors

julia> img = testimage("mandrill")
RGB Images.Image with:
  data: 512x512 Array{ColorTypes.RGB{FixedPointNumbers.UFixed{UInt8,8}},2}
  properties:
    colorspace: sRGB
    spatialorder:  x y

julia> imgg = convert(Image{Gray}, img)
Gray Images.Image with:
  data: 512x512 Array{ColorTypes.Gray{FixedPointNumbers.UFixed{UInt8,8}},2}
  properties:
    colorspace: sRGB
    spatialorder:  x y

I see there's a stray property, but note

julia> colorspace(imgg)
"Gray"

gives the right answer. (Dispatch wins over dictionary properties.) Obviously I/someone should clean this up, though.

timholy avatar Mar 02 '16 22:03 timholy

That works fine. Thanks a lot for your help!!!!!

alexmulo avatar Mar 02 '16 22:03 alexmulo

Closed by #577

timholy avatar Jan 30 '17 13:01 timholy

This is currently failing for me on MacOs HighSierra,

I see the following error, after: imgg = convert(Image{Gray},img)

  ERROR: TypeError: Type{...} expression: expected UnionAll, got Type{Gtk.GtkImage}

appersonj avatar Feb 03 '18 21:02 appersonj

That was the old syntax. New syntax is documented at http://juliaimages.github.io/latest/. Just use imgg = Gray.(img).

timholy avatar Feb 04 '18 10:02 timholy

What documentation are you following? It would be good to correct posted documents that are out of date.

timholy avatar Feb 04 '18 10:02 timholy