DICOM @ OFFIS

Discussion Forum for OFFIS DICOM Tools - For registration, send email with desired user name to the OFFIS DICOM team
It is currently Thu, 2017-11-23, 00:51

All times are UTC + 1 hour




Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Tue, 2015-02-10, 15:12 
Offline

Joined: Fri, 2015-01-23, 15:36
Posts: 27
Hi to all,
I want to decompress a DICOM file like in this example http://support.dcmtk.org/docs/mod_dcmjpeg.html
But my problem is that I don't want to load a file.

I have an array which inside there are the PixelData values Compressed. I have tried in this way but doesn't work.

Code:
DJDecoderRegistration::registerCodecs();
DJEncoderRegistration::registerCodecs();

DcmFileFormat fileformat;
DJ_RPLossless param_lossless;
      
DcmDataset *pDataset = fileformat.getDataset();
pDataset->chooseRepresentation(EXS_JPEGProcess14SV1, &param_lossless);
            
BYTE*   pBufferImg = (BYTE*)pArray->ImgDicom.GetAt(0); //here I have my PixelData
//I put it into my dataset
pDataset->putAndInsertUint8Array(DCM_PixelData, pBufferImg, pArray->NumByteImg);
//decompress
OFCondition status = pDataset->chooseRepresentation(EXS_LittleEndianExplicit, NULL); //status is OK
...
//add all the tags like Rows, Columuns, BitStored, etc
...
if (pDataset->canWriteXfer(EXS_LittleEndianExplicit))
{
   fileformat.saveFile("test.dcm", EXS_LittleEndianExplicit);
}

DJDecoderRegistration::cleanup(); // deregister JPEG codecs
DJEncoderRegistration::cleanup();


The file test.dcm is created but I can't open it (free Dicom Viewr software crash) and the dimension is equal to the compressed file, so the decode procedure doesn't work... What is my error?


Top
 Profile  
 
PostPosted: Tue, 2015-02-10, 19:21 
Offline
DCMTK Developer

Joined: Tue, 2011-05-03, 14:38
Posts: 1874
Location: Oldenburg, Germany
According to the DICOM standard, compressed pixel data is stored in a special way, so-called "encapsulated format" (see DICOM part 5 for details). So, your "simple" approach with the byte array does not work.


Top
 Profile  
 
PostPosted: Wed, 2015-02-11, 09:14 
Offline

Joined: Fri, 2015-01-23, 15:36
Posts: 27
J. Riesmeier wrote:
According to the DICOM standard, compressed pixel data is stored in a special way, so-called "encapsulated format" (see DICOM part 5 for details). So, your "simple" approach with the byte array does not work.

Oh I see, so what I can do with DCMTK library? I have also tried in this way

Code:
pDataset->findAndGetElement(DCM_PixelData, dummyElem);
                  
Uint32 frameSize;
dummyElem->getUncompressedFrameSize(pDataset, frameSize);

BYTE* buf = new BYTE[frameSize];
OFString decompressedColorModel;
Uint32 startFragment = 0;
Uint32 fakeSize = frameSize - 1;

pDataset->loadAllDataIntoMemory();
DcmFileCache *cache = NULL;

OFCondition status = dummyElem->getUncompressedFrame(pDataset, 0, startFragment, buf, fakeSize, decompressedColorModel, cache);


If I use frameSize instead of frameSize-1 I have "Too many bytes requested" this is why I have used minus one.

The Frame size is correct but getUncompressedFrame is Illegal call, perhaps wrong parameter and I don't understand why....


Last edited by GiordiX on Wed, 2015-02-11, 09:27, edited 1 time in total.

Top
 Profile  
 
PostPosted: Wed, 2015-02-11, 09:16 
Offline

Joined: Fri, 2015-01-23, 15:36
Posts: 27
This is another way that I have found as a solution to my problem on internet

Code:
///. get PixelData element in DCM dataset
pDcmDataSet->findAndGetPixelData(...);
///. get PixelSequence in PixelData element
pPixelData->getEncapsulatedRepresentation(...)
///. get PixelItem in PixelSequence
pDcmPixelSequence->getItem(...);
///. get frame in Pixel Item
pPixelItem->getUint8Arrary(...);


But in my case the getItem fail...
Can you provide some example that use the array of the Pixel Data?


Top
 Profile  
 
PostPosted: Wed, 2015-02-11, 11:39 
Offline
DCMTK Developer

