gpt4 book ai didi

python - 将 bmp 图像转换为 DICOM

转载 作者:太空宇宙 更新时间:2023-11-04 06:29:07 29 4
gpt4 key购买 nike

我有 800 张 BMP 格式的图像,我想将它们转换成 DICOM。我是这样开始的,但由于某种原因它不起作用。

我对 VTK 的经验有限:

file_in = 'C:/programfile/image.bmp'
file_out = 'test1.dcm'
vtkGDCMImageReader()

最佳答案

这是在 python 中:

r = vtkBMPReader()
r.SetFileName( 'test1.bmp' )

w = vtkGDCMImageWriter()
w.SetInput( r.GetOutput() )
w.SetFileName( 'test1.dcm' )
w.Write()

如果您的输入 BMP 使用查找表,您可以简单地传递它:

r = vtkBMPReader()
r.SetFileName( 'test1.bmp' )
r.Allow8BitBMPOn()
r.Update()
r.GetOutput().GetPointData().GetScalars().SetLookupTable( r.GetLookupTable() )

w = vtkGDCMImageWriter()
w.SetInput( r.GetOutput() )
w.SetFileName( 'test1.dcm' )
w.SetImageFormat( VTK_LOOKUP_TABLE );
w.Write()

相反(DICOM -> BMP):

r = vtkGDCMImageReader()
r.SetFileName( 'test1.dcm' )

w = vtkBMPWriter()
w.SetInput( r.GetOutput() )
w.SetFileName( 'test1.bmp' )
w.Write()

当然你可以从命令行来做,简单地使用gdcm2vtk :

$ gdcm2vtk input.bmp output.dcm

$ gdcm2vtk --palette-color input.bmp output.dcm

关于python - 将 bmp 图像转换为 DICOM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5035078/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com