What should I do with DICOM in MPEG2?

I exported the video acquired by Linac's EPID in dicom format. Try to analyze with pydicom as usual.

import pydicom
dicom_data = pydicom.dcmread(file_name)

Then

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

I see, it's a video. As usual

array = dicom_data.pixel_array

When I try to get a pixel array with

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 

That doesn't work. I was wondering if I could analyze it from dicom_data.PixelData, but I was wondering if it could be analyzed as a normal video file.

import cv2
cap = cv2.VideoCapture(file_name)

That's not an error. Can you go?

frames = []
while True:
    ret, frame = cap.read()
    if ret == True:
        frame=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY) #I have a Gray scale
        frames.append(frame)
    else:
        break

When I tried to do something, the list of frames was successfully created. If you call this np.array (frames) .shape

(143, 576, 720)

Well, you can see that it contains 143 images of 576 x 720. After that, the first image could be displayed as plt.imshow (np.array (frames) [0 ,:,:]).

It turned out that even if it is a dicom file, it can be analyzed using opencv as a normal video file.

Recommended Posts

What should I do with DICOM in MPEG2?
What automation should I do in RPA, VBA, and programming languages?
What should I do with the Python directory structure after all?
After all, what should I use to do type comparisons in Python?
I failed when clustering with k-means, but what should I do (implementation of kernel k-means)
What I do when imitating embedded go in python
What I learned in Python
I briefly summarized what you should keep in mind when learning with or without supervised learning
What to do with Magics install
What to do with PYTHON release?
I want to do ○○ with Pandas
Working with DICOM images in Python
Python | What you can do with Python
What I was addicted to with json.dumps in Python base64 encoding
VRM output for VRoid cluster, what should I do after all?
What skills do I need to program with the FBX SDK Python?
What you can do with API vol.1
What to do if you get lost in file reference with FileNotFoundError
What to do if you can't install with pip in babun environment
What you can do with programming skills
I want to visualize the transfer status of the 2020 J League, what should I do?
You will be an engineer in 100 days --Day 35 --Python --What you can do with Python
What I did when I got stuck in the time limit with lambda python
I want to do Dunnett's test in Python
What to do if pipreqs results in UnicodeDecodeError
[Python] What I did to do Unit Test
I struggled with conditional branching in Django's Templates.
[Question] What happens when I use% in python?
What to do to get google spreadsheet in python
What command should I type to list currently available modules like gem list in python?
real-time-Personal-estimation (What should I do to prevent the estimation of images outside the category) * Failure.
What I did when I was angry to put it in with the enable-shared option
What to do if you run python in IntelliJ and end with an error
What to do if pip install fails in Xcode 5.1
[openpyxl] What to do when IllegalCharacterError appears in pandas.DataFrame.to_excel
I want to transition with a button in flask
How to do hash calculation with salt in Python
I was in trouble because I couldn't push with heroku
How to do zero-padding in one line with OpenCV
Links to do what you want with Sublime Text
I was addicted to scraping with Selenium (+ Python) in 2020
I want to work with a robot in python.
pickle To read what was made in 2 series with 3 series
What to do if a UnicodeDecodeError occurs in pip
Storage I / O notes in Python with Azure Functions
[ML Ops] I want to do multi-project with Python
What you can't do with hstack or vstack with dstack
I can't manipulate iframes in a page with Selenium
Note that I dealt with HTML in Beautiful Soup
What I did to get started with Linux commands
Work memo that I tried i18n with Flask app
What you can and cannot do with Tensorflow 2.x
What I learned by participating in the ISUCON10 qualifying
I want to do something in Python when I finish
What I was addicted to when dealing with huge files in a Linux 32bit environment
What you should not do in the process of time series data analysis (including reflection)