I have a compliant dicom file (dicom.dcm) that I'm attempting to replace the pixel data (and I know I have to adjust rows,cols and other elements). The command I'm using is:
dcmodify --debug --verbose -mf "PixelData=my.mp4" dicom.dcm
This is what I am seeing:
I: Processing file: dicom.dcm
I: Loading file into dataset manager: dicom.dcm
I: Getting dataset from loaded file: dicom.dcm
I: Creating backup of input file: dicom.dcm.bak
I: Executing (option|path|value): mf|PixelData|my.mp4
I: Saving current dataset to file: dicom.dcm
It does make a backup of my dicom.dcm file as dicom.dcm.bak. I end up with a dicom.dcm that is 18 bytes smaller, but when I extract 7fe0,0010 it is the same mp4 video that I started with.
Any suggestions on what I am doing wrong? I've tried -if as well.
Thx
dcmodify issue
Moderator: Moderator Team
-
- DCMTK Developer
- Posts: 2073
- Joined: Fri, 2004-11-05, 13:47
- Location: Oldenburg, Germany
- Contact:
Re: dcmodify issue
Hi,
could you try to prepare a (test) input file for dcmodify where you just delete (i.e. dcmodify -e PixelData dicom.dcm) the pixel data from your original file?
Then use that modified dicom.dcm file in your call (using dcmodify -if ...) and see whether insertion of the pixel data from file works.
Best regards,
Michael
could you try to prepare a (test) input file for dcmodify where you just delete (i.e. dcmodify -e PixelData dicom.dcm) the pixel data from your original file?
Then use that modified dicom.dcm file in your call (using dcmodify -if ...) and see whether insertion of the pixel data from file works.
Best regards,
Michael
-
- Posts: 4
- Joined: Tue, 2022-02-01, 09:43
Re: dcmodify issue
Michael,
Thank you. This is the contents of my bash script:
--------------------------------------------------------------------
echo "Deleting prior PixelData"
dcmodify -e PixelData dicom.dcm
echo "Inserting new PixelData"
dcmodify --debug --verbose -if "PixelData=my.mp4" dicom.dcm
---------------------------------------------------------------------
I end up with a dicom.dcm file that is 1342 bytes (which was 991166212) and am now receiving an error. My my.mp4 file is relatively small: 143166 bytes in size but it is a valid mp4 file as verified by ffmpeg.
Here's the output I'm getting (and yes the group/element Pixel Representation is in the original Dicom file: (0028,0103) US 0 # 2, 1 PixelRepresentation)
Deleting prior PixelData
Inserting new PixelData
I: Processing file: dicom.dcm
I: Loading file into dataset manager: dicom.dcm
I: Getting dataset from loaded file: dicom.dcm
I: Creating backup of input file: dicom.dcm.bak
I: Executing (option|path|value): if|PixelData|my.mp4
I: Saving current dataset to file: dicom.dcm
E: couldn't save file: Pixel representation not found
I: Restoring original file from backup
I: ------------------------------------
E: There was 1 error
-rwxrwx--- 1 root 1342 Feb 2 12:22 dicom.dcm
-rwxr-xr-x 1 root 991166212 Feb 2 09:22 dicom.dcm.orig
Thank you. This is the contents of my bash script:
--------------------------------------------------------------------
echo "Deleting prior PixelData"
dcmodify -e PixelData dicom.dcm
echo "Inserting new PixelData"
dcmodify --debug --verbose -if "PixelData=my.mp4" dicom.dcm
---------------------------------------------------------------------
I end up with a dicom.dcm file that is 1342 bytes (which was 991166212) and am now receiving an error. My my.mp4 file is relatively small: 143166 bytes in size but it is a valid mp4 file as verified by ffmpeg.
Here's the output I'm getting (and yes the group/element Pixel Representation is in the original Dicom file: (0028,0103) US 0 # 2, 1 PixelRepresentation)
Deleting prior PixelData
Inserting new PixelData
I: Processing file: dicom.dcm
I: Loading file into dataset manager: dicom.dcm
I: Getting dataset from loaded file: dicom.dcm
I: Creating backup of input file: dicom.dcm.bak
I: Executing (option|path|value): if|PixelData|my.mp4
I: Saving current dataset to file: dicom.dcm
E: couldn't save file: Pixel representation not found
I: Restoring original file from backup
I: ------------------------------------
E: There was 1 error
-rwxrwx--- 1 root 1342 Feb 2 12:22 dicom.dcm
-rwxr-xr-x 1 root 991166212 Feb 2 09:22 dicom.dcm.orig
-
- DCMTK Developer
- Posts: 2073
- Joined: Fri, 2004-11-05, 13:47
- Location: Oldenburg, Germany
- Contact:
Re: dcmodify issue
Hi,
I just tried the original call (-mf PixelData=file.mp4) and I have the same problem. I need to debug this.
Note that MPEG4 is a so-called encapsulated transfer syntax so you have to produce a pseudo-item structure inside the Pixel Data element value, containing a Pixel Sequence with Pixel Items. This must already be part of the input (mp4) file, i.e. file.mp4 in the above example would not be a valid MP4 file but instead a valid MP4 file wrapped in that Pixel Sequence structure.
However, the insertion call you use should work anyway since dcmodify does not check the validity of values (beyond very basic VR data type checks). I let you know once I know more.
Best regards,
Michael
I just tried the original call (-mf PixelData=file.mp4) and I have the same problem. I need to debug this.
Note that MPEG4 is a so-called encapsulated transfer syntax so you have to produce a pseudo-item structure inside the Pixel Data element value, containing a Pixel Sequence with Pixel Items. This must already be part of the input (mp4) file, i.e. file.mp4 in the above example would not be a valid MP4 file but instead a valid MP4 file wrapped in that Pixel Sequence structure.
However, the insertion call you use should work anyway since dcmodify does not check the validity of values (beyond very basic VR data type checks). I let you know once I know more.
Best regards,
Michael
-
- Posts: 4
- Joined: Tue, 2022-02-01, 09:43
Re: dcmodify issue
Thanks Michael. Please let me know if there is anything I can help to co-diagnose/debug/test this issue
Bruce
Bruce
-
- DCMTK Developer
- Posts: 2073
- Joined: Fri, 2004-11-05, 13:47
- Location: Oldenburg, Germany
- Contact:
Re: dcmodify issue
Hi Bruce,
I now had time to look into the issue. The problem you reported only shows up when trying to insert values into the Pixel Data of files that are stored in a compressed transfer syntax.
Unfortunately there is no easy solution to support this use case, so I only made sure that dcmodify reports an error message now that such a modification is not supported.
The related commit 22d18ce61 is now in the internal DCMTK testing branch and will visible in the public DCMTK in a few days.
Maybe we can implement this feature in the future. For now you could use dump2dcm to replace pixel data of encapsulated files which is a little bit more uncomfortable. Or if you want to use dcmodify, you can decompress the file first (dcmdjpeg for JPEG, dcmdjpls for JPEG-LS, ...) and insert an uncompressed Pixel Data value using dcmodify options -i, -if, -m or -mf.
Best regards,
Michael
I now had time to look into the issue. The problem you reported only shows up when trying to insert values into the Pixel Data of files that are stored in a compressed transfer syntax.
Unfortunately there is no easy solution to support this use case, so I only made sure that dcmodify reports an error message now that such a modification is not supported.
The related commit 22d18ce61 is now in the internal DCMTK testing branch and will visible in the public DCMTK in a few days.
Maybe we can implement this feature in the future. For now you could use dump2dcm to replace pixel data of encapsulated files which is a little bit more uncomfortable. Or if you want to use dcmodify, you can decompress the file first (dcmdjpeg for JPEG, dcmdjpls for JPEG-LS, ...) and insert an uncompressed Pixel Data value using dcmodify options -i, -if, -m or -mf.
Best regards,
Michael
Who is online
Users browsing this forum: No registered users and 1 guest