将bmp图像转换为DICOM

2 投票
1 回答
3282 浏览
提问于 2025-04-16 12:02

我有800张BMP格式的图片,我想把它们转换成DICOM格式。我开始尝试这样做,但不知道为什么没有成功。

我对VTK的了解不多:

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

1 个回答

1

这里是用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

撰写回答