[vtkusers] Where's my Reslice?
Jothy
jothybasu at gmail.com
Tue Apr 27 15:34:38 EDT 2010
This is an ugly python code, but may be usefull
def slice(ImageSet,Orientation,slice,window,grayscale):
# reader is the input VTK volume
# Calculate the center of the volume
#ImageSet.UpdateInformation()
(xMin, xMax, yMin, yMax, zMin, zMax) = ImageSet.GetWholeExtent()
(xSpacing, ySpacing, zSpacing) = ImageSet.GetSpacing()
(x0, y0, z0) = ImageSet.GetOrigin()
center = [x0 + xSpacing * 0.5 * (xMin + xMax),
y0 + ySpacing * 0.5 * (yMin + yMax),
z0 + zSpacing * 0.5 * (zMin + zMax)]
# Matrices for axial, coronal, sagittal, oblique view orientations
axial = vtk.vtkMatrix4x4()
axial.DeepCopy((1, 0, 0,center[0] ,
0, 1, 0,center[1] ,
0, 0, 1, slice,
0, 0, 0, 1))
sagittal = vtk.vtkMatrix4x4()
sagittal.DeepCopy((0, 0,-1, slice,
1, 0, 0, center[1],
0,-1, 0,center[2] ,
0, 0, 0, 1))
coronal = vtk.vtkMatrix4x4()
coronal.DeepCopy((1, 0, 0, center[0],
0, 0, 1, slice,
0,-1, 0, center[2],
0, 0, 0, 1))
oblique = vtk.vtkMatrix4x4()
oblique.DeepCopy((1, 0, 0, center[0],
0, 0.866025, -0.5, center[1],
0, 0.5, 0.866025, center[2],
0, 0, 0, 1))
# Extract a slice in the desired orientation
reslice = vtk.vtkImageReslice()
reslice.SetInput(ImageSet)
reslice.SetOutputDimensionality(2)
reslice.SetResliceAxesOrigin(10,20,20)
if Orientation=='axial':
reslice.SetResliceAxes(axial)
elif Orientation=='sagittal':
reslice.SetResliceAxes(sagittal)
elif Orientation=='coronal':
reslice.SetResliceAxes(coronal)
reslice.SetInterpolationModeToCubic()
# Create a greyscale lookup table
table = vtk.vtkLookupTable()
table.SetRange(grayscale) # image intensity range
table.SetValueRange(0, 1.0) # from black to white
table.SetSaturationRange(0.0, 0.0) # no color saturation
table.SetRampToSCurve()
table.SetNumberOfTableValues(402)
table.Build()
# Map the image through the lookup table
color = vtk.vtkImageMapToColors()
color.SetLookupTable(table)
color.SetInputConnection(reslice.GetOutputPort())
# Display the image
actor = vtk.vtkImageActor()
actor.SetInput(color.GetOutput())
renderer = vtk.vtkRenderer()
renderer.AddActor(actor)
ctv=vtk.vtkSphereSource()
ctv.SetRadius(100)
ctv.SetThetaResolution(100)
ctv.SetPhiResolution(100)
sphereMapper=vtk.vtkPolyDataMapper()
sphereMapper.SetInputConnection(ctv.GetOutputPort())
sp=vtk.vtkPlane()
sp.SetOrigin(0,0,10)
sp.SetNormal(0,0,1)
cutter=vtk.vtkCutter()
cutter.SetCutFunction(sp)
cutter.SetInput(sphereMapper.GetInput())
cutter.Update()
cmapper=vtk.vtkPolyDataMapper()
cmapper.SetInputConnection( cutter.GetOutputPort())
cmapper.ScalarVisibilityOff()
sphereActor=vtk.vtkActor()
sphereActor.GetProperty().SetColor(1.0,1,0)
sphereActor.GetProperty().SetLineWidth(3)
sphereActor.GetProperty().SetEdgeColor(1,1,0.5)
sphereActor.GetProperty().SetAmbient(1)
sphereActor.GetProperty().SetDiffuse(0)
sphereActor.GetProperty().SetSpecular(0)
sphereActor.SetMapper(cmapper)
renderer.AddActor(sphereActor)
#renderer.SetColorWindow (900)
#renderer.SetColorLevel (-100)
#window = vtk.vtkRenderWindow()
#renderer.GetActiveCamera().Zoom(1.1)
window.GetRenderWindow().AddRenderer(renderer)
renwin=window.GetRenderWindow()
# Set up the interaction
interactorStyle = vtk.vtkInteractorStyleImage()
interactor = vtk.vtkRenderWindowInteractor()
## interactor.SetInteractorStyle(interactorStyle)
renwin.GetRenderWindow().SetInteractor(QVW.QVTKRenderWindowInteractor)
renwin.Render()
Jothy
On Tue, Apr 27, 2010 at 8:30 PM, Eric E. Monson <emonson at cs.duke.edu> wrote:
> Hey Scott,
>
> I'm not an expert on this, (and you didn't describe what you had to put in your vtkImageChangeInformation to see the other views), but it sounds a bit like maybe there's just something wrong with how you're specifying your transform to get your slice, so you're not really slicing through where you think you are. The output of the reslice filter should just be an image (i.e. a vtkImageData which is only 1-deep, so it's flat like an image instead of what you'd think of as a volume).
>
> Have you taken a look at this example? [vtk_source]/Examples/ImageProcessing/Cxx/ImageSlicing.cxx (or its Python or Tcl equivalent)
>
> That one shows very nicely how to specify a 4x4 matrix which controls the slice axis (set with reslice->SetReliceAxes(resliceAxes) ), and uses a vtkImageActor and standard vtkRenderWindow to display the image. If you haven't, maybe you can at least play with those methods and see if they make any difference.
>
> -Eric
>
>
> On Apr 27, 2010, at 3:08 PM, Scott Johnson wrote:
>
>> It was my understanding that those allow the plane orientation to be manipulated and display the plane in space. I want the 2D result of the reslice to be presented to the user as a 2D image and then allow them to step through the slices. I don't want them to be able to change the orientation. I'm determining the orientation based on a fiducial.
>>
>> Can I turn off the plane manipulation and fix the display orientation toward the user? I'll look at vtkImagePlaneWidget a bit more.
>>
>> I'm not finding the documentation for vtkImagePlaneWidget2 at http://www.vtk.org/doc/nightly/html/annotated.html. Is it somewhere else?
>>
>> Thanks
>>
>> -- Scott
>>
>> -----Original Message-----
>> From: Jothy [mailto:jothybasu at gmail.com]
>> Sent: Tuesday, April 27, 2010 1:44 PM
>> To: Scott Johnson
>> Cc: vtkusers at vtk.org
>> Subject: Re: [vtkusers] Where's my Reslice?
>>
>> Either you use vtkImagePlaneWidget or vtkImageplaneWidget2 and get
>> their output to display on axial,sagittal,coronal.
>>
>> Jothy
>>
>> On Tue, Apr 27, 2010 at 7:35 PM, Scott Johnson
>> <Scott.Johnson at neuwave.com> wrote:
>>> Thanks Jothy,
>>>
>>> I'm going to extend the display to oblique angles of the plane. I need the full transform to do that. I'm just using sagittal and coronal to get me started.
>>>
>>> -- Scott
>>>
>>> -----Original Message-----
>>> From: Jothy [mailto:jothybasu at gmail.com]
>>> Sent: Tuesday, April 27, 2010 12:28 PM
>>> To: Scott Johnson
>>> Cc: vtkusers at vtk.org
>>> Subject: Re: [vtkusers] Where's my Reslice?
>>>
>>> Hi Scott,
>>>
>>> You don't need to use the transform for displaying the sagittal and
>>> coronal views. Just set SetSliceOrientationToYZ &
>>> SetSliceOrientationToXZ and set slice.
>>>
>>> Jothy
>>>
>>> On Tue, Apr 27, 2010 at 6:20 PM, Scott Johnson
>>> <Scott.Johnson at neuwave.com> wrote:
>>>> Hi Folks,
>>>>
>>>>
>>>>
>>>> I'm trying to display image planes in a vtkImageViewer2 without much luck.
>>>> My current pipeline looks like:
>>>>
>>>>
>>>>
>>>> vtkTransform
>>>>
>>>> |
>>>>
>>>> V
>>>>
>>>> vtkDICOMImageReader->vtkImageReslice->vtkImageViewer2
>>>>
>>>>
>>>>
>>>> If I try to display an Axial slice, it works fine, if I try to display
>>>> sagittal or coronal slices I don't see the images. If I insert a
>>>> vtkImageChangeInformation object after the vtkDICOMImageReader, I can see
>>>> the sagittal and coronal images as well as the axial. This causes a problem
>>>> because I am trying to coordinate other displays with the resliced result.
>>>> I need to see the images without using the vtkImageChangeInformation object.
>>>>
>>>>
>>>>
>>>> I've tried to explicitly set the bounds on the vtkImageActor managed by the
>>>> vtkImageViewer2, with no luck. I've also tried to place the vtkCamera to
>>>> point at the center of the plane along the direction of the normal. Didn't
>>>> work either.
>>>>
>>>>
>>>>
>>>> There may be a fundamental misunderstanding on my part as to how
>>>> vtkImageReslice works. I am assuming that the resulting resliced volume
>>>> would be displayed the same as an axial image, so I am leaving the
>>>> vtkImageViewer2->SetSliceOrientationXY() and moving between slices with the
>>>> SetSlice method.
>>>>
>>>>
>>>>
>>>> The eventual goal is to reslice the image volume at oblique angles, but I
>>>> figure I'm on the right track if I can get the sagittal and coronal images
>>>> to display correctly.
>>>>
>>>>
>>>>
>>>> I'm concerned that vtkImageViewer2 is doing something for me that I don't
>>>> want it to do. Do I need to manage my own vtkImageActor?
>>>>
>>>>
>>>>
>>>> A code snippet for the Coronal images follows:
>>>>
>>>> (input is the vtkDICOMImageReader)
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> _transform = vtkTransform::New();
>>>>
>>>> _transform->RotateZ(0.0);
>>>>
>>>> _transform->RotateX(90.0);
>>>>
>>>> _transform->RotateY(0.0);
>>>>
>>>>
>>>>
>>>> _reslice = vtkImageReslice::New();
>>>>
>>>> _reslice->SetOutputDimensionality(3);
>>>>
>>>> _reslice->SetResliceTransform(_transform);
>>>>
>>>> _reslice->SetInputConnection(input);
>>>>
>>>> _reslice->Update();
>>>>
>>>>
>>>>
>>>> inputData=vtkImageData::SafeDownCast(_reslice->GetInput());
>>>>
>>>> inputData->GetCenter(center);
>>>>
>>>> _transform->Translate(center[0], center[1], center[2]);
>>>>
>>>>
>>>>
>>>> _interactor = vtkRenderWindowInteractor::New();
>>>>
>>>>
>>>>
>>>> _imageViewer = vtkImageViewer2::New();
>>>>
>>>> _imageViewer->SetupInteractor(_interactor);
>>>>
>>>> _imageViewer->SetSize(400, 400);
>>>>
>>>> _imageViewer->SetColorWindow(1024);
>>>>
>>>> _imageViewer->SetColorLevel(800);
>>>>
>>>> _imageViewer->SetInputConnection(_reslice->GetOutputPort());
>>>>
>>>>
>>>>
>>>> Any ideas appreciated.
>>>>
>>>>
>>>>
>>>> Thanks
>>>>
>>>>
>>>>
>>>> -- Scott
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> 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
>>>>
>>>>
>>>
>> _______________________________________________
>> 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