将 DICOM 转换为 TIFF
我是 Python 新手,所以如果我的信息不正确,请原谅我的无知。我正在尝试对目录进行光栅处理,并将其中的所有 DICOM 文件转换为 TIFF 文件。我已经可以使用搜索功能,但我很难将图像保存为 TIFF。我正在使用 pydicom 库读取 DICOM 并操作标头信息。另外,我尝试使用pydicom中的save_as函数保存到TIFF,但我宁愿使用PIL中的save函数来正确设置TIFF的压缩。我认为问题是我不能/不明白如何从 DICOM 中提取实际图像数据并将其放入新图像中。任何帮助将不胜感激......干杯
Python 2.7 皮尔1.1.7 皮迪康0.9.6
I'm new to Python so forgive my ignorance If I don't have all the info correct. I'm trying raster through a directory and convert all the DICOM files within to TIFF files. I have gotten the search functionality to work, but I am having a hard time saving the images as TIFFs. I'm using the pydicom libraries to read in the DICOM and manipulate the header information. Also, I have tried using the save_as function in pydicom to save to TIFF, but I would rather use the save function in PIL to properly set the compression of the TIFF. I think the problem is that I can't/don't understand how to extract the actual image data from a DICOM and place it in a new image.Any Help would be greatly appreciated ... Cheers
Python 2.7
PIL 1.1.7
Pydicom 0.9.6
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在网上找到了同一查询的答案,虽然我不记得该网站,但当我将其应用到我的代码时,也在这里为其他人共享:
或者如果您想保存图像,则使用:
pylab.imsave('',ImageFile.pixel_array,cmap=pylab.cm.bone)
imsave
默认情况下会将图像保存在 中。 png 格式。如果支持,您可以在imsave()
中指定所需的格式。希望它有用。
Found an answer online to the same query sometime back, although I don't remember the site but as I applied it to my code, sharing it here for others as well :
or if you want to save the image then instead use:
pylab.imsave('<DestinationFilePath>',ImageFile.pixel_array,cmap=pylab.cm.bone)
The
imsave
will by default save the image in .png format though. You can specify the desired format in theimsave()
if it is supported.Hope it is useful.
如果您知道如何使用
PIL
将图像数据保存为.tiff
,这个示例应该可以帮助您将图像数据从pydicom
传递到PIL
(还有更多在评论中)。If you know how to use
PIL
to save image data as.tiff
, this example should help you to pass image data frompydicom
toPIL
(there is more here in the comments).