getInterData with multiframe dicom files

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
Mercusyo
Posts: 34
Joined: Mon, 2011-10-31, 15:22

getInterData with multiframe dicom files

#1 Post by Mercusyo »

Hello,

I used the "getInterData" method for reading the real pixel data. But I don't know how use this methode with multifram dicom files ?
I only have the first frame :?

Code: Select all

	bool isReturn = false;
	unsigned long NbByte = 0;
	unsigned short* pixelData = NULL;
	// Récupération des données de l'image
	DicomImage* img = new DicomImage(filename, NULL, 0, nbFrame);
	if (img->getStatus() == EIS_Normal)
	{
		const DiPixel *inter = img->getInterData();		
		if (inter != NULL)
		{
			NbByte = inter->getCount();	
			if (NbByte > 0)
			{
				pixelData = (unsigned short*)inter->getData();				
				unsigned long lDataSize = img->getOutputDataSize()/sizeof(unsigned short); // Nombre de valeurs dans la matrice des pixels
				if (pixelData != NULL)
				{
					std::cout << "NbByte : " << NbByte << std::endl;		
					short iScalar = getScalarSize(filename);
					std::cout << "iScalar : " << iScalar << std::endl;
					/*for (unsigned long i = 0; i < lDataSize; i++)
					{						
						value[i] = pixelData[i];
					}*/
					std::memcpy(value, pixelData, lDataSize);
					if (value != NULL)
						isReturn = true;
					free(pixelData);
				}
			}
		}
	}
	return isReturn;
NB : I have to use the "getRepresentation", this snippet is just a test ...
Thank you a lot for your help,

J. Riesmeier
DCMTK Developer
Posts: 2506
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: getInterData with multiframe dicom files

#2 Post by J. Riesmeier »

First of all, you shouldn't mix output (rendered) and intermediate pixel data as you do with getOutputDataSize() and getInterData().

Regarding your actual question: The pixel data of all frames are stored consecutively. Please note, however, that color images are internally stored in planes!

Mercusyo
Posts: 34
Joined: Mon, 2011-10-31, 15:22

Re: getInterData with multiframe dicom files

#3 Post by Mercusyo »

Thank you for your reply :!:

I suspected that I can't mix these 2 methods ... How can I do for reading a frame of a dicom multi frame with the "getInterData" methode, please :?:

Thank you,

Best regards,

J. Riesmeier
DCMTK Developer
Posts: 2506
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: getInterData with multiframe dicom files

#4 Post by J. Riesmeier »

You should check what the internal representation of the pixel data is, i.e. you should use DiPixel::getRepresentation(). The resolution of the image can be determined with getRows(), getColumns() and getFrameCount().

Mercusyo
Posts: 34
Joined: Mon, 2011-10-31, 15:22

Re: getInterData with multiframe dicom files

#5 Post by Mercusyo »

Ok thank you for your help.
Another question, should I use the "getInputCount" method or "getCount()" to determine the number of bytes of the file :?:
I used the internal representation and I created 6 methods like this : (example for unsigned char*)

Code: Select all

bool getInternalPixelDataUint8(const char* filename, unsigned char* value, unsigned long fstart, const int nbFrame)
{
	bool isResult = false;
	unsigned long NbByte = 0;
	unsigned char* pixelData = NULL;
	unsigned long lFlag = nbFrame>1?CIF_UsePartialAccessToPixelData:CIF_MayDetachPixelData;
	DicomImage* img = new DicomImage(filename, lFlag, fstart, nbFrame);
	if (img->getStatus() == EIS_Normal)
	{
		const DiPixel *inter = img->getInterData();		
        if (inter != NULL)
        {
			NbByte = inter->getInputCount();
			if (NbByte > 0)
			{
				pixelData = (unsigned char*)inter->getData();
				unsigned int lFrameSize = (NbByte/nbFrame)*sizeof(unsigned char);
				if (pixelData != NULL)
				{
					std::memcpy(value, pixelData, lFrameSize);
					if (value != NULL)
						isResult = true;
					free(pixelData);
				}
			}
        }
	}
	return isResult;
}
Best regards,

J. Riesmeier
DCMTK Developer
Posts: 2506
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: getInterData with multiframe dicom files

#6 Post by J. Riesmeier »

Using DiPixel::getCount() would be correct since you are interested in the intermediate representation and not in the PixelData element stored in the DICOM dataset.
I used the internal representation and I created 6 methods like this : (example for unsigned char*)
Looks pretty cumbersome. Why don't you use a C++ template (or a switch statement) for the 6 variants? By the way, casting away const from the return value of DiPixel::getData() and freeing this memory is no good idea! :shock: Also, what is the purpose of checking the "value" parameter for being non-NULL after you copied data to it? Your code does not seem to be very robust.

Mercusyo
Posts: 34
Joined: Mon, 2011-10-31, 15:22

Re: getInterData with multiframe dicom files

#7 Post by Mercusyo »

Ok thank you for your reply. I created of course a template for this method. Yesterday, it was just a test.
My project was developed in C++ Builder, and I uses Visual Studio C++ to create a DLL for mangling methods between C++ Builder and VSC++.

Best regards,

Mercusyo
Posts: 34
Joined: Mon, 2011-10-31, 15:22

Re: getInterData with multiframe dicom files

#8 Post by Mercusyo »

Hello,
I have some troubles with different multi frame dicom files. Can I send you this files :?: If yes, how :?:

For exemple, I have a dicom file with 15 frames. The "type representation" is "unsigned char*"; I recover the 8 first frames correctly, but not the other frames ... the frame 9 to 15 is binary the same :?: But in reality no ...
I looked the file with "Dicom Eye" and with my own Viewer in C++ Builder, the 8 first frames are the same, but the other frames no ...
I don't understand what is happens.

Thanks a lot for your idea,

Bes regards,

J. Riesmeier
DCMTK Developer
Posts: 2506
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: getInterData with multiframe dicom files

#9 Post by J. Riesmeier »

You should first check that the issue is not related to your code. This could e.g. be done by using the DCMTK command line tool dcm2pnm/dcmj2pnm with option --all-frames and --write-bmp (if you prefer BMP images as output).

Mercusyo
Posts: 34
Joined: Mon, 2011-10-31, 15:22

Re: getInterData with multiframe dicom files

#10 Post by Mercusyo »

Hello,

Thank you for your help ! I found what was wrong. Indeed, the were some errors in my source code ...

Best regards,

Post Reply

Who is online

Users browsing this forum: Baidu [Spider] and 1 guest