On Monday, November 16, 2015 09:10:21 AM Tobias Knopp wrote:
> It seems in the case of alpha blending there are some missing parts. I
> still do not get how the "Overlay" functions work without an alpha channel
> but I will try to understand it.

The "Overlay" functions are barely any more sophisticated than this (and in 
fact I almost implemented them this way, then decided to try to make them a 
little more flexible):

# generate a green/magenta image from two grayscale channels
imgout[1, : , :] = img1   # magenta = red + blue
imgout[3, :,  :] = img1
imgout[2, :,  :] = img2   # the green channel
imgoutc = reinterpret(RGB{T}, imgout)

This requires no alpha blending or anything.

> And yes I mean that kind of interpolation. If have implemented now a
> function
> 
>   colorize{T<:Colorant}(x::Real,wmin::Real,wmax::Real,cmap::Vector{T})
> 
> that takes as input a real value and two window parameters that are mapped
> to a certain color. And since the Colors.jl package has only RGB colormaps
> I have additionally implemented RGBA colormaps. I am currently not sure if
> this would fit into the existing package infrastructure...

Colors.jl has "only RGB colormaps" in the sense that perhaps no one has 
written convenience functions to _generate_ a colormap with an alpha channel. 
But since we're talking about a Vector{C} with C<:Colorant rather than 
C<:Color, the generalization is very natural.

I would definitely say that what you're doing belongs in those packages. As 
always it just comes down to what people have needed and what they've bothered 
to implement.

--Tim


