Convert BMP image to DICOM

I have 800 images in BMP format and I would like to convert them to DICOM. I started like this, but for some reason this does not work.

My experience with VTK is limited:

file_in = 'C:/programfile/image.bmp'
file_out = 'test1.dcm'
vtkGDCMImageReader()
+2
source share
2 answers

Here it is in python:

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

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

If your input BMP uses a lookup table, you can simply pass it:

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()

And vice versa (DICOM → BMP):

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

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

Of course you can do this from the command line, just use gdcm2vtk :

$ gdcm2vtk input.bmp output.dcm

or

$ gdcm2vtk --palette-color input.bmp output.dcm
+1
source
0

All Articles