Modify pixel data and save change

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
ligangs
Posts: 8
Joined: Thu, 2009-11-19, 07:45

Modify pixel data and save change

#1 Post by ligangs »

Hi, everyone,
I have a problem: I want change the Dicom file pixel data and save it. I checked other similar topics but not found the answer.
I do it as these steps:
1. Open file:
DcmFileFormat fileformat;
DcmDataset *dataset = fileformat.getDataset();

OFCondition error = fileformat.loadFile(fname);//load with default params

dataset->loadAllDataIntoMemory();

E_TransferSyntax xfer = dataset->getOriginalXfer();
dataset->chooseRepresentation(xfer, NULL);

2. Get pixel data into dataset
DicomImage *di = new DicomImage(dataset, xfer, 0);
// It is const data, problem is here, i cannot save my change.
Uint8 *pixelData= (Uint8 *)(di->getOutputData(8,0));

for (int i=0;i<count;i++)// count is the data's length
pixelData = ...; // modify data

3. write back modify data
di->writeImageToDataset(*dataset);
delete di;

4. save file
fileformat.saveFile("444.dcm",xfer,EET_ExplicitLength);

another problem is: if i change one series in the Multi-series Dicom file, what can i do?

Hope someone help me, thanks! I think I must misunderstand the Dcmtk.

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

#2 Post by alwittta »

After changing the pixel data, instead of calling writeImageToDataset, you can use the following function to insert back the Pixel Data (pData) to dataset.

Code: Select all

dataset->putAndInsertUint8Array(DCM_PixelData, 
		pData, Height*effWidth); 
I don't understand your second question.
if i change one series in the Multi-series Dicom file, what can i do?

ligangs
Posts: 8
Joined: Thu, 2009-11-19, 07:45

#3 Post by ligangs »

Thank you very much, it runs!
My 2nd problem is:
I have multi frame dicom image, if I change one of the frames, not all frames. I want write back or save a new dicom image with the changed frame, Could you please let me know how to do it?

thanks again.

sorry for my poor english. :oops:

ligangs
Posts: 8
Joined: Thu, 2009-11-19, 07:45

#4 Post by ligangs »

I think I dont describe my 2nd problem clearly.

I have a multi frames dicom image, and i got one of the frame pixel data, and changed it. then i dont know how to write back the changed frame pixel data.

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

#5 Post by Jörg Riesmeier »

From the original posting:
// It is const data, problem is here, i cannot save my change.
Uint8 *pixelData= (Uint8 *)(di->getOutputData(8,0));
As you can read in the documentation, the purpose of the DicomImage class is visualization and not manipulation of DICOM images. The returned pixel array of getOutputData() is the result of the rendering pipeline, i.e. nothing that should be modified as you tried to do. And this is also the reason why the return value is "const"!

If you want to replace the pixel data of the image, you should use the functionality provided by the dcmdata module, e.g. in case of uncompressed pixel data: putAndInsertUint8Array() or putAndInsertUint16Array().

ligangs
Posts: 8
Joined: Thu, 2009-11-19, 07:45

#6 Post by ligangs »

Thank you alwittta and Jörg Riesmeier for your help!

Post Reply

Who is online

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