[vtkusers] Crop plane

David Gobbi david.gobbi at gmail.com
Tue Sep 27 11:03:04 EDT 2011


Hi Martijn,

The best way to tackle the problem might be to add an alpha channel to
your image before displaying it.  Is your im_mask an 8-bit image?
Then you can try this:

- use vtkImageMapToColors and SetOutputFormatToRGB() to convert im to RGB
- use vtkImageAppendComponents to combine im and im_mask into an RGBA image

Then, when you display the image, any pixels where the mask is zero
will be transparent, and any pixels where the mask is 255 will be opaque.

 - David


On Tue, Sep 27, 2011 at 8:20 AM, Martijn Steenwijk
<martijnsteenwijk at gmail.com> wrote:
> Dear all,
>
>
>
> I have a dataset of a brain and it’s brain mask (see attached image). I
> derived the brain contour using a contour filter and would like to map the
> brain (not skull and skin) on a specific plane. I used the following code to
> generate the attached image:
>
>
>
> Inputs: im  and im_mask
>
> ---
>
>
>
> contour = vtk.vtkContourFilter()
>
> contour.SetInput(im_mask)
>
> contour.SetValue(0,0.5)
>
> contour.SetComputeNormals(0)
>
>
>
> smooth = vtk.vtkSmoothPolyDataFilter()
>
> smooth.SetInput(contour.GetOutput())
>
> smooth.SetNumberOfIterations(10)
>
> smooth.SetRelaxationFactor(0.5)
>
>
>
> plane = vtk.vtkPlane()
>
> plane.SetOrigin(im.GetCenter())
>
> plane.SetNormal(1,0,-1)
>
>
>
> cutter = vtk.vtkCutter()
>
> cutter.SetInput(im)
>
> cutter.SetCutFunction(plane)
>
> cutter.Update()
>
>
>
> cutter2 = vtk.vtkCutter()
>
> cutter2.SetInput(smooth.GetOutput())
>
> cutter2.SetCutFunction(plane)
>
> cutter2.SetGenerateCutScalars(0)
>
> cutter2.Update()
>
>
>
> … where cutter displays the plane and cutter2 (cut of contour) displays the
> red line.
>
>
>
> Is there a way to crop this plane such that a flat plane (a vtkPolyData
> object) arises which is bounded by the ‘red line’  and which can be used to
> apply a vtkProbeFilter which ‘probes’ the ‘im’ dataset such that the values
> of the original image are displayed on the cropped plane?
>
>
>
> Thanks for sharing your thoughts,
>
>
>
> With best regards,
>
> Martijn



More information about the vtkusers mailing list