vtkplotter - 如何设置颜色图
vtkplotter - How to set a colormap
我正在使用带标签的 DICOM,并且正在使用 vtkplotter 可视化 3D 模型。每个体素都有一个标签,用于识别骨骼的识别部分,范围从 -1024 到根据 DICOM 扫描而变化的值。如何为每个标量值分配特定颜色?我尝试使用 color(),但据我了解,我只能以有序的方式插入与从最小值开始的值相对应的颜色。我必须为某个标量值 x 指定颜色 y。
我用来显示 3D 模型的代码片段:
from vtkplotter import *
volume = load('Letter:/dicom_folder')
volume.color(['white', 'red', 'yellow'])
volume.alpha([0.0, 0.5, 0.5])
volume.show()
编辑:
我是这样解决的:
from vtkmodules.vtkCommonDataModel import vtkPiecewiseFunction
from vtkmodules.vtkRenderingCore import vtkColorTransferFunction, vtkVolumeProperty
from vtkplotter import *
volume = load('Letter:/dicom_folder')
volumeColor = vtkColorTransferFunction()
r, g, b = getColor('white')
volumeColor.AddRGBPoint(-1024, r, g, b)
r, g, b = getColor('yellow')
volumeColor.AddRGBPoint(-1023, r, g, b)
r, g, b = getColor('blue')
volumeColor.AddRGBPoint(-1022, r, g, b)
volumeScalarOpacity = vtkPiecewiseFunction()
volumeScalarOpacity.AddPoint(-1024, 0.0)
volumeScalarOpacity.AddPoint(-1023, 0.5)
volumeScalarOpacity.AddPoint(-1022, 0.5)
volumeProperty = vtkVolumeProperty()
volumeProperty.SetColor(volumeColor)
volumeProperty.SetScalarOpacity(volumeScalarOpacity)
volumeProperty.SetInterpolationTypeToLinear()
volumeProperty.ShadeOn()
volumeProperty.SetAmbient(0.4)
volumeProperty.SetDiffuse(0.6)
volumeProperty.SetSpecular(0.2)
volume.SetProperty(volumeProperty)
volume.show()
如果您有更好或更有效的解决方案,请告诉我。
from vtkmodules.vtkCommonDataModel import vtkPiecewiseFunction
from vtkmodules.vtkRenderingCore import vtkColorTransferFunction, vtkVolumeProperty
from vtkplotter import *
volume = load('Letter:/dicom_folder')
volumeColor = vtkColorTransferFunction()
r, g, b = getColor('white')
volumeColor.AddRGBPoint(-1024, r, g, b)
r, g, b = getColor('yellow')
volumeColor.AddRGBPoint(-1023, r, g, b)
r, g, b = getColor('blue')
volumeColor.AddRGBPoint(-1022, r, g, b)
volumeScalarOpacity = vtkPiecewiseFunction()
volumeScalarOpacity.AddPoint(-1024, 0.0)
volumeScalarOpacity.AddPoint(-1023, 0.5)
volumeScalarOpacity.AddPoint(-1022, 0.5)
volumeProperty = vtkVolumeProperty()
volumeProperty.SetColor(volumeColor)
volumeProperty.SetScalarOpacity(volumeScalarOpacity)
volumeProperty.SetInterpolationTypeToLinear()
volumeProperty.ShadeOn()
volumeProperty.SetAmbient(0.4)
volumeProperty.SetDiffuse(0.6)
volumeProperty.SetSpecular(0.2)
volume.SetProperty(volumeProperty)
volume.show()
我正在使用带标签的 DICOM,并且正在使用 vtkplotter 可视化 3D 模型。每个体素都有一个标签,用于识别骨骼的识别部分,范围从 -1024 到根据 DICOM 扫描而变化的值。如何为每个标量值分配特定颜色?我尝试使用 color(),但据我了解,我只能以有序的方式插入与从最小值开始的值相对应的颜色。我必须为某个标量值 x 指定颜色 y。
我用来显示 3D 模型的代码片段:
from vtkplotter import *
volume = load('Letter:/dicom_folder')
volume.color(['white', 'red', 'yellow'])
volume.alpha([0.0, 0.5, 0.5])
volume.show()
编辑:
我是这样解决的:
from vtkmodules.vtkCommonDataModel import vtkPiecewiseFunction
from vtkmodules.vtkRenderingCore import vtkColorTransferFunction, vtkVolumeProperty
from vtkplotter import *
volume = load('Letter:/dicom_folder')
volumeColor = vtkColorTransferFunction()
r, g, b = getColor('white')
volumeColor.AddRGBPoint(-1024, r, g, b)
r, g, b = getColor('yellow')
volumeColor.AddRGBPoint(-1023, r, g, b)
r, g, b = getColor('blue')
volumeColor.AddRGBPoint(-1022, r, g, b)
volumeScalarOpacity = vtkPiecewiseFunction()
volumeScalarOpacity.AddPoint(-1024, 0.0)
volumeScalarOpacity.AddPoint(-1023, 0.5)
volumeScalarOpacity.AddPoint(-1022, 0.5)
volumeProperty = vtkVolumeProperty()
volumeProperty.SetColor(volumeColor)
volumeProperty.SetScalarOpacity(volumeScalarOpacity)
volumeProperty.SetInterpolationTypeToLinear()
volumeProperty.ShadeOn()
volumeProperty.SetAmbient(0.4)
volumeProperty.SetDiffuse(0.6)
volumeProperty.SetSpecular(0.2)
volume.SetProperty(volumeProperty)
volume.show()
如果您有更好或更有效的解决方案,请告诉我。
from vtkmodules.vtkCommonDataModel import vtkPiecewiseFunction
from vtkmodules.vtkRenderingCore import vtkColorTransferFunction, vtkVolumeProperty
from vtkplotter import *
volume = load('Letter:/dicom_folder')
volumeColor = vtkColorTransferFunction()
r, g, b = getColor('white')
volumeColor.AddRGBPoint(-1024, r, g, b)
r, g, b = getColor('yellow')
volumeColor.AddRGBPoint(-1023, r, g, b)
r, g, b = getColor('blue')
volumeColor.AddRGBPoint(-1022, r, g, b)
volumeScalarOpacity = vtkPiecewiseFunction()
volumeScalarOpacity.AddPoint(-1024, 0.0)
volumeScalarOpacity.AddPoint(-1023, 0.5)
volumeScalarOpacity.AddPoint(-1022, 0.5)
volumeProperty = vtkVolumeProperty()
volumeProperty.SetColor(volumeColor)
volumeProperty.SetScalarOpacity(volumeScalarOpacity)
volumeProperty.SetInterpolationTypeToLinear()
volumeProperty.ShadeOn()
volumeProperty.SetAmbient(0.4)
volumeProperty.SetDiffuse(0.6)
volumeProperty.SetSpecular(0.2)
volume.SetProperty(volumeProperty)
volume.show()