How to extract/view all frames of a multi-frame DICOM file?

纵然是瞬间 提交于 2019-12-13 14:01:02

问题


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

(I used http://www.barre.nom.fr/medical/samples/files/US-PAL-8-10x-echo.gz file after extraction).

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


回答1:


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)

Document also explains about viewing images at http://pydicom.readthedocs.io/en/stable/viewing_images.html.

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.

Another helpful blog of Rony http://dicomiseasy.blogspot.in/2012/08/chapter-12-pixel-data.html

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



来源:https://stackoverflow.com/questions/47707756/how-to-extract-view-all-frames-of-a-multi-frame-dicom-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!