Coder Social home page Coder Social logo

Comments (8)

timholy avatar timholy commented on May 24, 2024

In Julia, "white" = 1, not 255.

https://github.com/JuliaGraphics/ColorTypes.jl#rgb-plus-bgr-rgb1-rgb4-and-rgb24-the-abstractrgb-group

from colors.jl.

cormullion avatar cormullion commented on May 24, 2024

Oh. I was trying:

julia> RGBA(Colors.color_names["red"])

because

julia> Colors.color_names["red"]
(255,0,0)

julia> Colors.color_names["white"]
(255,255,255)

from colors.jl.

timholy avatar timholy commented on May 24, 2024

That's just for internal use. Did you come across a recommendation to use it somewhere, or did you find it by poking through the source code?

Try this instead:

julia> using Colors

julia> colorant"red"
RGB{U8}(1.0,0.0,0.0)

from colors.jl.

cormullion avatar cormullion commented on May 24, 2024

No problem. I like using the named colors: I was trying to find the name matching a specific color. I thought 0-255 values were supported, and was confused with the "Inexact error".

color_to_be_matched = (0.835, 0.388, 0.361)
for (colname, colvalue) in Colors.color_names
  r, g, b = colvalue
  x = colordiff(RGB(color_to_be_matched...), RGB(r/256, g/256, b/256))
  if x < 5
    println(colname, "\t", x)
  end
end

I didn't think the 0-255 values weren't supported.

from colors.jl.

timholy avatar timholy commented on May 24, 2024

It's a natural mistake. The reason why we don't support integers in the 0-255 range is that they lead to some troublesome ambiguities, esp. now that 10, 14, and 16-bit images are common. For a 16-bit image, 255 barely registers as brighter than "black"---and note that you're typing 255 as a 64-bit integer, which if taken literally is even worse!

This is what allows Julia to avoid needing stuff like this: http://scikit-image.org/docs/stable/user_guide/data_types.html#image-data-types-and-what-they-mean and to be able to write algorithms that take image values at face value, rather than having separate implementation for UInt8, UInt16, etc. (which is found all over the place in OpenCV's codebase).

In terms of making your life easier: you can use 255 as 255uf8 if you prefer that (need using FixedPointNumbers, I think). It also would be nice to throw a more informative error, but there could be performance consequences. We're fine with people specifying RGB(1,0,0) for example, so we can't make the error happen purely dependent on input types (unless we make RGB(1,0,0) illegal). If you have any thoughts, I'm all ears---you're not the first to be confused by this.

from colors.jl.

timholy avatar timholy commented on May 24, 2024

Closed by JuliaGraphics/ColorTypes.jl#51. The new error is

julia> RGBA(56, 34, 23)
ERROR: ArgumentError: (56,34,23,1) are integers in the range 0-255, but integer inputs are encoded with the UFixed8
  type, an 8-bit type representing 256 discrete values between 0 and 1.
  Consider dividing your input values by 255, for example: RGBA{UFixed8}(56/255,34/255,23/255,1/255)
  See the READMEs for FixedPointNumbers and ColorTypes for more information.
 in throw_colorerror(::Type{FixedPointNumbers.UFixed{UInt8,8}}, ::Tuple{Int64,Int64,Int64,Int64}) at /home/tim/.julia/v0.5/ColorTypes/src/types.jl:615
 in throw_colorerror(::Type{FixedPointNumbers.UFixed{UInt8,8}}, ::Int64, ::Int64, ::Int64, ::Int64) at /home/tim/.julia/v0.5/ColorTypes/src/types.jl:585
 in checkval at /home/tim/.julia/v0.5/ColorTypes/src/types.jl:575 [inlined]
 in ColorTypes.RGBA{FixedPointNumbers.UFixed{UInt8,8}}(::Int64, ::Int64, ::Int64, ::Int64) at /home/tim/.julia/v0.5/ColorTypes/src/types.jl:453
 in ColorTypes.RGBA{T<:Union{AbstractFloat,FixedPointNumbers.FixedPoint}}(::Int64, ::Int64, ::Int64) at /home/tim/.julia/v0.5/ColorTypes/src/types.jl:478

which hopefully qualifies as user-friendly.

from colors.jl.

cormullion avatar cormullion commented on May 24, 2024

@timholy This newbie thanks you! I'll continue my quest of making Julia the easiest to use and most powerful language around... :)

from colors.jl.

timholy avatar timholy commented on May 24, 2024

You're no newbie 😄. But you're very good at discovering things that would trip up a newbie, and that's invaluable. Keep 'em coming.

from colors.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.