Joined: Tue, 2011-05-03, 14:38
Posts: 1874
Location: Oldenburg, Germany
Unfortunately, it's not clear to me what "pArray->ImgDicom" contains. Is it a JPEG stream (just the pixel data with JPEG markers) or the content of a DICOM Pixel Data element (where the transfer syntax of the DICOM dataset is JPEG lossless compressed).


Top
 Profile  
 
PostPosted: Wed, 2015-02-11, 12:16 
Offline

Joined: Fri, 2015-01-23, 15:36
Posts: 27
J. Riesmeier wrote:
Unfortunately, it's not clear to me what "pArray->ImgDicom" contains. Is it a JPEG stream (just the pixel data with JPEG markers) or the content of a DICOM Pixel Data element (where the transfer syntax of the DICOM dataset is JPEG lossless compressed).


The second, a DICOM Pixel Data element (where the transfer syntax of the DICOM dataset is JPEG lossless compressed).

My approach was move this PixelData in one dataset, change the representation, and save the file but as you say this is not possibile.

So I change my approach: move this PixelData in one dataset, get again the PixelData and put it in one dummy DcmElement, get the FrameSize from the dummy (and I have the value that I expected for the decomressed file to save), get the Frame with dummyElem->getUncompressedFrame but I'm stuck in this part, where I have "Illegal call perhaps wrong parameter" error and I can't understand why....

The codec are registered...
The size is correct... Where is my error?


Top
 Profile  
 
PostPosted: Wed, 2015-02-11, 14:12 
Offline
DCMTK Developer

Joined: Tue, 2011-05-03, 14:38
Posts: 1874
Location: Oldenburg, Germany
What do you mean by "move this PixelData in one dataset"? How did you actually do that?


Top
 Profile  
 
PostPosted: Wed, 2015-02-11, 14:20 
Offline

Joined: Fri, 2015-01-23, 15:36
Posts: 27
J. Riesmeier wrote:
What do you mean by "move this PixelData in one dataset"? How did you actually do that?


With a putAndInsert function
Code:
dataset->putAndInsertUint8Array(DCM_PixelData, bufferOfMyPixelDataCompressed, NumByteImg);


But in any case, if you for a second forget my code, if I have an array which inside there is the PixelData value compressed (coming from a compressed Dicom file), how can I generate and save a DICOM file uncompressed? A decode request, but without loading any file...


Top
 Profile  
 
PostPosted: Wed, 2015-02-11, 14:28 
Offline
DCMTK Developer

Joined: Tue, 2011-05-03, 14:38
Posts: 1874
Location: Oldenburg, Germany
I'm sorry but this line does not show how you "move pixel data" (it only puts a byte array into the pixel data element, which only works for uncompressed pixel data, of course). Could you please provide a more detailed description on what you actually want to do. As I said, compressed pixel data is stored differently ("encapsulated format").


Top
 Profile  
 
PostPosted: Wed, 2015-02-11, 14:44 
Offline

Joined: Fri, 2015-01-23, 15:36
Posts: 27
J. Riesmeier wrote:
I'm sorry but this line does not show how you "move pixel data" (it only puts a byte array into the pixel data element, which only works for uncompressed pixel data, of course). Could you please provide a more detailed description on what you actually want to do. As I said, compressed pixel data is stored differently ("encapsulated format").


First of all thanks for your answers.
I want to do the same thing that works for uncompressed pixel data but with compressed pixel data.

So, inside an array I have compressed pixel data and starting from this I want another byte array that contains the UNcompressed Pixel data; in such a way now I can use the putAndInsertUint8Array function because, as you said, this "only works for uncompressed pixel data".

Hope is clear, sorry for my english


Top
 Profile  
 
PostPosted: Wed, 2015-02-11, 15:05 
Offline
DCMTK Developer

Joined: Tue, 2011-05-03, 14:38
Posts: 1874
Location: Oldenburg, Germany
Quote:
So, inside an array I have compressed pixel data and starting from this I want another byte array that contains the UNcompressed Pixel data; in such a way now I can use the putAndInsertUint8Array function because, as you said, this "only works for uncompressed pixel data".

I think we go i circles. I still don't know what your use case is. You have a byte array with JPEG compressed data and want to generate a decompressed version of the contained pixel data, right? So, where does DICOM come into play?


Top
 Profile  
 
PostPosted: Wed, 2015-02-11, 15:19 
Offline

Joined: Fri, 2015-01-23, 15:36
Posts: 27
J. Riesmeier wrote:
Quote:
So, inside an array I have compressed pixel data and starting from this I want another byte array that contains the UNcompressed Pixel data; in such a way now I can use the putAndInsertUint8Array function because, as you said, this "only works for uncompressed pixel data".

