modifying and existing or writing a new multi frame image

14 views
Skip to first unread message

Tallhamer

unread,
Aug 1, 2024, 10:07:52 PMAug 1
to pydicom
I have a multi frame cine image coming off of a Varian Linac with the following dicom information

Dataset.file_meta -------------------------------
(0002, 0000) File Meta Information Group Length  UL: 196
(0002, 0001) File Meta Information Version        OB: b'\x00\x01'
(0002, 0002) Media Storage SOP Class UID         UI: RT Image Storage
(0002, 0003) Media Storage SOP Instance UID      UI: 1.2.246.352.62.1.5046228569911715883.45253810023799210
(0002, 0010) Transfer Syntax UID                 UI: MPEG2 Main Profile / Main Level
(0002, 0012) Implementation Class UID            UI: 1.2.246.352.70.2.1.160.3
(0002, 0013) Implementation Version Name         SH: 'DCIE 16.1'
...
(0008, 0005) Specific Character Set              CS: 'ISO_IR 192'
(0008, 0008) Image Type                          CS: ['ORIGINAL', 'PRIMARY', 'PORTAL']
(0008, 0012) Instance Creation Date              DA: '20240726'
(0008, 0013) Instance Creation Time              TM: '163337'
(0008, 0016) SOP Class UID                       UI: RT Image Storage
...

(0008, 0060) Modality                            CS: 'RTIMAGE'
(0008, 0064) Conversion Type                     CS: 'DI'
(0008, 0070) Manufacturer                        LO: 'Varian Medical Systems'
(0008, 0090) Referring Physician's Name          PN: ''
(0008, 1010) Station Name                        SH: 'TrueBeam1547'
(0008, 1070) Operators' Name                     PN: 'mjt5d0'
(0008, 1090) Manufacturer's Model Name           LO: 'Patient Verification'
(0010, 0010) Patient's Name                      PN: 'BEAM ON Test^PKR'

(0018, 1065) Frame Time Vector                   DS: [0, 1044.8851, 1043.8731, 1044.8719, 1043.8731]
(0018, 5100) Patient Position                    CS: 'HFS'
(0020, 1040) Position Reference Indicator        LO: ''
(0028, 0002) Samples per Pixel                   US: 1
(0028, 0004) Photometric Interpretation          CS: 'YBR_PARTIAL_420'
(0028, 0006) Planar Configuration                US: 0
(0028, 0008) Number of Frames                    IS: '118'
(0028, 0009) Frame Increment Pointer             AT: (0018, 1065)
(0028, 0010) Rows                                US: 576
(0028, 0011) Columns                             US: 720
(0028, 0100) Bits Allocated                      US: 8
(0028, 0101) Bits Stored                         US: 8
(0028, 0102) High Bit                            US: 7
(0028, 0103) Pixel Representation                US: 0
(0028, 1040) Pixel Intensity Relationship        CS: 'LIN'
(0028, 1041) Pixel Intensity Relationship Sign   SS: -1
...
(3002, 0011) Image Plane Pixel Spacing           DS: [0.55751111111111, 0.55751111111111]
(3002, 0012) RT Image Position                   DS: [-200.42524444444, 160.284444444444]
(3002, 0026) RT Image SID                        DS: '1500.06108461104'

if I do something like this

ds = dcmread(r'C:\tmp\cine_dcm_testing\mv_cine.dcm')

with open(r'C:\tmp\cine_dcm_testing\mv.mpeg', 'wb') as f:
f.write(ds.PixelData)

The pixel data writen out is a simple mpeg2 file with no compression and will open up and any random video player like VLC.

I have read in more than one location that many editors or DICOM viewers will often ignore the DICOM tag settings if the raw pixel data is stored within the file as a byte string of a known format (i.e. MPEG2). The viewer will often just pass this string of bytes off to an internal video player or to your systems default video player. I have confirmed this is the case for these images with a couple different viewers.

What I would like to do is test a few assumptions by:
  1. Swaping out the raw mpeg2 bytes in the files coming off my linac with another complete mpeg2 movie  and simply saving it to a new DICOM file to see if I can import that file into a DICOM viewer and see if it even cares that the mpeg2 data doesn't match the DICOM tags (i.e. Columns, Rows, Number of Frames...etc.)
    • Attempts to do this with pydicom have failed. 
  2. If the viewer does care I'm actually struggling to figure out how to write my own cine multi-frame DICOM file to match this format (i.e. required tages and format of the pixel data).
    • All of my attemps to write my own cine images by using multiple images as frames or by writing in my own raw MPEG2 video bytes to the pixel data tag have failed so I know I'm missing something.  I would love some pointers or examples to get me started down the right path.
If anyone has tried to write their own multi-frame images either using stacks of raw images or prefeably using the MPEG2 or MPEG4 Transfer Syntax I would love to hear how you achived it.

Thanks
Mike

Farhan Mohd

unread,
Aug 1, 2024, 10:13:07 PMAug 1
to pyd...@googlegroups.com
Hi Mike,
Perhaps the below link would help you.



--
You received this message because you are subscribed to the Google Groups "pydicom" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pydicom+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pydicom/9b4b22ce-1b9b-4959-8a2e-655561da4d9en%40googlegroups.com.

Michael Tallhamer

unread,
Aug 1, 2024, 10:37:51 PMAug 1
to pyd...@googlegroups.com

I appreciate that Farhan. However, I'm not really having any issues reading or processing these images with pydicom, PIL, or opencv in python.

I have process the MPEG2 video stream from the files and would like to replace it in the original file with the processed video or  in many cases write a completely new cine multi-frame image by taking a video input from another source and writing it into a dicom file.

I'm unfortunately running into errors when trying to write these new files from scratch and can't seem to find an example of doing this anywhere.

Thanks again.
Mike


justin....@gmail.com

unread,
Aug 10, 2024, 11:42:09 AMAug 10
to pydicom
Hi Mike,
have you looked through the capabilities of 3D Slicer?  looks like it can do some mpeg stuff, but maybe not exactly what you are looking for.
and also handling of multi volume images
Reply all
Reply to author
Forward
0 new messages