Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert color image to gray scale #449

Closed
alexmulo opened this issue Mar 2, 2016 · 6 comments
Closed

Convert color image to gray scale #449

alexmulo opened this issue Mar 2, 2016 · 6 comments

Comments

@alexmulo
Copy link

alexmulo commented Mar 2, 2016

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

@timholy
Copy link
Member

timholy commented Mar 2, 2016

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.

@alexmulo
Copy link
Author

alexmulo commented Mar 2, 2016

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

@timholy
Copy link
Member

timholy commented Jan 30, 2017

Closed by #577

@timholy timholy closed this as completed Jan 30, 2017
@appersonj
Copy link

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}

@timholy
Copy link
Member

timholy commented Feb 4, 2018

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

@timholy
Copy link
Member

timholy commented Feb 4, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants