-
Notifications
You must be signed in to change notification settings - Fork 21
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
Fixing Coloramity #101
Comments
The plan sounds good. Renaming Color.jl to Colors.jl is probably a good idea in any case. I'd like to better understand why a color should be considered a FixedVector. Sure, colors form a vector space, but then again lots of things do. Often they are treated like scalar quantities within a program (e.g. like complex numbers). |
Oh perfect timing, I was just starting to look into this! Obviously this split wasn't intended! I was mainly waiting for FixedSizeArrays and FileIO to mature, which slowly starts to happen. @JeffBezanson my main intention is to share a lot of functions. Starting from core functions like length, eltype (defined on the type and instance), over construction, simple conversion, math, to functions defined for arrays of FixedSizeVectors. Its really a lot of functionality which would be nasty to duplicate. |
@timholy this looks good to me! |
@timholy would you mind to post a nice example and requirements of your perfect world to JuliaGeometry/meta#8 ? |
@JeffBezanson a = [Vec3(1f0) for i=1:10]::Vector{Vec3{Float32}}
b = [rand(Vec{3, Float32} for i=1:10]
a[1][1:2]
map(RGB, b)
RGB([1,2,3])
Vec(Vec(2,3, 4), 1) + Vec(1,2,3,4)
a[1:end, 1] # -> [x,x,x,x, ...]
mean(a)
... These are all functions I would like to see for all scalar like types. By the way, I'm using this for my benchmark package as well, which is quite nice for mean, max etc. immutable BenchData{T} <: FixedVector{5, T}
time_ns ::T
gc_bytes ::T
gc_time_ns ::T
gc_num_pause ::T
gc_full_sweep ::T
end
a = zeros(BenchData, N)
for i=1:N
a[i] = @bench expr
end
mean(a) #etc Its also nice to do k-means and PCA and things like that on e.g. RGB directly, which would be a lot easier if its a subtype of FixedSizeArray (Which would work for arbitrary other data types which inherit from FixedSizeArrays). |
immutable AlphaColor{T, C<:Color{T}} <: AbstractAlphaColor{T,4}
alpha::T
c::C # C really has to be Color{T} (use inner constructor here)
end Can we expect this to work at some point via some triangular dispatch alike pattern? |
I know it seems daunting, but I think it's better to make core infrastructure reasonably mature before commencing on such a split. Otherwise you're basically asking other people to carry out that maturation for you (see https://github.com/JuliaIO/FileIO.jl/commits/master). And how do you otherwise know it will work?
I see the point, but for Images I do a lot of that already: https://github.com/timholy/Images.jl/blob/cb9c0811cef911ff590fd58dc4eab3bc6d17274f/src/colortypes.jl#L225-L577. Is that really the only reason you use As an example of what can make this kind of thing hard, what you'd probably like is something like this: immutable ColorAlpha{T,N,C{T,N}} <: FixedVector{T,N+1}
c::Color{T,N}
alpha::T
end but the
I think it's on the slate in JuliaLang/julia#8974. The code in Images is looking forward to a nice haircut once that merges.
I think "vision about how the whole visualization pipeline should work" is a little too broad to be relevant here.
On balance, so far I now lean away from the notion from making color types subtypes of |
Well the magic gpu reason is that it gives me an interface that I can program against, of which I can be sure that the GPU can handle it. Otherwise I would need to put Reinterpret is nice and all, but you loose type information, which you have to bring back at some point (e.g. when visualizing). I mean its not the worst, but why bother if you can easily just keep it? On top of that, PCA is best implemented with some notion of a
Definitely not relevant here, but the vision is made up of a lot of small parts which need to work together and i'm interested in how you would like to work with this. |
Also, if I remember the results of my Images.jl load time benchmarks correctly, these https://github.com/timholy/Images.jl/blob/cb9c0811cef911ff590fd58dc4eab3bc6d17274f/src/colortypes.jl#L225-L577 lines of code where accountable for a big fraction of the load time. |
Also, I started using tuples, which at some point will use llvm's vector type, giving us better chances for simd optimizations. Which is a big plus for Images, I suppose. immutable RGB{T}
_::NTuple{3, T}
end When we can overwrite getfield it might be bearable though. In the meantime I introduced a type called |
You can have the same function defined for
We could have a I could be persuaded that it might be workable to use
Navigate to the julia> @profile imread("earth_apollo17.jpg")
RGB Images.Image with:
data: 3000x3002 Array{Color.RGB{FixedPointNumbers.UfixedBase{UInt8,8}},2}
properties:
IMcs: sRGB
spatialorder: x y
pixelspacing: 1 1
julia> Profile.print()
275 task.jl; anonymous; line: 92
275 REPL.jl; eval_user_input; line: 63
275 profile.jl; anonymous; line: 16
275 /home/tim/.julia/v0.4/Images/src/io.jl; imread; line: 139
178 /home/tim/.julia/v0.4/Images/src/io.jl; imread; line: 263
178 /home/tim/.julia/v0.4/Images/src/ioformats/libmagickwand.jl; readimage; line: 226
47 /home/tim/.julia/v0.4/Images/src/io.jl; imread; line: 291
50 /home/tim/.julia/v0.4/Images/src/io.jl; imread; line: 322
50 /home/tim/.julia/v0.4/Images/src/ioformats/libmagickwand.jl; exportimagepixels!; line: 180 Those two lines are both
The same should apply for any dedicated color type hierarchy that looks a lot like |
Hello colleagues, i have to say, i'm not very deep into the differentiation between Arrays, Vectors, FixedArray etc. so i cannot contribute on this. If this is done like doing a new packages Colors.jl replacing (all) the available interfaces in Colors.jl and integrate (all) color conversions i fear again the 'Graphics' situation where packages slightly went out of sync, so changes like this should have a roadmap and some process to catch all dependencies. |
I meant the package load time ;)
That's for sure, but that means rewriting the color types to essentially look like what I did in @jiahao's comment is definitely noteworthy. How about going with
Yes, this is really unfortunate. It's sad how hard it is to work on abstract interfaces in Julia. I hope triangular dispatch will make this quite a bit easier.
@lobingera Can you explain this a bit more? I'm not really sure, why we should pretend that its a scalar, while we share 90% of the functions with FixedSizeVectors. |
Ah, yes, formerly that was really important, and the main reason I had basically stopped extending Images. It's not an issue now, though: julia> tic(); using Images; toc()
elapsed time: 0.928678548 seconds
0.928678548 (Obviously, using precompilation. EDIT: That's without have |
OK, that's great! I'll put that effort into ColorTypes.jl so you get to have the more granular organization you want. If your |
Much less of an issue I would say ;) We still shouldn't stress codegen like that. |
Great! I'll make sure to help wherever needed. |
With precompilation, IIUC all those |
Sure, but compilation takes longer and the cache will be bigger, I suppose. |
@SimonDanisch |
I don't feel like I have enough understanding to really contribute to the discussion, but @timholy I'd definitely accept the PR once a consensus has been reached. |
OK, @SimonDanisch and I have been hard at work, and we have a lot of progress to report. There are three new packages, all hosted at JuliaGraphics:
I'd like to open the floor for comments on the naming, design, and implementation of those packages. Given the disruptive nature of this change, I should justify why I think it's worth switching:
This was a pretty huge pile of work. I hope folks like it! One important detail: this will basically cause interoperability-chaos if some packages switch and others do not, or if there are long lags in switching. So first, I want to give folks a couple of days to look the new packages over and make comments; we'll modify these packages accordingly. Once that's done, it's time to transition to using them. If you want to transition your packages yourself, that's great, otherwise I'll submit pull requests for many of them. But, I propose that we hold off merging until an appointed "C-day" (Colors-day) and try to synchronize this transition across packages as well as possible. |
This is a great plan and a huge amount of work. Thank you both for undertaking it. One minor suggestion: how about |
I see that |
|
Why aren't |
According to this article, "tint" and "shade" already have technical meanings in color theory, so it's probably best not to use that. |
Are the ranges on things like |
+1 for making the apex Color |
That's enough "yea"s for me, Color it will be. Tomorrow morning 😄. |
The 3 packages keep things extremely neatly layered now. And awesome - Really appreciate the Tour de force! |
I'm quite happy with this. Nice job Tim and Simon! I'm not a big fan of My preference would be an apex type called |
Is "colorant" a somewhat standard term? It is in the dictionary: "a dye, pigment, or other substance that colors something." That seems apt. |
It's not standard as far as I know. It's hard to find prior art because I don't know of a comparable library; most are thoroughly graphics oriented or thoroughly colorimetry oriented. |
That's actually a very good thing. I suspect that custom types and external dispatch are quite necessary to satisfy both sets of needs with a single hierarchy. Maybe what is needed is a non-technical term since all the other terms are taken and mean something else. |
The transparentColor vs. OpaqueColor makes some sense in compositing, as opaque colours replace what is already 'painted' and transparent colours mix with the paint on the canvas. For plotting i sometimes like to be able to choose between opqaue and (half-)transparent colours. I understand you like to deal in Colors with color perception and currently the discussion (see ColorTypes) is more from how to technically deal with values. |
@dcjones, I will change those names. I more than half-expected this to be your view of it, and I think getting the names technically correct is a good thing. I do wish more of the colorimetry experts would chime in early in the game. I'm CCing two other folks, @glenn-sweeney and @m-lohmann. Along with @dcjones, would you please click "watch" on both https://github.com/JuliaGraphics/ColorTypes.jl and https://github.com/JuliaGraphics/Colors.jl, since those are where an increasing amount of the discussion is/will be happening? |
Despite the reputation that bikeshedding has, getting names right once and for all is very important. |
Perhaps the most important part of this transition, in fact. (But not the most work; that honor is easily captured by the traits system.) |
I've been lurking around Julia a while now. I work for BBC R&D and whilst colour isn't my area of expertise, I spend a lot of time discussing all aspects of video with those who are, so perhaps my input would be valuable here. First, sincere thanks to Tim and Simon for the work. It is the continued enthusiasm by the core Julia developers to do the dirty work which makes it so appealing as a platform. I would support @dcjones recommendations for the names in the type hierarchy. (I see now this change is already reflected in ColorTypes.jl). Of all those discussed, those names are the clearest to me. I also support the decisions about separating ColorVectorSpace. The relevant READMEs make it very clear what the different packages are for. Rec709 (from which sRGB derives its colour primaries) defines a 10 bit representation of colour value, where the interval 0 to 1 maps to 64 to 940. As this is a somewhat specialised use case, perhaps I should add it myself. One suggestion for an enhancement: Might it be useful to have a guide to adding additional colour space? Obviously Tim has captured many, but I know feature film cameras use different colour spaces, for example. I can't think of any other use cases, however. |
Thanks for commenting, @AndrewGibb. If you want to add The idea of adding an extension guide is a good one. |
Done. |
💯 |
I haven't had a chance yet to read through this discussion, but I'm not sure I would put colorant at the apex of the type hierarchy, as pure light sources also produce color percepts, as does pressure on the surface of the eye. Not to mention that some colors are produced without the presence of a physical stimulus (e.g., percepts of blue at the fovea). The current choice seems to put too much weight on the idea that colors are the result of surfaces alone, which is not really the case. Indeed, a colorant alone will not produce a color percept and requires the presence of an emitting light source, the choice of which can have a large influence on the perceived color, as light is essential and color is ultimately a perceptual process, rather than an external physical entity. |
This has been merged, many packages are now using it, and I am off working on other things. So at this point, anyone who wants further redesign has to do the work him/herself 😄. |
I have no problem with helping out and implementing changes, in face I am happy to do so. I just wanted to put that out there to see what people think. Best, |
Hard to say without a more concrete sketch of your idea of a redesign---my reaction could range anywhere from "great!" to "more appropriate for a LightPerception package." But glad to hear that you're willing to help make julia better, as always. |
Actually, I should have started my post with a huge thank you, rather than being pedantic, especially when I haven't been active in the Julia community for so long. So, my apologies; that was rude of me. I really like the work that has gone into the color packages since I've had a time-out. I will try to post something within the next days. I've always felt that it is unfortunate that there has been such a heavy split of color terminology over the years in industry, physiology/psychophysics, and phenomenology research. Each of these subfields shares some terminology, but not all, and it can be difficult within psychophysics/physiology, where researchers sometimes introduce new terms for concepts that phenomenologists already labeled and made clear in the past. The huge divide between the science of color and the arts also doesn't help. Best, |
In an ideal world, one would be able to:
Unfortunately, currently we are far from living in this world. It seems that the biggest problem is the separation between this package (Color) and ColorTypes.jl. I'm running into this in the course of trying to split out functionality in Images into the JuliaIO packages. Overall I agree that splitting this functionality is a good thing: for example, it would be great to largely divorce
Images.jl
from ImageMagick. The problem is that theImageMagick.jl
package started by Simon (using code lifted from Images) usesColorTypes
, whileImages
(and essentially all other packages) usesColor
, so the GL&JuliaIO world is completely incompatible with the rest of the package ecosystem.I have a proposal for fixing this, and I'm (grumpily) willing to put in the (considerable) time needed to make it happen:
FixedSizeArrays.jl
for smooth interoperability with GL. Consequently, I propose we keep his design of having a standalone ColorTypes package that only encodes the basic color type definitions, and that it be based on FixedSizeArrays.Color.jl
. We also pick names that are less awkward than our current names.Colors.jl
. We issue a deprecation warning forusing Color
.CC @lobingera, @timothyrenner, @shashi, @dcjones, @vtjnash, @stevengj, @nolta, @SimonDanisch, @jiahao. I'd like feedback from most/all of you before undertaking this course, since it will be a fair amount of work and I'd like to have some confidence that the PR I submit will be accepted.
Proposed type hierarchy sketch for the new ColorTypes:
The text was updated successfully, but these errors were encountered: