Splitting multiframe DICOM files

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
toto1024
Posts: 1
Joined: Tue, 2012-04-03, 08:55

Splitting multiframe DICOM files

#1 Post by toto1024 »

Hi all!

I'm new with the Dcmtk library so I need to ask some questions to start in the right direction.

I need to split a multiframe DICOM image into separate DICOM files, one file per frame. I wouldn't change the compression and I prefer to keep overlays. I suppose each individual DICOM file must contain the same dataset? Only the DCM_NumberOfFrames property will change?

I looked at the dcml2pnm because I saw that DICOM files were splitted into JPEG images, for example. I think it is a good starting point for me because I just have to handle the DICOM file creation.

Could you tell me if I'm wrong.

In the switch...case which is in the for (unsigned int frame = 0; frame < fcount; frame++) loop, I will add a case to handle the DICOM output file.

1. I need to create a FileFormat to be able to generate the DICOM file?

2. I need to copy the original dataset without pixels inside this FileFormat. How can I do that? It seems that the pixels contained inside the DcmDataset object are empty when this dataset has already been attached with a DicomImage object so I need to keep a copy of this dataset?

3. I need to copy the pixels of the frame numbered n. How can I do that? I have a DcmElement containing pixels data. I got this object with the DCM_PixelData and a print of this object give me the output :

Code: Select all

(7fe0,0010) OB (PixelSequence #=13)                     # u/l, 1 PixelData
(fffe,e000) pi 00\00\00\00\a2\21\01\00\54\45\02\00\5c\6d\03\00\68\99\04\00\d6\c5\05\00\46\f3\06\00\3e\21\08\00\92\4e\09\00\90\7c\0a\00\4a\ab\0b\00\da\da\0c\00 #  48, 1 Item
(fffe,e000) pi (not loaded)                             # 74138, 1 Item
(fffe,e000) pi (not loaded)                             # 74666, 1 Item
(fffe,e000) pi (not loaded)                             # 75776, 1 Item
(fffe,e000) pi (not loaded)                             # 76804, 1 Item
(fffe,e000) pi (not loaded)                             # 76902, 1 Item
(fffe,e000) pi (not loaded)                             # 77160, 1 Item
(fffe,e000) pi (not loaded)                             # 77296, 1 Item
(fffe,e000) pi (not loaded)                             # 77132, 1 Item
(fffe,e000) pi (not loaded)                             # 77302, 1 Item
(fffe,e000) pi (not loaded)                             # 77490, 1 Item
(fffe,e000) pi (not loaded)                             # 77704, 1 Item
(fffe,e000) pi (not loaded)                             # 77542, 1 Item
(fffe,e0dd) na (SequenceDelimitationItem)               #   0, 0 SequenceDelimitationItem
I suppose I need to query for DCM_Item inside this object?

4. I need to set the number of frames to 1 with putAndInsertString() function, because each dicom output file will contain only one frame?

5. I save the file with the saveFile from FileFormat but I can't give it a FILE object, so it will take a path as char *.

Best regards.
toto1024 :)

Michael Onken
DCMTK Developer
Posts: 2051
Joined: Fri, 2004-11-05, 13:47
Location: Oldenburg, Germany
Contact:

Re: Splitting multiframe DICOM files

#2 Post by Michael Onken »

Hi Toto,
toto1024 wrote:Hi all!

I'm new with the Dcmtk library so I need to ask some questions to start in the right direction.

I need to split a multiframe DICOM image into separate DICOM files, one file per frame. I wouldn't change the compression and I prefer to keep overlays. I suppose each individual DICOM file must contain the same dataset? Only the DCM_NumberOfFrames property will change?
Note that overlays can be a bit more complicated since it is possible to define that overlays only apply for specific frames and are not to be shown on others.

