python vtk dicom_python - Convert bmp image into DICOM

I have 800 images in BMP format and I would like to convert them into DICOM. I have started like this, but it is not working for some reason.

My experience with VTK is limited:

file_in = 'C:/programfile/image.bmp'

file_out = 'test1.dcm'

vtkGDCMImageReader()

python

vtk

dicom

gdcm

|

this question

edited Jan 4 '16 at 10:41

malat 3,927 5 38 78 asked Feb 17 '11 at 21:46

user622170 11 3

|

2 Answers

2

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 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 the opposite (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 it from the command line, simply use gdcm2vtk:ircos) The error information is: Traceback (most recent call last): File "/usr/lib/python2.7/dist-packages/IPython/core/interactiveshell.py", line 2820, in run_code exec code_obj in self.user_global_ns, self.user_ns File "

$ gdcm2vtk input.bmp output.dcm

or

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

|

this answer

edited Apr 30 '13 at 11:36 answered Mar 25 '11 at 14:09

malat 3,927 5 38 78

|

If you are using C++ there are other libraries DICOM file libraries. Check out DCMTK, specifically one of their example application already does this for you. http://support.dcmtk.org/docs-dcmrt/img2dcm.html

|

this answer answered Apr 29 '13 at 3:45

denver 1,379 7 24

|

ut the image that I produce does not match the original. I know I need rescaling the pixels of the image to convert it but I do not know how. Does anyone know how I can do the conversion properly Below, my code in python: from vtk import *

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值