LoginSignup
1
2

More than 3 years have passed since last update.

MPEG2のDICOMってどうすりゃいいの

Last updated at Posted at 2020-08-12

LinacのEPIDで取得した動画をdicom形式でexportした。いつも通りにpydicomで解析してみる。

import pydicom
dicom_data = pydicom.dcmread(file_name)

すると、

(0002, 0010) Transfer Syntax UID                 UI: MPEG2 Main Profile / Main Level

なるほど、動画なんですね。
いつもの通り、

array = dicom_data.pixel_array

でpixel arrayを取得しようとすると、

NotImplementedError: Unable to decode pixel data with a transfer syntax UID of '1.2.840.10008.1.2.4.100' (MPEG2 Main Profile / Main Level) as there are no pixel data handlers available that support it. Please see the pydicom documentation for information on supported transfer syntaxes 

あれ、うまくいかない。
dicom_data.PixelDataから解析するかと思いながら、めんどいな、もしかして普通に動画ファイルとして解析できちゃったりしないかな、なんて思って、

import cv2
cap = cv2.VideoCapture(file_name)

あれ、エラーでない。いけるのか?

frames = []
while True:
    ret, frame = cap.read()
    if ret == True:
        frame=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY) #Gray scaleにしてあるよ
        frames.append(frame)
    else:
        break

とかしてみたら無事にframesのリストができてる。
これを np.array(frames).shapeとかすれば

(143, 576, 720)

なるほど、576 x 720 の画像が143枚入っているのがわかる。
あとはplt.imshow(np.array(frames)[0,:,:])として最初の画像が表示できた。

dicomファイルだからと身構えず普通に動画ファイルとしてopencvを使って解析できることがわかった。

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2