Comments (8)
In Julia, "white" = 1, not 255.
from colors.jl.
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.
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.
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.
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.
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.
@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.
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)
- RGB -> XTerm256 approximation? HOT 13
- move storage type conversion trait from ImageCore to Colors HOT 6
- Optimizing the types used for intermediate calculations HOT 5
- Source of the YIQ transform matrix HOT 1
- is `inv` on Colors well defined? HOT 4
- Fatal performance degradation due to precompilation or inference bugs HOT 8
- MethodError: no method matching coloralpha(::Type{RGB24}) HOT 1
- What should `default_brettel_neutral` be? HOT 1
- Ambiguity with AbstractTrees
- 'Render' colours in REPL HOT 15
- in the README, put a link on the home page HOT 2
- colorwheel generator HOT 1
- add colorwheel generator HOT 1
- Release v0.13? HOT 2
- Ambiguous show method for `Union{}[]` HOT 3
- colormap("<Color>", maxcount; w=<Int>, logscale=<Bool>) stackoverflows HOT 7
- oklab/oklch for CSS4 and cheap deltaE HOT 1
- BGR interpreted as RGB HOT 1
- Luv and LCHuv gives incorrect color values for low lightness cyan HOT 1
- Support for Preferences.jl HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from colors.jl.