> 
> Cheers,
> 
> Tobias
> 
> Am Montag, 16. November 2015 12:39:30 UTC+1 schrieb Tim Holy:
> > On Monday, November 16, 2015 02:25:43 AM Tobias Knopp wrote:
> > > After investigating this a little further I found that the key things I
> > > am/was missing are:
> > > - How to compose two RGBA values a and b. It turns out that this is the
> > > "over" operation given by
> > > 
> > >   c = alpha*b + (1-alpha)*a
> > > 
> > > if alpha is the alpha channel of b and a has alpha=1. Do I have missed
> > 
> > it
> > 
> > > or is the over operation somewhere implemented in a package?
> > 
> > I'm not aware of a package that implements alpha-compositing. Perhaps it
> > could
> > be added to ColorVectorSpace (which might then need a new name), or
> > perhaps
> > better it could be its own package. If you're interested in this, I'd
> > recommend starting by creating a type that makes it clear whether you're
> > working with pre-multiplied alpha or not, see
> > https://en.wikipedia.org/wiki/Alpha_compositing#Description
> > 
> > > - The second thing is colormaps that include an alpha channel. This
> > 
> > allows
> > 
> > > to overlay data in a very flexible way. Otherwise its not really clear
> > 
> > how
> > 
> > > to compose things
> > 
> > ImageCmap lets you define a colormap that includes an alpha channel, but
> > it
> > doesn't implement any special operations.
> > 
> > > - The third is: given a colormap, how to interpolate into it (+ window
> > > level, window brightness).
> > 
> > Not quite sure what you mean, are you asking if you can have a fractional
> > value that lies between two points in the colormap? If the operations you
> > want
> > to implement can be expressed in terms of + and * via the standard rules
> > of
> > interpolation, this one should be easy :-): just use Interpolations.jl to
> > create the colormap vector, e.g.,
> > 
> >     icmap = interpolate(cmap, BSpline(Linear()))
> > 
> > and pass that to ImageCmap. We can easily generalize it to allow an
> > AbstractVector.
> > 
> > Note that currently img[i,j] for an ImageCmap returns the index, not the
> > color
> > value. I don't remember why I did it that way, but I think that's
> > something
> > that will have to change. Just need to think of the right migration
> > strategy.
> > 
> > Best,
> > --Tim
> > 
> > > Cheers,
> > > 
> > > Tobias
> > > 
> > > Am Donnerstag, 12. November 2015 21:54:18 UTC+1 schrieb Tim Holy:
> > > > On Thursday, November 12, 2015 12:15:46 PM Tobias Knopp wrote:
> > > > > Thanks Tim, I tried to look into the code of Overlay but it wasn't
> > 
> > to
> > 
> > > > clear
> > > > 
> > > > > to me. In particular I am missing where the RGB(A) data is combined.
> > > > 
> > > > Here:
> > https://github.com/timholy/Images.jl/blob/cac28026250814f6ae6594dd26e92707
> > 
> > > > 6177db60/src/overlays.jl#L60-L67>
> > > > 
> > > > > Is it
> > > > > really as simple as adding the individual RGB values and preventing
> > > > > overflow by clamp?
> > > > 
> > > > Yes.
> > > > 
> > > > > Or is there some infrastructure for color mixing in Colors.jl
> > > > 
> > > > There is, but it's considerably slower. See the ColorVectorSpace.jl
> > 
> > README
> > 
> > > > for
> > > > discussion.
> > > > 
> > > > > I further looked for functions for gray value mapping
> > > > 
> > > > (Contrast/Brightness)
> > > > 
> > > > > in Colors.jl but could not find anything. This is of course not
> > > > 
> > > > complicated
> > > > 
> > > > > to code but I don't want to miss an existing solution.
> > > > 
> > > > The whole "MapInfo" structure is a very flexible and powerful. Search
> > 
> > for
> > 
> > > > it on
> > > > this page:
> > > > http://timholy.github.io/Images.jl/function_reference.html
> > > > From my standpoint, the best feature is that it's "lazy": you specify
> > 
> > the
> > 
> > > > transformation you want, but don't execute it until you need it. For
> > > > people
> > > > like me who routinely browse 1TB images but probably look at <1% of
> > 
> > the
> > 
> > > > raw
> > > > data in any given dataset (and who also don't have 1TB worth of
> > 
> > RAM...),
> > 
> > > > this
> > > > is quite an advantage.
> > > > 
> > > > In my own work, I pretty routinely design custom MapInfo types/map
> > > > functions
> > > > for visualization purposes. For example, I can color individual blobs
> > 
> > in
> > 
> > > > each
> > > > frame of a movie with something along the lines of
> > > > 
> > > > immutable ColorizeBlobs
> > > > 
> > > >     blobpixels::Vector   # of length nblobs
> > > >     blobcolors::Vector{RGB{U8}}  # color assigned to each blob
> > > > 
> > > > end
> > > > 
> > > > and passing that to ImageView using the "scalei" keyword argument (a
> > > > legacy of
> > > > the days when this was called ScaleInfo rather than MapInfo). It's a
> > 
> > nice
> > 
> > > > way
> > > > of getting custom visualization while leaving all the stupid zoom &
> > > > navigation
> > > > functionality up to ImageView.
> > > > 
> > > > --Tim
> > > > 
> > > > > Tobi
> > > > > 
> > > > > Am Donnerstag, 12. November 2015 16:42:00 UTC+1 schrieb Tim Holy:
> > > > > > Probably the easiest thing would be to just extend the code in
> > 
> > Images
> > 
> > > > and
> > > > 
> > > > > > submit a PR (the code is not very complicated).
> > > > > > 
> > > > > > However, you can do very fancy things with MapInfo objects. This
> > 
> > is
> > 
> > > > > > untested,
> > > > > > but it should be close:
> > > > > > 
> > > > > > immutable TwoColormap <: MapInfo
> > > > > > 
> > > > > >     colormap1
> > > > > >     colormap2
> > > > > > 
> > > > > > end
> > > > > > 
> > > > > > function map!(dest, mapi::TwoColormap,
> > > > > > src::Tuple{AbstractArray,AbstractArray})
> > > > > > 
> > > > > >     img1, img2 = src
> > > > > >     for I in eachindex(dest)
> > > > > >     
> > > > > >         dest[I] = clamp(RGBmapi.colormap1[img1[I]] +
> > > > > > 
> > > > > > mapi.colormap2[img2[I]])
> > > > > > 
> > > > > >     end
> > > > > >     dest
> > > > > > 
> > > > > > end
> > > > > > 
> > > > > > --Tim
> > > > > > 
> > > > > > On Thursday, November 12, 2015 07:23:07 AM Tobias Knopp wrote:
> > > > > > > Hi,
> > > > > > > 
> > > > > > > I am using the OverlayImage type from the Images.jl package to
> > > > 
> > > > overlay
> > > > 
> > > > > > two
> > > > > > 
> > > > > > > different grayscale images (tomographic data).
> > > > > > > If I understand it correctly OverlayImage is restricted to
> > 
> > colormaps
> > 
> > > > > > that
> > > > > > 
> > > > > > > go from black to a certain RGB value. Has anybody an idea how
> > 
> > this
> > 
> > > > could
> > > > 
> > > > > > be
> > > > > > 
> > > > > > > extended to Colormaps provided by Colors.jl?
> > > > > > > 
> > > > > > > So my need is:
> > > > > > > Input: two 3D datasets (FloatingPoint) + two Colormaps +
> > 
> > WindowWidth
> > 
> > > > > > > WindowLevel for each
> > > > > > > Output: Combined 3D dataset as RGBA values.
> > > > > > > 
> > > > > > > Thanks
> > > > > > > 
> > > > > > > Tobias

Reply via email to