dicom多帧转换_如何提取/查看多帧DICOM文件的所有帧?
发布日期:2021-06-25 19:30:10 浏览次数:4 分类:技术文章

本文共 2354 字,大约阅读时间需要 7 分钟。

I know I can view a dicom file using following code:

import dicom

from dicom.contrib.pydicom_PIL import show_PIL

f = "CT-MONO2-8-abdo.dcm"

ds = dicom.read_file(f, force=True)

show_PIL(ds)

However, how can I extract and view all frames from a multi-frame DICOM file? I tried using above code but got following error:

File "/home/auser/.local/lib/python3.5/site-packages/dicom/dataset.py", line 399, in _get_pixel_array

raise NotImplementedError("Pixel Data is compressed in a format pydicom does not yet handle. Cannot return array")

NotImplementedError: Pixel Data is compressed in a format pydicom does not yet handle. Cannot return array

I had tried with some multi-frame files located at http://www.barre.nom.fr/medical/samples/. The pixel size etc are available for these files.

How can I extract and/or view different frames of a multi-frame DICOM file?

Edit: Following command using gdcm works on Linux to convert these to uncompressed file:

$ gdcmconv --raw compressed.dcm uncompressed.dcm

This is then read by python code above but that shows only first frame. How can I extract and view other frames?

解决方案

pydicom supports reading pixel data. Refer this documentation.

pydicom tends to be “lazy” in interpreting DICOM data. For example, by

default it doesn’t do anything with pixel data except read in the raw

bytes:

import dicom

ds=dicom.read_file("MR_small.dcm")

ds.PixelData

'\x89\x03\xfb\x03\xcb\x04\xeb\x04\xf9\x02\x94\x01\x7f ...

...

About pixel_array

A property of Dataset called pixel_array provides more useful pixel

data for uncompressed images. The NumPy numerical package must be

installed on your system to use this property, because pixel_array

returns a NumPy array:

import dicom

ds=dicom.read_file("MR_small.dcm")

ds.pixel_array

array([[ 905, 1019, 1227, ..., 302, 304, 328],

[ 628, 770, 907, ..., 298, 331, 355],

[ 498, 566, 706, ..., 280, 285, 320],

...,

[ 334, 400, 431, ..., 1094, 1068, 1083],

[ 339, 377, 413, ..., 1318, 1346, 1336],

[ 378, 374, 422, ..., 1369, 1129, 862]], dtype=int16)

ds.pixel_array.shape

(64, 64)

As explained in error message (and by @kritzel_sw in comment) the pydicom does not support the Transfer Syntax of source image yet. Change the Transfer Syntax using some other tool before attempting to extract the frames.

Also check this Stack Overflow question; it is about old version but may be helpful.

转载地址:https://blog.csdn.net/weixin_39622901/article/details/111481829 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:python上位机界面设计_用Python写个上位机学习系列之第一个界面的设计
下一篇:layui弹窗自适应变大_layui弹窗宽度固定高度自适应界面

发表评论

最新留言

留言是一种美德,欢迎回访!
[***.207.175.100]2024年04月12日 03时00分10秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章