The datasets of the resulting files can be different, however, since they have the same image characteristics (like Rows, Columns), at least those corresponding attributes should be the same. This is more a logical reason than one enforced by the DICOM standard (there are no rules how to split a DICOM multiframe image).
I looked at the dcml2pnm because I saw that DICOM files were splitted into JPEG images, for example. I think it is a good starting point for me because I just have to handle the DICOM file creation.
Could you tell me if I'm wrong.
No, you're right: It (dcmj2pnm) is a good starting to see how to access each frame. However, note that dcmj2pnm does decompress the pixel data! It does not take over the JPEG data in the DICOM file.
In the switch...case which is in the for (unsigned int frame = 0; frame < fcount; frame++) loop, I will add a case to handle the DICOM output file.

1. I need to create a FileFormat to be able to generate the DICOM file?
One approach would be to open the file to convert, copy the frame you need to memory and then delete the pixel data element from the dataset in memory. Then, adapt all attributes necessary and save it to a new filename.
2. I need to copy the original dataset without pixels inside this FileFormat. How can I do that? It seems that the pixels contained inside the DcmDataset object are empty when this dataset has already been attached with a DicomImage object so I need to keep a copy of this dataset?
See question 1. As far as I remember, DicomImage can take over the pixel data from the dataset in order to prevent it from doing a copy. You can control the behaviour with the flag "CIF_MayDetachPixelData". If you disable this, then the dataset should keep a copy of the pixel data. Search for the flag in DCMTK source code to see how it is used (it is evaluated in dcmimgle/libsrc/diimage.cc).
3. I need to copy the pixels of the frame numbered n. How can I do that? I have a DcmElement containing pixels data. I got this object with the DCM_PixelData and a print of this object give me the output :

Code: Select all

(7fe0,0010) OB (PixelSequence #=13)                     # u/l, 1 PixelData
(fffe,e000) pi 00\00\00\00\a2\21\01\00\54\45\02\00\5c\6d\03\00\68\99\04\00\d6\c5\05\00\46\f3\06\00\3e\21\08\00\92\4e\09\00\90\7c\0a\00\4a\ab\0b\00\da\da\0c\00 #  48, 1 Item
(fffe,e000) pi (not loaded)                             # 74138, 1 Item
(fffe,e000) pi (not loaded)                             # 74666, 1 Item
(fffe,e000) pi (not loaded)                             # 75776, 1 Item
(fffe,e000) pi (not loaded)                             # 76804, 1 Item
(fffe,e000) pi (not loaded)                             # 76902, 1 Item
(fffe,e000) pi (not loaded)                             # 77160, 1 Item
(fffe,e000) pi (not loaded)                             # 77296, 1 Item
(fffe,e000) pi (not loaded)                             # 77132, 1 Item
(fffe,e000) pi (not loaded)                             # 77302, 1 Item
(fffe,e000) pi (not loaded)                             # 77490, 1 Item
(fffe,e000) pi (not loaded)                             # 77704, 1 Item
(fffe,e000) pi (not loaded)                             # 77542, 1 Item
(fffe,e0dd) na (SequenceDelimitationItem)               #   0, 0 SequenceDelimitationItem
I suppose I need to query for DCM_Item inside this object?
Compressed pixel data enforces a "pseudo sequence" within the pixel data element. This is called "pixel sequence"; so if you get the elemten Pixel Data from the surrounding dataset, it should identify itself (call ident() function on it) as EVR_pixelSQ. If so, cast it DcmPixelSequence. On such an object you can then call getItem which returns you a DcmPixelItem object representing one of above Items.
4. I need to set the number of frames to 1 with putAndInsertString() function, because each dicom output file will contain only one frame?
Yes. In many cases you also can remove the number of frames element completely. However, it depensd on the type of object, e.g. CTImageStorage object, ... Look into the standard part 3 and checkout the description of the corresponding IOD. DICOM is not that easy in this regard.
5. I save the file with the saveFile from FileFormat but I can't give it a FILE object, so it will take a path as char *.
Yes. (?!)

As a final note: You can look at the img2dcm tool which reads JPEG images from the file system and converts to DICOM objects. It does not support multiframe but it might help you to see how construction of the object works.

Best,
Michael

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest