how to extract frames from DICOM "Mpeg2 Main Profile @ Main Level" file

All other questions regarding DCMTK

Moderator: Moderator Team

Message
Author
Ro2a
Posts: 9
Joined: Fri, 2010-09-17, 17:14

how to extract frames from DICOM "Mpeg2 Main Profile @ Main Level" file

#1 Post by Ro2a »

Hello

I want to develope a programe using VS c++ and dcmtk that can load a dicom file which has the following caracterestics:
Mpeg2 Main Profile @ Main Level --> transfer syntax
YBR_PARTIAL_422 (0028,0004) --> photometric Interpretation
VedioEndoscopocImageStorage --> SOP class UID

I tried to load it use the DicomImage class or DcmFileFormat class but i get always the following error :
can't change to unencapsulated representation for pixel module

so please is it possible to load this type of files using dcmtk and how I can do that ?

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

#2 Post by Michael Onken »

Hi,

the problem with DicomImage class is that DCMTK is not able to decode MPEG2 data in order to access its frames or the "images" included at all. So forget about using DicomImage.

However, loading with DcmFileformat should work. After that you may access the raw MPEG2 data by further API calls, e.g. to visualize it using ffmpeg or any other library/program. Where is DcmFileformat exactly failing?

Best regards,
Michael

Ro2a
Posts: 9
Joined: Fri, 2010-09-17, 17:14

#3 Post by Ro2a »

thank you very much for your answer

In fact with DcmFileFormat I have no loading errors but if I use this Class how I can extract certain frames from the vedio included in this file?

or there is another Class that enables me to do that ??

to be more clear: I want to extarct certain frames numbers(i.e 1,20,56,70) and save them as jpeg images that's why I tried to use DicomImage since it enables me to get the frames that I want.


thank you for you help
regards

Jörg Riesmeier
ICSMED DICOM Services
ICSMED DICOM Services
Posts: 2217
Joined: Fri, 2004-10-29, 21:38
Location: Oldenburg, Germany

#4 Post by Jörg Riesmeier »

MPEG2 data is stored in a single pixel item in DICOM, so the extraction of individual frames is up to the application developer - i.e. you :-)

Ro2a
Posts: 9
Joined: Fri, 2010-09-17, 17:14

#5 Post by Ro2a »

:? :shock: :(

thank you for telling me that ;)

but I really need to know what I have to use or with what I should begin because don't have an experince in using DMCTK .


thank you again and any help tp be able to begin extracting the frames will be very appreciated

best regards

alwittta
Posts: 111
Joined: Wed, 2006-03-15, 08:30

#6 Post by alwittta »

Hi,

Load the image using the DcmFileFormat class and
use the following function to extract pixel data in unsigned 8-bit integers format:

Code: Select all

findAndGetUint8Array(...)
There are different similar functions for accessing pixel data in signed and unsgined 16 and 32 bit format:

Code: Select all

findAndGetUint16Array 
findAndGetSint16Array  
findAndGetUint32Array 
findAndGetSint32Array 
HTH,
Alvin

Ro2a
Posts: 9
Joined: Fri, 2010-09-17, 17:14

#7 Post by Ro2a »

thank you very much for your helpful reply
but I have problem here

Code: Select all

unsigned long count = 0; 
const Uint8 *myPixelData= NULL;
cond = dataset->findAndGetUint8Array(DCM_PixelData, myPixelData,&count);

if(cond.bad())
	{
		cout<<"error get pixel data "<<cond.text()<<endl;
	}
	else 
		cout<<"result count = " << count << endl;
I got always "zero" for the count ;
result count = 0

so could you please tell me what is the problem and what I have to do to solve il to be able to extract the needed frames??

best regards

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

#8 Post by Michael Onken »

Hi,

@alwitta: Thanks for helping out! However, that only works for uncompressed pixel data.

For compressed pixel data you have to use the DcmPixelSequence class due to the internal structure of the compressed PixelData element. This gives you acccess to the included offset table (empty for MPEG2) and all frames. However, for MPEG2 there is only a single "frame" containing all MPEG2 data as a blob . You won't be able to access individual frames with DCMTK because DCMTK does not know how to decompress MPEG2 data and hence is not able to find out where a specific frame begins.

So you have to get the complete MPEG2 data, and then decompress it using another library. I will post an example how to do that soon in the wiki and reference here in the forum topic.

Best regards,
Michael

alwittta
Posts: 111
Joined: Wed, 2006-03-15, 08:30

#9 Post by alwittta »

Hi,

@Ro2a: Sorry for the wrong reply.

@Michael: Thanks for the information.

Meanwhile, in the dcmdump program there is an option to extract the pixel data to file using the +W option.

Code: Select all

dcmdump.exe -d +W d:\output 1.dcm 
Thanks and Regards,
Alvin

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

#10 Post by Michael Onken »

Hi,

here is an howto describing how to access compressed image data with DCMTK.

Hope that helps,
Michael

Ro2a
Posts: 9
Joined: Fri, 2010-09-17, 17:14

#11 Post by Ro2a »

thank you very much for this very interesting way of decompresing the image data using DCMTK

So according to you in all the cases I will not be able to extract certain frames from the MPEG2 DICOM image even if I decompress the data, that's right ??

so I have to use another library in addition to DCMTK in order to achive the extraction of certain frames ???


thank you again for your great help

regards

Jörg Riesmeier
ICSMED DICOM Services
ICSMED DICOM Services
Posts: 2217
Joined: Fri, 2004-10-29, 21:38
Location: Oldenburg, Germany

#12 Post by Jörg Riesmeier »

Of course, if you decompress the MPEG2 stream you would be able to extract certain frames :-) However, this requires some additional library like "ffmpeg".

Btw, we haven't yet added support for compressing and decompressing MPEG2 to the DCMTK mainly because of licensing issues (and because of limited time, of course).

Ro2a
Posts: 9
Joined: Fri, 2010-09-17, 17:14

#13 Post by Ro2a »

I really thank you for your help
but please please please do you have any example hpw to use ffmpeg or sdk in vc++ to decompresse the mpeg file that I have ??

I'm lost here cause I don't know even how to begin

thanks a lot

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

#14 Post by Michael Onken »

Hi,

sorry, I don't have much clue on how to use ffmpeg or the like but you will find some tutorials about it. Especially when you first write the MPEG stream to disk, you might use the ffmpeg commandline tool for the conversion.

Best regards,
Michael

Ro2a
Posts: 9
Joined: Fri, 2010-09-17, 17:14

#15 Post by Ro2a »

thank you and sorry for asking a lot of question but I need you help to tell me at which step I have to decompress the image in order to use within the dcmtk library?

do I decompress it (by using ffmpeg for example) and the I load the image by using fileformat? or after decompressing the MPEG I can load it by using the dicomImage Class ??


regards

Post Reply

Who is online

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