[vtkusers] Crop plane
Martijn Steenwijk
martijnsteenwijk at gmail.com
Tue Sep 27 15:10:32 EDT 2011
Hi David,
Thanks for your suggestion. I had to play around a bit. It appears that
setting RGB as first input for vtkImageAppendComponents and setting opacity
as second input does not work (then the renderer seems to ignore the opacity
channel and just displays a fully opaque plane), but setting (unsigned
char)im as first input and then adding the opacity channel does work.
Thanks again!
Best,
Martijn
-----Original Message-----
From: David Gobbi [mailto:david.gobbi at gmail.com]
Sent: dinsdag 27 september 2011 17:03
To: martijnsteenwijk at gmail.com
Cc: vtkusers at vtk.org
Subject: Re: [vtkusers] Crop plane
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 its 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