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.
Modify pixel data and save change
Moderator: Moderator Team
After changing the pixel data, instead of calling writeImageToDataset, you can use the following function to insert back the Pixel Data (pData) to dataset.
I don't understand your second question.
Code: Select all
dataset->putAndInsertUint8Array(DCM_PixelData,
pData, Height*effWidth);
if i change one series in the Multi-series Dicom file, what can i do?
-
- ICSMED DICOM Services
- Posts: 2217
- Joined: Fri, 2004-10-29, 21:38
- Location: Oldenburg, Germany
From the original posting:
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().
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"!// It is const data, problem is here, i cannot save my change.
Uint8 *pixelData= (Uint8 *)(di->getOutputData(8,0));
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().
Who is online
Users browsing this forum: Ahrefs [Bot], Baidu [Spider] and 1 guest