使用 vtk 调整 dicom 文件中的 window 级别
adjust window level in dicom file using vtk
我正在尝试更改图像 window 宽度和级别。
我知道我需要创建 vtkWindowLevelLookupTable。
并将其附加到映射器。就像描述的那样 here.
我不明白这个映射器是从哪里来的,它的输入连接是什么。
我的代码:
_reader2 = vtkDICOMImageReader.New();
_reader2.SetDirectoryName(path);
_reader2.Update();
// Visualize
_ImageViewer2 = vtkImageViewer2.New();
_ImageViewer2.SetInputConnection(_reader2.GetOutputPort());
var image = _ImageViewer2.GetInput();
// get range of slices (min is the first index, max is the last index)
_ImageViewer2.GetSliceRange(ref _MinSlice2, ref _MaxSlice2);
this.vScrollBar2.Maximum = _MaxSlice2 + 1 + vScrollBar2.LargeChange - 1;
Debug.WriteLine("slices range from : " + _MinSlice2.ToString() + " to " + _MaxSlice2.ToString());
vtkRenderWindow renderWindow = renderWindowControl2.RenderWindow;
_interactorStyle2 = vtkInteractorStyleImage.New();
_interactorStyle2.MouseWheelForwardEvt += new vtkObject.vtkObjectEventHandler(interactor_MouseWheelForwardEvt2);
_interactorStyle2.MouseWheelBackwardEvt += new vtkObject.vtkObjectEventHandler(interactor_MouseWheelBackwardEvt2);
renderWindow.GetInteractor().LeftButtonPressEvt += new vtkObject.vtkObjectEventHandler(renderWindowControl2_Click);
renderWindow.GetInteractor().SetInteractorStyle(_interactorStyle2);
renderWindow.GetRenderers().InitTraversal();
vtkRenderer ren;
while ((ren = renderWindow.GetRenderers().GetNextItem()) != null)
ren.SetBackground(0.0, 0.0, 0.0);
_ImageViewer2.SetRenderWindow(renderWindow);
_ImageViewer2.GetRenderer().AddActor2D(sliceStatusActor);
_ImageViewer2.GetRenderer().AddActor2D(usageTextActor);
_ImageViewer2.SetSlice(_MinSlice2);
// Compute a simple window/level based on scalar range
vtkWindowLevelLookupTable wlLut = new vtkWindowLevelLookupTable();
double range = _reader2.GetOutput().GetScalarRange()[1] - _reader2.GetOutput().GetScalarRange()[0];
double level = (_reader2.GetOutput().GetScalarRange()[1] +
_reader2.GetOutput().GetScalarRange()[0]) / 2.0;
wlLut.SetWindow(1000);
wlLut.SetLevel(-1000);
// Create a mapper and actor.
vtkDataSetMapper mapper = new vtkDataSetMapper();
mapper.SetInputConnection(_reader2.GetOutputPort());
mapper.SetLookupTable(wlLut);
// mapper.SetScalarRange(0, 255);
vtkActor actor = new vtkActor();
var actors = _ImageViewer2.GetRenderer().GetActors();
actor.SetMapper(mapper);
// Add the actors to the scene
_ImageViewer2.GetRenderer().AddActor(actor);
_ImageViewer2.Render();
vtkImageViewer2
已经实现了 Window/Level 功能。
您可以像这样访问它:
myImageViewer2.GetWindowLevel().SetWindow(1000);
myImageViewer2.GetWindowLevel().SetLevel(-1000);
我正在尝试更改图像 window 宽度和级别。
我知道我需要创建 vtkWindowLevelLookupTable。 并将其附加到映射器。就像描述的那样 here.
我不明白这个映射器是从哪里来的,它的输入连接是什么。 我的代码:
_reader2 = vtkDICOMImageReader.New();
_reader2.SetDirectoryName(path);
_reader2.Update();
// Visualize
_ImageViewer2 = vtkImageViewer2.New();
_ImageViewer2.SetInputConnection(_reader2.GetOutputPort());
var image = _ImageViewer2.GetInput();
// get range of slices (min is the first index, max is the last index)
_ImageViewer2.GetSliceRange(ref _MinSlice2, ref _MaxSlice2);
this.vScrollBar2.Maximum = _MaxSlice2 + 1 + vScrollBar2.LargeChange - 1;
Debug.WriteLine("slices range from : " + _MinSlice2.ToString() + " to " + _MaxSlice2.ToString());
vtkRenderWindow renderWindow = renderWindowControl2.RenderWindow;
_interactorStyle2 = vtkInteractorStyleImage.New();
_interactorStyle2.MouseWheelForwardEvt += new vtkObject.vtkObjectEventHandler(interactor_MouseWheelForwardEvt2);
_interactorStyle2.MouseWheelBackwardEvt += new vtkObject.vtkObjectEventHandler(interactor_MouseWheelBackwardEvt2);
renderWindow.GetInteractor().LeftButtonPressEvt += new vtkObject.vtkObjectEventHandler(renderWindowControl2_Click);
renderWindow.GetInteractor().SetInteractorStyle(_interactorStyle2);
renderWindow.GetRenderers().InitTraversal();
vtkRenderer ren;
while ((ren = renderWindow.GetRenderers().GetNextItem()) != null)
ren.SetBackground(0.0, 0.0, 0.0);
_ImageViewer2.SetRenderWindow(renderWindow);
_ImageViewer2.GetRenderer().AddActor2D(sliceStatusActor);
_ImageViewer2.GetRenderer().AddActor2D(usageTextActor);
_ImageViewer2.SetSlice(_MinSlice2);
// Compute a simple window/level based on scalar range
vtkWindowLevelLookupTable wlLut = new vtkWindowLevelLookupTable();
double range = _reader2.GetOutput().GetScalarRange()[1] - _reader2.GetOutput().GetScalarRange()[0];
double level = (_reader2.GetOutput().GetScalarRange()[1] +
_reader2.GetOutput().GetScalarRange()[0]) / 2.0;
wlLut.SetWindow(1000);
wlLut.SetLevel(-1000);
// Create a mapper and actor.
vtkDataSetMapper mapper = new vtkDataSetMapper();
mapper.SetInputConnection(_reader2.GetOutputPort());
mapper.SetLookupTable(wlLut);
// mapper.SetScalarRange(0, 255);
vtkActor actor = new vtkActor();
var actors = _ImageViewer2.GetRenderer().GetActors();
actor.SetMapper(mapper);
// Add the actors to the scene
_ImageViewer2.GetRenderer().AddActor(actor);
_ImageViewer2.Render();
vtkImageViewer2
已经实现了 Window/Level 功能。
您可以像这样访问它:
myImageViewer2.GetWindowLevel().SetWindow(1000);
myImageViewer2.GetWindowLevel().SetLevel(-1000);