I think we go i circles. I still don't know what your use case is. You have a byte array with JPEG compressed data and want to generate a decompressed version of the contained pixel data, right? So, where does DICOM come into play?


Yes, right.

Because for make the compression of the data (the same that now I want uncompressed) I have used the DCMTK library in this way:

starting from an array of byte of my Uncompressed Jpeg Image, I put it into a dataset with
dataset->putAndInsertUint8Array(DCM_PixelData, myArraySource, sizeBuffer)
//add all the necessary DICOM tags Rows, Columns, Bitstored, etc
//make the compression with
pdataset->chooseRepresentation(EXS_JPEGProcess14SV1, &param_lossless);
//accessing to compressed pixel data with the procedure of the HowTo (http://support.dcmtk.org/redmine/projec ... ressedData)
//now I have the original compressed pixel data

What I want to do now is the viceversa, starting from the original compressed pixel data, I want to uncompressed it and save in a new array, that I can transfer in a dataset using putAndInsertUint8Array. How can I do this???
I must work with the array because I do this things inside another existing project that use the DICOM files.


Top
 Profile  
 
PostPosted: Wed, 2015-02-11, 18:50 
Offline
DCMTK Developer

Joined: Tue, 2011-05-03, 14:38
Posts: 1874
Location: Oldenburg, Germany
You have to create a DcmPixelSequence, insert the pixel items with the JPEG data (the first item always contains the basic offset table), and then use DcmPixelData::putOriginalRepresentation() to put the pixel sequence to the DICOM PixelData element. Code examples can be found both in "dump2dcm.cc" and in "xml2dcm.cc". Also "img2dcm" and its underlying classes should contain such code, e.g. in Image2Dcm::insertEncapsulatedPixelData().

But before you do that, please read the relevant parts of DICOM P3.5 and make sure that you understood how the encapsulated format for compressed pixel data works.


Top
 Profile  
 
PostPosted: Thu, 2015-02-12, 17:34 
Offline

Joined: Fri, 2015-01-23, 15:36
Posts: 27
J. Riesmeier wrote:
You have to create a DcmPixelSequence, insert the pixel items with the JPEG data (the first item always contains the basic offset table), and then use DcmPixelData::putOriginalRepresentation() to put the pixel sequence to the DICOM PixelData element. Code examples can be found both in "dump2dcm.cc" and in "xml2dcm.cc". Also "img2dcm" and its underlying classes should contain such code, e.g. in Image2Dcm::insertEncapsulatedPixelData().
But before you do that, please read the relevant parts of DICOM P3.5 and make sure that you understood how the encapsulated format for compressed pixel data works.


SOLVED! Thank you very much for your advices. :wink:
insertEncapsulatedPixelData() is exactly what I need: I made the same steps of this function and I have put my pixel data in my dataset in the correct way.
I have also read the relevant parts of DICOM P3.5 and I have understood some part of the encapsulated format, but not all.
It's quite difficult for me but I will study more.


Top
 Profile  
 
PostPosted: Tue, 2015-09-08, 21:37 
Offline

Joined: Thu, 2012-10-25, 07:18
Posts: 4
GiordiX wrote:
J. Riesmeier wrote:
You have to create a DcmPixelSequence, insert the pixel items with the JPEG data (the first item always contains the basic offset table), and then use DcmPixelData::putOriginalRepresentation() to put the pixel sequence to the DICOM PixelData element. Code examples can be found both in "dump2dcm.cc" and in "xml2dcm.cc". Also "img2dcm" and its underlying classes should contain such code, e.g. in Image2Dcm::insertEncapsulatedPixelData().
But before you do that, please read the relevant parts of DICOM P3.5 and make sure that you understood how the encapsulated format for compressed pixel data works.


SOLVED! Thank you very much for your advices. :wink:
insertEncapsulatedPixelData() is exactly what I need: I made the same steps of this function and I have put my pixel data in my dataset in the correct way.
I have also read the relevant parts of DICOM P3.5 and I have understood some part of the encapsulated format, but not all.
It's quite difficult for me but I will study more.


Would it be possible to elaborate on how you use the function insertEncapsulatedPixelData? It's a private method, and I'm wondering how you exposed it. I too would like to convert a compressed stream using the DCMTK jpeg decoder. Thanks,


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next

All times are UTC + 1 hour


Who is online

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


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group