[vtkusers] efficient way to set opacity pixelwise?

David Gobbi david.gobbi at gmail.com
Tue May 31 16:55:55 EDT 2016


Hi Chen,

The easiest way to set the opacity according to the pixel value is to do it
with
the lookup table.  For example, to make dark pixels transparent and bright
pixels opaque, build an alpha ramp:

table->SetAlphaRange(0.0, 1.0);
table->Build();

Or you can use a for() loop to build the table with SetTableValue(i,
r,g,b,a)
with a different "a" for each table entry.

 - David


On Tue, May 31, 2016 at 2:40 PM, hchen <hjchen.work at gmail.com> wrote:

> Hello,
>
> Does anyone know if there is an efficient way of setting opacity pixelwise,
> eg. using luminance of a pixel for its opacity?
>
> I am writing an application where I need to overlay a few images (eg, a
> slice of CT, and then a few planned and measured doses, the doses have a
> lot
> zeros), I have been using SetOpacity in vtkImageBlend or vtkImageProperty,
> it works OK, but it feels like the more layers displayed, the duller the
> bottom layers becomes. So, I am trying to set opacity for layers( except
> the
> bottom one ) according their pixel value to see if it will do better. As
> for
> now, I first use vtkImageMapToColors to convert to RGBA, then loop through
> each pixel using SetComponent in vtkArrayData to set opacity pixelwise. The
> program is written in python, so the looping is not particularly efficient.
>
> If anyone knows a better way of setting opacity on a per-pixel base, I
> would
> appreciate a lot!
>
> Thanks!
>
> Chen
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160531/0cedda91/attachment.html>


More information about the vtkusers mailing list