本文实现了 Python C++ 版本 的 四视图,横断面,冠状面,矢状面,3D
三维重建 医学图像的可视化 PyQt Python VTK四视图(横断面,冠状,矢状面,3D)
主要功能:
1.支持 JPG PNG TIF DICOM RAW MHD Nii 等多种数据格式导入
2. 四视图搭建,,横断面,冠状面,矢状面 3D;
3. 四窗口每个窗口可以最大化,恢复
3.二维数据视图的图层切换, 缩放,窗宽窗位调整功能;可以通过进度条换图层;可以通过进度条调整窗宽窗位;
4.三维可视化数据显示,缩放,旋转 ,平移
5.测量功能,2D 距离测量 角度测量 :
6.3D 体绘制 ,三维可视化数据显示,缩放,旋转 ,平移
效果:
视频:
python-vtk-measure-ppp
这里主要讲一下体绘制:
1.固定点光线投影算法
vtkFixedPointVolumeRayCastMapper
该类能够实现基于Alpha合成的体绘制方法和最大密度投影体绘制方法,能够支持任意类型或者独立多元数据。
例如,当输入为二元独立数据时,第一源数据用于颜色映射,而第二元作为不透明度映射。该类使用了空间跳跃技术来加速体绘制的渲染过程,而在内部计算时,统一使用了float数据类型。
vtkFixedPointVolumeRayCastMapper与vtkVolumeRayCastMapper对比两个类的使用方法基本一致,都支持设置光线采样步长、图像采样距离、自动调整图像采样距离等操作。
vtkFixedPointVolumeRayCastMapper
只支持基于Alpha合成的体绘制方法和最大密度体绘制方法,
光线投影+最大密度投影+等值面法
void SetBlendModeToComposite();
void SetBlendModeToMaximumIntensity();
void SetBlendModeToMinimumIntensity();
void SetBlendModeToAddictive();
2、基于GPU加速的光线投射体会自算法
vtkGPUVolumeRayCastMapper类实现了基于GPU加速光线投影体绘制算法。该类的使用方法与上面各类基本一致。同样可以实现光线采样步长、图像采样距离、自动调整图像采样距离等。
vtkSmartPointer<vtkGPUVolumeRayCastMapper> volumeMapper =
vtkSmartPointer<vtkGPUVolumeRayCastMapper>::New();
volumeMapper->SetInputData(reader->GetOutput());;
volumeMapper->SetSampleDistance(volumeMapper->GetSampleDistance() / 2); //设置光线采样距离
3.样例:
分别:文章来源:https://www.toymoban.com/news/detail-700095.html
1.MIP
2.CompositeRamp
3.CompositeShadeRamp
4.CT_Skin
5.CT_Bone
6.CT_Muscle
7.RGB_Composite文章来源地址https://www.toymoban.com/news/detail-700095.html
// Create our volume and mapper
vtkNew<vtkVolume> volume;
vtkNew<vtkFixedPointVolumeRayCastMapper> mapper;
mapper->SetInputConnection(reader->GetOutputPort());
vtkNew<vtkColorTransferFunction> colorFun;
vtkNew<vtkPiecewiseFunction> opacityFun;
// Create the property and attach the transfer functions
vtkNew<vtkVolumeProperty> property;
property->SetIndependentComponents(independentComponents);
property->SetColor(colorFun);
property->SetScalarOpacity(opacityFun);
property->SetInterpolationTypeToLinear();
// connect up the volume to the property and the mapper
volume->SetProperty(property);
volume->SetMapper(mapper);
// Depending on the blend type selected as a command line option,
// adjust the transfer function
switch (blendType)
{
// MIP
// Create an opacity ramp from the window and level values.
// Color is white. Blending is MIP.
case 0:
colorFun->AddRGBSegment(0.0, 1.0, 1.0, 1.0, 255.0, 1.0, 1.0, 1.0);
opacityFun->AddSegment(opacityLevel - 0.5 * opacityWindow, 0.0,
opacityLevel + 0.5 * opacityWindow, 1.0);
mapper->SetBlendModeToMaximumIntensity();
break;
// CompositeRamp
// Create a ramp from the window and level values. Use compositing
// without shading. Color is a ramp from black to white.
case 1:
colorFun->AddRGBSegment(opacityLevel - 0.5 * opacityWindow, 0.0, 0.0, 0.0,
opacityLevel + 0.5 * opacityWindow, 1.0, 1.0, 1.0);
opacityFun->AddSegment(opacityLevel - 0.5 * opacityWindow, 0.0,
opacityLevel + 0.5 * opacityWindow, 1.0);
mapper->SetBlendModeToComposite();
property->ShadeOff();
break;
// CompositeShadeRamp
// Create a ramp from the window and level values. Use compositing
// with shading. Color is white.
case 2:
colorFun->AddRGBSegment(0.0, 1.0, 1.0, 1.0, 255.0, 1.0, 1.0, 1.0);
opacityFun->AddSegment(opacityLevel - 0.5 * opacityWindow, 0.0,
opacityLevel + 0.5 * opacityWindow, 1.0);
mapper->SetBlendModeToComposite();
property->ShadeOn();
break;
// CT_Skin
// Use compositing and functions set to highlight skin in CT data
// Not for use on RGB data
case 3:
colorFun->AddRGBPoint(-3024, 0, 0, 0, 0.5, 0.0);
colorFun->AddRGBPoint(-1000, .62, .36, .18, 0.5, 0.0);
colorFun->AddRGBPoint(-500, .88, .60, .29, 0.33, 0.45);
colorFun->AddRGBPoint(3071, .83, .66, 1, 0.5, 0.0);
opacityFun->AddPoint(-3024, 0, 0.5, 0.0);
opacityFun->AddPoint(-1000, 0, 0.5, 0.0);
opacityFun->AddPoint(-500, 1.0, 0.33, 0.45);
opacityFun->AddPoint(3071, 1.0, 0.5, 0.0);
mapper->SetBlendModeToComposite();
property->ShadeOn();
property->SetAmbient(0.1);
property->SetDiffuse(0.9);
property->SetSpecular(0.2);
property->SetSpecularPower(10.0);
property->SetScalarOpacityUnitDistance(0.8919);
break;
// CT_Bone
// Use compositing and functions set to highlight bone in CT data
// Not for use on RGB data
case 4:
colorFun->AddRGBPoint(-3024, 0, 0, 0, 0.5, 0.0);
colorFun->AddRGBPoint(-16, 0.73, 0.25, 0.30, 0.49, .61);
colorFun->AddRGBPoint(641, .90, .82, .56, .5, 0.0);
colorFun->AddRGBPoint(3071, 1, 1, 1, .5, 0.0);
opacityFun->AddPoint(-3024, 0, 0.5, 0.0);
opacityFun->AddPoint(-16, 0, .49, .61);
opacityFun->AddPoint(641, .72, .5, 0.0);
opacityFun->AddPoint(3071, .71, 0.5, 0.0);
mapper->SetBlendModeToComposite();
property->ShadeOn();
property->SetAmbient(0.1);
property->SetDiffuse(0.9);
property->SetSpecular(0.2);
property->SetSpecularPower(10.0);
property->SetScalarOpacityUnitDistance(0.8919);
break;
// CT_Muscle
// Use compositing and functions set to highlight muscle in CT data
// Not for use on RGB data
case 5:
colorFun->AddRGBPoint(-3024, 0, 0, 0, 0.5, 0.0);
colorFun->AddRGBPoint(-155, .55, .25, .15, 0.5, .92);
colorFun->AddRGBPoint(217, .88, .60, .29, 0.33, 0.45);
colorFun->AddRGBPoint(420, 1, .94, .95, 0.5, 0.0);
colorFun->AddRGBPoint(3071, .83, .66, 1, 0.5, 0.0);
opacityFun->AddPoint(-3024, 0, 0.5, 0.0);
opacityFun->AddPoint(-155, 0, 0.5, 0.92);
opacityFun->AddPoint(217, .68, 0.33, 0.45);
opacityFun->AddPoint(420, .83, 0.5, 0.0);
opacityFun->AddPoint(3071, .80, 0.5, 0.0);
mapper->SetBlendModeToComposite();
property->ShadeOn();
property->SetAmbient(0.1);
property->SetDiffuse(0.9);
property->SetSpecular(0.2);
property->SetSpecularPower(10.0);
property->SetScalarOpacityUnitDistance(0.8919);
break;
// RGB_Composite
// Use compositing and functions set to highlight red/green/blue regions
// in RGB data. Not for use on single component data
case 6:
opacityFun->AddPoint(0, 0.0);
opacityFun->AddPoint(5.0, 0.0);
opacityFun->AddPoint(30.0, 0.05);
opacityFun->AddPoint(31.0, 0.0);
opacityFun->AddPoint(90.0, 0.0);
opacityFun->AddPoint(100.0, 0.3);
opacityFun->AddPoint(110.0, 0.0);
opacityFun->AddPoint(190.0, 0.0);
opacityFun->AddPoint(200.0, 0.4);
opacityFun->AddPoint(210.0, 0.0);
opacityFun->AddPoint(245.0, 0.0);
opacityFun->AddPoint(255.0, 0.5);
mapper->SetBlendModeToComposite();
property->ShadeOff();
property->SetScalarOpacityUnitDistance(1.0);
break;
default:
vtkGenericWarningMacro("Unknown blend type.");
break;
}
// Set the default window size
renWin->SetSize(600, 600);
renWin->SetWindowName("FixedPointVolumeRayCastMapperCT");
renWin->Render();
// Add the volume to the scene
renderer->AddVolume(volume);
renderer->ResetCamera();
renderer->SetBackground(colors->GetColor3d("SlateGray").GetData());
auto camera = renderer->GetActiveCamera();
camera->SetPosition(56.8656, -297.084, 78.913);
camera->SetFocalPoint(109.139, 120.604, 63.5486);
camera->SetViewUp(-0.00782421, -0.0357807, -0.999329);
camera->SetDistance(421.227);
camera->SetClippingRange(146.564, 767.987);
// interact with data
renWin->Render();
iren->Start();
到了这里,关于三维重建 PyQt Python VTK 体绘制 医学图像可视化系统,可提供源码(横断面,冠状面,矢状面,3D)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!