Closed tknopp closed 7 years ago
Great question; I'd forgotten this as a loose end. I think a better approach is described here, but obviously I haven't implemented it. (For reference, "GFP" and "tdTomato" are names of fluorescent proteins of particular color. I was imagining a situation in which users were taking two grayscale images that captured these two channels of information.)
BTW you don't have to call StackedView
directly, see http://juliaimages.github.io/latest/conversions_views.html#Using-colorview-to-make-color-overlays-1. I should change that deprecation warning.
Ok, but the code within the deprecation is based on the new infrastructure, right? Then maybe the deprecation could simply be removed until a full alternative is available?
while I seem to get the idea of your proposed approach, in my code base I have
colortuple = (distinguishable_colors(length(images),colorant"red")...)
where images
is an array of images to be combined. So its a little bit more dynamic than in your code snipped.
Interesting. Thanks for explaining.
@timholy: I upgraded Images
package and now the Overlay
seems to be removed. Unfortunately (see above) for the way I used it there is still no replacement.
Can you lay out a spec of your exact needs? Is it just that you want to assign a specific RGB color value to each channel? I think you can do this:
julia> using StaticArrays, MappedArrays, Colors, ColorVectorSpace
julia> a = rand(2, 3, 5);
julia> b = reinterpret(SVector{2,Float64}, a, (3, 5))
3×5 Array{SVector{2,Float64},2}:
[0.0916688, 0.767672] [0.533447, 0.745838] [0.626199, 0.974785] [0.0865907, 0.223772] [0.565332, 0.616537]
[0.247969, 0.809979] [0.81957, 0.484365] [0.873802, 0.257433] [0.808143, 0.192257] [0.152572, 0.191004]
[0.0444801, 0.452599] [0.717806, 0.702905] [0.407974, 0.611004] [0.278851, 0.862654] [0.0481439, 0.491182]
julia> f(x) = x[1]*RGB(1,0.2,0.4) + x[2]*RGB(0.2,0.5,0.5)
f (generic function with 1 method)
julia> c = mappedarray(f, b)
3×5 MappedArrays.ReadonlyMappedArray{ColorTypes.RGB{Float64},2,Array{SVector{2,Float64},2},#f}:
RGB{Float64}(0.245203,0.40217,0.420504) RGB{Float64}(0.682615,0.479608,0.586298) RGB{Float64}(0.821156,0.612632,0.737872) RGB{Float64}(0.131345,0.129204,0.146522) RGB{Float64}(0.68864,0.421335,0.534401)
RGB{Float64}(0.409964,0.454583,0.504177) RGB{Float64}(0.916443,0.406096,0.570011) RGB{Float64}(0.925289,0.303477,0.478237) RGB{Float64}(0.846595,0.257757,0.419386) RGB{Float64}(0.190773,0.126016,0.156531)
RGB{Float64}(0.135,0.235196,0.244092) RGB{Float64}(0.858387,0.495014,0.638575) RGB{Float64}(0.530174,0.387097,0.468691) RGB{Float64}(0.451382,0.487097,0.542867) RGB{Float64}(0.14638,0.25522,0.264849)
and it will be oh-so-much-more performant and sensible than the old Overlay
type. That said, if this is too many steps, maybe we can talk about something to simplify it?
is the first dim of a
here now the "channel" dim?
If yes this seems exactly what I want and no these are not too many steps (many thanks!). I have to maintain some legacy code where Overlay
has been used and just want it to work (independent how the code looks ;-) )
I will close once I have verified that this works.
is the first dim of a here now the "channel" dim?
Yes, sorry I didn't state that clearly.
It occurs to me that there's no reason we couldn't have a function in Images which does these steps. If you get something that you like, care to contribute it? Or I can do it myself; sorry I didn't tackle this earlier.
sorry I didn't tackle this earlier.
don't worry. stability / maintenance of Images infrastructure of an extremely good quality! There simply must be several Tim Holys under your account ;-)
works like a charm. I will close this therefore. Either adding a convenience function or make an example in the documentation would make this example more accessible. Sorry, but right know I cannot contribute (grant writing mode, ya know...)
The Overlay deprecation says:
I read through the documentation but
colorview
seems to be restricted to setting thergb
channels. The Overlay type allowed to set arbitrary colors to each channels. Will this functionality be removed?