Write rotated overlay data to rotated dcm

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
dragon_fly
Posts: 16
Joined: Mon, 2012-11-05, 10:52

Write rotated overlay data to rotated dcm

#1 Post by dragon_fly »

Since I post the first help(viewtopic.php?f=1&t=3607),
I tried my best.

My code is as follows:

Code: Select all


int main(int argc, char *argv[])
{
   DicomImageClass::setDebugLevel(0xff);
   E_TransferSyntax xfer=EXS_Unknown;
   DcmFileFormat dfile; 
   OFCondition status = dfile.loadFile("CR.dcm",xfer,   

   EGL_noChange,DCM_MaxReadLength,ERM_autoDetect); 

   DcmDataset *dcmDataset=dfile.getDataset();
   xfer=dcmDataset->getOriginalXfer();
   DicomImage *pImg=new DicomImage(dcmDataset,xfer,CIF_AcrNemaCompatibility ,0,0);

  if (pImg->getStatus()==EIS_Normal)
     {

                unsigned int left,top,width,height;
	   EM_Overlay mode;

	   Uint16 overlayGroupLength;
	   Uint16 overlayRows;
	   Uint16 overlayColumns;
	   const char * overlayType;
	   const Sint16 *overlayOrigin=new Sint16[2];
	   Uint16 overlayBitsAllocated;
	   Uint16 overlayBitPosition;

                 dcmDataset->findAndGetSint16Array(DCM_OverlayOrigin,overlayOrigin);
	   dcmDataset->findAndGetUint16(DCM_OverlayGroupLength,overlayGroupLength);
	   dcmDataset->findAndGetUint16(DCM_OverlayRows,overlayRows);
	   dcmDataset->findAndGetUint16(DCM_OverlayColumns,overlayColumns);
	   dcmDataset->findAndGetString(DCM_OverlayType,overlayType);
	   dcmDataset->findAndGetUint16(DCM_OverlayBitsAllocated,overlayBitsAllocated);
	   dcmDataset->findAndGetUint16( DCM_OverlayBitPosition,overlayBitPosition);  

                  pImg->rotateImage(90);
	   // Uint8 * data=(Uint8*)pImg->getOverlayData(0,left,top,width,height,mode);
	    const void * data=pImg->getFullOverlayData(0,width,height);
	    const size_t size=(size_t)(width*height);
	   //   cout<<"left="<<left<<endl;
	   //   cout<<"top="<<top<<endl;
	   cout<<"width="<<width<<endl;
	   cout<<"height="<<height<<endl;
	   pImg->writeImageToDataset(*dcmDataset);  
                
               // remove old overlay
                 dcmDataset->remove( DCM_OverlayData );
	   dcmDataset->remove(DCM_OverlayRows  );
	   dcmDataset->remove(DCM_OverlayColumns );
	   dcmDataset->remove(DCM_OverlayType );
	   dcmDataset->remove(DCM_OverlayBitsAllocated);
	   dcmDataset->remove(DCM_OverlayBitPosition );
	   dcmDataset->remove(DCM_OverlayOrigin );
                 
                dcmDataset->putAndInsertUint8Array(DCM_OverlayData,OFstatic_cast(const  

                Uint8*,data),width*height);
	  dcmDataset->putAndInsertUint16(DCM_OverlayGroupLength,overlayGroupLength);
	  dcmDataset->putAndInsertUint16(DCM_OverlayRows,height);
	  dcmDataset->putAndInsertUint16(DCM_OverlayColumns,width);
	  dcmDataset->putAndInsertString(DCM_OverlayType,overlayType);
	  dcmDataset->putAndInsertUint16(DCM_OverlayBitsAllocated,overlayBitsAllocated);
	  dcmDataset->putAndInsertUint16(DCM_OverlayBitPosition,overlayBitPosition);

               dcmDataset->putAndInsertSint16Array(DCM_OverlayOrigin,overlayOrigin,2);

	  //dcmDataset->putAndInsertString(DCM_PhotometricInterpretation, "MONOCHROME1");
	  // dcmDataset->putAndInsertUint16(DCM_SamplesPerPixel,1);
	   OFCondition a=dcmDataset->saveFile("Rotated.dcm",xfer);
          
         if (data!=NULL)
	   {
		   cout<<"overlay:"<<width<<"/"<<height<<endl;
	   
		    /*write overlay data(bitmap) to a file*/
		    FILE *file=fopen("overlay.raw","wb");
		    if (file!=NULL)
		    {
		      fwrite(data,size,1,file);
		      fclose(file);
		    }
	   }   else
		   cout<<"no such overlay plane"<<endl;
}
   return 0;
}       


The overlay.raw could show the "L" is rotated by 90 degree form Left to the bottom,but I don't

know why could not write the rotated overlay data to Rotated.dcm ?

Is this code" dcmDataset->putAndInsertUint8Array(DCM_OverlayData,OFstatic_cast(const

Uint8*,data),width*height);"wrong?

The Rotated.dcm was 5M larger than CR.dcm, but the Rotated.dcm could not show the rotated overlay.
Hopes someone will give some advice, I am not very familiar with DCMTK and DICOM standard,I am trying my best to understand them.
Thanks in advance.

dragon_fly
Posts: 16
Joined: Mon, 2012-11-05, 10:52

Re: Write rotated overlay data to rotated dcm

#2 Post by dragon_fly »

DCM_OverlayData has one bit

Problem solved! :mrgreen:

Post Reply

Who is online

Users browsing this forum: Google [Bot], Semrush [Bot] and 1 guest