Overwrite an image/pixel data in the dicom file using dcmtk

自作多情 提交于 2019-12-11 10:03:33

问题


I use dcmtk to read a dicom file and extract the image into a .tiff format. After doing some image processing I have an image which I would like to save in the source dicom file.That is overwriting the old image/pixel data with my new ones, while keeping rest of the data(uid,patient name,,etc) same.

I use the following code to read dicom

OFCondition status = src_fileformat.loadFile(src_path);

    if (status.good())
    {
        Sint32 instanceNumber = 0;
        if (src_fileformat.getDataset()->findAndGetSint32(DCM_InstanceNumber, instanceNumber).good())
        {
            cout << "instance Number N: " << instanceNumber << endl;
            sprintf(instanceNum, "%d", instanceNumber);
            printf("%s\n", instanceNum);
        }

        else
            cerr << "Error: cannot access Instance Number!" << endl;
    }
    else
        cerr << "Error: cannot read DICOM file (" << status.text() << ")" << endl;

    src_dcm = new DicomImage(src_path);
    if (src_dcm != NULL)
    {
        if (src_dcm->getStatus() == EIS_Normal)
        {
            if (src_dcm->isMonochrome())
            {
                src_dcm->setMinMaxWindow();
                Uint8 *pixelData = (Uint8 *)(src_dcm->getOutputData(16 /* bits */));
                if (pixelData != NULL)
                {
                    src_dcm->writeBMP("source.tiff", 24);  /* do something useful with the pixel data */
                }
            }
        }
        else
            cerr << "Error: cannot load DICOM image (" << DicomImage::getString(src_dcm->getStatus()) << ")" << endl;
    }

After image processing I have an image that I want to overwrite onto this source dicom file. I looked into image2dcm,but I couldn't get the correct syntax/method to do. any one help me out.. :)

Edit-1

Image2Dcm i2d; 
I2DOutputPlug *outPlug = new I2DOutputPlugSC(); 
 I2DImgSource *inputPlug = new I2DJpegSource(); 
 E_TransferSyntax writeXfer; 
 inputPlug->setImageFile(jpgFile); 
DcmDataset *dataset = NULL; 
OFCondition result = i2d.convert(inputPlug, outPlug, dataset, writeXfer); 

   // Saving output DICOM image 
  if (result.good()) 
      { 
        dataset->putAndInsertString(DCM_PhotometricInterpretation,"RGB"); 

            DcmFileFormat dcmff(dataset); 
    result = dcmff.saveFile(dcmFile, writeXfer); 
       }

I tried the above shown syntax,but couldn't exactly understand it

This is the processed image(above)

This is the original dicom image that I want to overwrite. Guys ,any idea or help??


回答1:


The basic approach should be:

  1. load the DICOM dataset from file
  2. replace the pixel data in the dataset
  3. modify various other element values (e.g. SOP Instance UID)
  4. save the modified DICOM dataset to a new file

In case of uncompressed images, the second step could be performed in the same manner as the third step, i.e. by an appropriate call of a putAndInsertXXX() method on the dataset. Of course, the element value of the Pixel Data attribute should be in correct DICOM format. See DICOM standard part 3 and 5 for details.



来源:https://stackoverflow.com/questions/35625269/overwrite-an-image-pixel-data-in-the-dicom-file-using-dcmtk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!