[vtkusers] best way to clip vtkImageData using vtkPloyData

David Gobbi david.gobbi at gmail.com
Fri Jul 16 12:38:42 EDT 2010


In vtkImageBlend, you need to have two inputs or else the filter will
do nothing.  The first input to vtkImageBlend is the background image,
and the second inputs is pasted on top of the first image, using the
stencil to specify a cut-out region.

So if you want to make several colored regions, you need to have
several solid-colored images to start with, and then paste each one on
top of your background using the proper stencil for that color.  Use
several vtkImageBlend filters in a chain, each one will add another
colored region to the image.

You can create a solid-colored image by creating a vtkLookupTable that
has just one color, and pass an input image of the desired sized
through vtkImageMapToColors to map the image to that color.  For the
background, you can either use your original image (mapped to RBG so
that other images can be blended on top of it), or you can use a black
image created by mapping your original image through a black lookup
table.

   David


On Thu, Jul 15, 2010 at 11:05 PM, Prathamesh Kulkarni
<prathameshmkulkarni at gmail.com> wrote:
> I managed to add more than one stencils by using the
> combined_vtkImageStencilData->Add(new_vtkImageStencilData) and then setting
> vtkImageStencil->AddStencil(combined_vtkImageStencilData);
> However, I have not been able to figure out a way to set the foreground
> color of any stencil to a given value. The aim is to show every stencil with
> a different color in the vtkImageData (= vtkImageStencil->GetOutput()).
> Any help will be highly appreciated.
>
> Thanks,
> Prathamesh
> On Thu, Jul 15, 2010 at 6:52 PM, Prathamesh Kulkarni
> <prathameshmkulkarni at gmail.com> wrote:
>>
>> I managed use vtkImageStencil and vtkImageAccumulate, but could not get a
>> proper blended image output with vtkImageBlend. Following is my code snippet
>> for vtkImageBlend:
>>
>>         blended_image->SetInput(image_data);
>>         blended_image->SetStencil(image_stencil_data);
>>
>>         blended_image->SetOpacity(1, opacity)
>>         blended_image->Update();
>>
>> When I try to render blended_image->GetOutput(), I simply get the input
>> image, as if setting the stencil had no effect. I expected to see a
>> different opacity in the stencil region. Please tell me if I am missing
>> anything here.
>>
>>
>> Also, I was wondering how to add multiple stencils to vtkImageStencil so
>> that at the output I can have a vtkImageData showing multiple stencils with
>> different colors.
>>
>> In any case, I did not understand how to set the foreground color of a
>> single stencil.
>>
>>
>>
>> Sorry for putting in 3 questions together.. Thanks for your answers in
>> advance.
>>
>>
>> Prathamesh
>>
>>
>> On Wed, Jul 14, 2010 at 5:31 PM, David Gobbi <david.gobbi at gmail.com>
>> wrote:
>>>
>>> Hi Prathamesh,
>>>
>>> You should use either vtkClipVolume or vtkImageStencil, based on what
>>> you want as an output. The vtkClipVolume filter will output an
>>> unstructured grid, i.e. it will produce a geometric data set
>>> consisting of voxel cells (each voxel cell will be a little cube with
>>> eight points at its corners).  If you want the output to be an actual
>>> image, with the background set to black or to transparent, then you
>>> should use vtkImageStencil.
>>>
>>> In either case, the best place to start is vtkImplicitLoop, which
>>> takes a contour and produces an "implicit function", which in
>>> VTK-speak, is a function used to define the inside vs. the outside of
>>> a selection area.  Then the vtkImplicitLoop can be used as an input to
>>> vtkImplicitFunctionToImageStencil.  The output of
>>> vtkImplicitFunctionToImageStencil can then be used as an input to e.g.
>>> vtkImageBlend (for pasting a cut-out image onto another image),
>>> vtkImageStencil (for blacking out the non-selected region of the
>>> image), or vtkImageAccumulate (for computing the average value,
>>> standard deviation, or the histogram of the image area inside the
>>> stencil).
>>>
>>>   David
>>>
>>>
>>>
>>>
>>> On Wed, Jul 14, 2010 at 4:13 PM, Prathamesh Kulkarni
>>> <prathameshmkulkarni at gmail.com> wrote:
>>> >
>>> > Hello all,
>>> >
>>> > I want to extract a sub-image from vtkImageData given a closed set of
>>> > points
>>> > forming any arbitrary shape (may be a vtkPolyData).
>>> >
>>> > I have been looking at vtk classes like vtkClipVolume, vtkExtractVOI,
>>> > vtkImageStencil. I am no able to understand which way should be
>>> > preferred
>>> > over which to do my task. Also, I am not able to figure out the exact
>>> > pipeline structure for these clipping methods.
>>> >
>>> > Could someone please throw some light on this?
>>> >
>>> > Thanks,
>>> > Prathamesh
>>> >
>>> > _______________________________________________
>>> > Powered by www.kitware.com
>>> >
>>> > Visit other Kitware open-source projects at
>>> > http://www.kitware.com/opensource/opensource.html
>>> >
>>> > Please keep messages on-topic and check the VTK FAQ at:
>>> > http://www.vtk.org/Wiki/VTK_FAQ
>>> >
>>> > Follow this link to subscribe/unsubscribe:
>>> > http://www.vtk.org/mailman/listinfo/vtkusers
>>> >
>>> >
>>
>
>



More information about the vtkusers mailing list