[vtkusers] Setting individual pixel's opacity.

Sandarak sandarak at wp.pl
Fri May 20 06:46:47 EDT 2005


Hi David,

I did something like that:

  vtkImageShiftScale *shiftScaler = vtkImageShiftScale::New();

  shiftScaler->SetInput( inputImage );
  shiftScaler->SetScale(255);
  shiftScaler->ClampOverflowOn();
  shiftScaler->Update();

  vtkImageAppendComponents *imageAppend = vtkImageAppendComponents::New();
  
  imageAppend->AddInput( inputImage );
  imageAppend->AddInput( shiftScaler->GetOutput() );
  imageAppend->Update();


But I must be missing something because I'm only getting black pixels
where i expect transparent ones.

Whole source file is in the attachment.

Michal



> Hi Michal,

> Don't use vtkImageMask.  It doesn't do what you want.

> You want to set opacity on a pixel-by-pixel basis, which
> means that you have to append an alpha component to your
> image.  The best way to do this is to use vtkImageAppendComponents.
> The first input to vtkImageAppendComponents is your image, and
> the second input is an alpha image.  The pixels in the alpha image
> should have a value of zero where you want transparent pixels,
> and 255 where you want opaque pixels.

>  - David

> Sandarak wrote:

>>Hi David,
>>
>>Thank you for answer.
>>
>>What should I do when I create alpha mask for my
>>Image?
>>
>>I've tried to use vtkImageMask and it's SetMaskAlpha method.
>>But when I'm setting this method to 1 I'm getting mask image
>>pixel visible, and setting 0 makes original image pixel visible.
>>Thus this doesn't make those pixels opaque, but only the mask is
>>opaque.
>>
>>Michal
>>
>>
>>  
>>
>>>Hi Michal,
>>>    
>>>
>>
>>  
>>
>>>Since your image is VTK_UNSIGNED_CHAR, you can use
>>>vtkImageAppendComponents to append an alpha mask to your image.
>>>To create the alpha mask, you could send your image through
>>>vtkImageShiftScale with a "Scale" value of 255 and with "ClampOverflow" on.
>>>That way all the mask pixels will be zero where your image is zero,
>>>and 255 where your image is nonzero.
>>>    
>>>
>>
>>  
>>
>>> - David
>>>    
>>>
>>
>>  
>>
>>>Sandarak wrote:
>>>    
>>>
>>
>>  
>>
>>>>Hello!
>>>>
>>>>Is it possible in VTK to set individual pixel's opacity in the image?
>>>>Or is it possible to set opacity to pixels with the same value?
>>>>
>>>>I'm working with an image of VTK_UNSIGNED_CHAR type and I would like
>>>>to set pixels with values 0  to be complately opaque, but I want to
>>>>have all other pixles visible.
>>>>
>>>>I know that there is vtkLookupTable and I can use SetAlphaRange
>>>>method. But it doesn't solve the problem.
>>>>
>>>>Thanks in advance
>>>>
>>>>Michal
>>>>
>>>>
>>>>_______________________________________________
>>>>This is the private VTK discussion list. 
>>>>Please keep messages on-topic. Check the FAQ at:
>>>>http://www.vtk.org/Wiki/VTK_FAQ
>>>>Follow this link to subscribe/unsubscribe:
>>>>http://www.vtk.org/mailman/listinfo/vtkusers
>>>>
>>>> 
>>>>
>>>>      
>>>>
>>
>>
>>
>>
>>  
>>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: opacity.cxx
Type: application/octet-stream
Size: 2719 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20050520/72bcf71f/attachment.obj>


More information about the vtkusers mailing list