[vtkusers] volume reslice problem

David Gobbi david.gobbi at gmail.com
Fri Aug 8 09:19:05 EDT 2008


Hi Andi,

If you are concerned about memory, then use vtkImageShiftScale to
apply the window/level to the image instead of vtkImageMapToColors.

shiftscale = vtkImageShiftScale::New();
shiftscale->SetShift(0.5*window - level);
shiftscale->SetScale(255.0/window);
shiftscale->ClampOverflowOn();
shiftscale->SetOutputScalarTypeToUnsignedChar();

This will remap the pixel values to to [0,255].

  David


On Fri, Aug 8, 2008 at 8:52 AM, Andi2008 <mail-andi at web.de> wrote:
>
> Hi,
>
> thank you for the quick answer. I tried to implement that but i have
> problems with the right settings and also the use of a look up table needs a
> lot more memory. Is it normal? I change the code as follows. Can you please
> take a look over?
>
> vtkRenderer *vtk_Renderer = vtkRenderer::New();
>
> vtkWin32OpenGLRenderWindow *vtk_Win32OpenGLWindow =
> vtkWin32OpenGLRenderWindow::New();
> vtk_Win32OpenGLWindow->AddRenderer(vtk_Renderer);
>
> // m_vtkvolumedata is an vtkImageData object and contains the volume
> double *spacing = pThis->m_vtkvolumedata->GetSpacing();
> int extent[6];
> pThis->m_vtkvolumedata->GetExtent(extent);
>
> double range[2];
> pThis->m_vtkvolumedata->GetScalarRange(range);
>
> vtkLookupTable *vtk_lookuptable = vtkLookupTable::New();
> vtk_lookuptable->SetRange(range[0], range[1]); // image intensity range
> vtk_lookuptable->SetHueRange(0.0, 0.0);
> vtk_lookuptable->SetValueRange(0.0, 1.0); // from black to white
> vtk_lookuptable->SetSaturationRange(0.0, 0.0); // no color saturation
> vtk_lookuptable->SetAlphaRange(1.0, 1.0);
>
> vtk_lookuptable->SetNumberOfColors(pow((float)2, pThis->m_iGrayscale));
> vtk_lookuptable->SetRampToLinear();
> vtk_lookuptable->Build();
>
> vtkImageMapToWindowLevelColors *vtk_color_mapper =
> vtkImageMapToWindowLevelColors::New();
> vtk_color_mapper->SetLookupTable(vtk_lookuptable);
> vtk_color_mapper->SetInput(pThis->m_vtkvolumedata);
> vtk_color_mapper->SetLevel(pThis->m_dLevel);
> vtk_color_mapper->SetWindow(pThis->m_dWindow);
> vtk_color_mapper->ReleaseDataFlagOn();
>
> vtkImageReslice *vtkImageReslicer = vtkImageReslice::New();
> vtkImageReslicer->SetInput(vtk_color_mapper->GetOutput());
> vtkImageReslicer->SetOutputDimensionality(2);
> vtkImageReslicer->SetInterpolationModeToLinear();
>
> vtkImageReslicer->SetOutputSpacing(spacing);
> vtkImageReslicer->ReleaseDataFlagOn();
>
> vtkImageMapper *mapper = vtkImageMapper::New();
> mapper->SetInput(vtkImageReslicer->GetOutput());
> mapper->SetColorWindow(255.0);
> mapper->SetColorLevel(127.5);
>
> vtkActor2D *vtkactor = vtkActor2D::New();
> vtkactor->SetMapper(mapper);
>
> vtkTransform *vtk_slicetransform        = vtkTransform::New();
> vtk_Renderer->AddActor(vtkactor);
> vtk_Renderer->ResetCamera();
> vtk_Renderer->GetActiveCamera()->ParallelProjectionOn();
>
>
>
> Thanks a lot
> Andi
>
>
>
>
>
> David Gobbi-3 wrote:
>>
>> Hi Andreas,
>>
>> By default, vtkImageReslice sets the "Background" value to zero.
>> Depending on how the Window/Level are set, this might appear as grey
>> in the rendered image.
>>
>> There is an easy fix for this.  Add vtkImageMapToColors (or
>> vtkImageMapToWindowLevelColors) in front of vtkImageReslice, instead
>> of doing the Window/Level in the ImageMapper.  For the ImageMapper,
>> you will have to set ColorWindow(255.0) and ColorLevel(127.5) to
>> properly render data that has already been window/leveled.
>>
>> When you create the vtkLookupTable for vtkImageMapToColors, make sure
>> that you call this function:
>>
>> table->SetRampToLinear();
>>
>> By default, VTK uses an sigmoid ramp (i.e. S-curve) for its lookup
>> tables, which you definitely do not want for medical images.  So you
>> have to make sure to set the lookup table's ramp to linear before you
>> use it.
>>
>>     David
>>
>>
>> On Fri, Aug 8, 2008 at 5:33 AM, Andreas Brüning <mail-andi at web.de> wrote:
>>> Hello,
>>>
>>> i am writing a program to reslice a volume(stacked CT images) in any
>>> direction and angle. Therefore i choose a point in the volume where to
>>> slice through and also angles in x-,y- and z direction to define gradient
>>> of the reslicearea. I create a reslice matrix using vtkTransform and
>>> reslice the volume with a vtkImagereslice object like described in the
>>> medical examples in vtk. I would like to get the data of the resliced
>>> image but i dont know where i can get this data.
>>>
>>> The following code shows my vtk pipeline:
>>>
>>>
>>> vtkRenderer *vtk_Renderer = vtkRenderer::New();
>>>
>>> vtkWin32OpenGLRenderWindow *vtk_Win32OpenGLWindow =
>>> vtkWin32OpenGLRenderWindow::New();
>>> vtk_Win32OpenGLWindow->AddRenderer(vtk_Renderer);
>>>
>>> double *spacing = pThis->m_vtkvolumedata->GetSpacing();
>>> int extent[6];
>>> pThis->m_vtkvolumedata->GetExtent(extent);
>>>
>>> vtkImageReslice *vtkImageReslicer = vtkImageReslice::New();
>>> vtkImageReslicer->SetInput(pThis->m_vtkvolumedata);    //vtkImageData
>>> comming from vtkImport
>>> vtkImageReslicer->SetOutputDimensionality(2);
>>> vtkImageReslicer->SetInterpolationModeToLinear();
>>>
>>>
>>> vtkImageReslicer->SetOutputSpacing(spacing);
>>>  vtkImageReslicer->ReleaseDataFlagOn();
>>>
>>> vtkImageMapper *mapper = vtkImageMapper::New();
>>> mapper->SetInput(vtkImageReslicer->GetOutput());
>>> mapper->SetColorLevel(pThis->m_dLevel);
>>> mapper->SetColorWindow(pThis->m_dWindow);
>>>
>>> vtkActor2D *vtkactor = vtkActor2D::New();
>>> vtkactor->SetMapper(mapper);
>>>
>>> vtkTransform *vtk_slicetransform        = vtkTransform::New();
>>>
>>> vtk_Renderer->AddActor(vtkactor);
>>> vtk_Renderer->ResetCamera();
>>> vtk_Renderer->GetActiveCamera()->ParallelProjectionOn();
>>>
>>>
>>>  The reslicing part looks like this:
>>>
>>> vtk_slicetransform->Identity();
>>> vtk_slicetransform->Translate(pThis->m_pSliceCenter[0],
>>> pThis->m_pSliceCenter[1], pThis->m_pSliceCenter[2]); //centerpoint for
>>> reslicing
>>>
>>> vtk_slicetransform->RotateZ(pThis->m_dSliceAngle_z);
>>> vtk_slicetransform->RotateX(pThis->m_dSliceAngle_x);
>>> vtk_slicetransform->RotateY(pThis->m_dSliceAngle_y);
>>>
>>> vtkImageReslicer->SetResliceAxes(vtk_slicetransform->GetMatrix());
>>>
>>> vtkImageReslicer->UpdateInformation();
>>>
>>> vtk_Win32OpenGLWindow->Render();
>>>
>>>
>>>
>>> When i run the program and change one angle i see gray areas around the
>>> resultimage. I dont know where it comes from, but i guess they are
>>> somehow representing the rest of the volume. Does anybody know how i can
>>> only show the resultimage? When i rotate around x-axis and y-axis the
>>> gray area get really big. I checked the OutputExtend of the resliceobject
>>> after reslicing and at this time i get negative results the outcomming
>>> extent is (0,-1,0,-1,0,-1).
>>>
>>>
>>> By the way. I dont use any vtkInteractors in here because i want to run
>>> this offscreen and only use everything to reslice the volume.
>>>
>>>
>>> Thanks in advance
>>> Andi
>>> ____________________________________________________________
>>> Großes Kino für zu Hause - Kostenlos für alle WEB.DE Nutzer!
>>> Jetzt kostenlos anmelden unter http://www.blockbuster.web.de
>>>
>>> _______________________________________________
>>> 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
>>>
>> _______________________________________________
>> 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
>>
>>
>
> --
> View this message in context: http://www.nabble.com/volume-reslice-problem-tp18888796p18891311.html
> Sent from the VTK - Users mailing list archive at Nabble.com.
>
> _______________________________________________
> 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
>



More information about the vtkusers mailing list