Inserting modified pixel data in a multiframe dicom image?

Compilation and installation of DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
faisal_tum
Posts: 33
Joined: Fri, 2013-01-11, 15:37

Inserting modified pixel data in a multiframe dicom image?

#1 Post by faisal_tum »

I've already managed to learn how I can modify the pixel data of a single frame dicom image. Now,I'm trying to do the same in case of multiframe images. I'm can extract all the necessary information and even can extract the pixel data individually for each frame and can modify them. But the problem arise when I have to insert the modified pixel data. In case of single frame I use the method in DcmDataset:

Code: Select all

putAndInsertUint8Array()
.
But I can't see any option like that for the multi-frame image. I get the pixel data for each frame using this method in DcmElement:

Code: Select all

getUncompressedFrame
, where I just have to put the frame index to get the corresponding pixel data. But while inserting I could not find any such option. My programming code is as following:

Code: Select all

int main()
{
	MdfDatasetManager file;
	if(EC_Normal==file.loadFile("test.dcm",ERM_autoDetect,EXS_Unknown))
	{
		DcmDataset *dataset = file.getDataset();
		E_TransferSyntax xfer= dataset->getOriginalXfer();
		bool OriginallyCompressed=false;
		if(xfer!=0 && xfer !=1 && xfer!=2 && xfer!=3)
		{
			OriginallyCompressed=true;
			DJDecoderRegistration::registerCodecs();
			if(EC_Normal==dataset->chooseRepresentation(EXS_LittleEndianExplicit, NULL))
			{
				if(dataset->canWriteXfer(EXS_LittleEndianExplicit))
				{
					cout<<"Originally it's a compressed image, but now decompressed!\n";
				}
			}
		}
		DcmElement* element=NULL;
		Uint16 rows = 0;
		Uint16 cols = 0;
		Uint16 samplePerPixel = 0;
		Uint16 planarConfiguration = 0;
		int index=0;
		// I've fixed these values but later I will change them to dinaymic and make it work as per user's wish.
		int ymin=50;//minimum rows
		int ymax=500;//maximum rows
		int xmin=100;//Minimum columns
		int xmax=600;//Maximum columns
		if(EC_Normal==dataset->findAndGetUint16(DCM_Rows, rows))
		{
			if(EC_Normal==dataset->findAndGetUint16(DCM_Columns, cols))
			{
				if(EC_Normal==dataset->findAndGetUint16(DCM_SamplesPerPixel,samplePerPixel))
				{	
					if(EC_Normal==dataset->findAndGetUint16(DCM_PlanarConfiguration,planarConfiguration))
					{
						if(EC_Normal==dataset->findAndGetElement(DCM_PixelData,element))
						{
							Uint32 startFragment=0;
							Uint32 sizeF=0;
							element->getUncompressedFrameSize(dataset,sizeF);
							long int numOfFrames=0;
							dataset->findAndGetLongInt(DCM_NumberOfFrames,numOfFrames);
							for(int i=0;i<int(numOfFrames);i++)
							{
								Uint8 * buffer = new Uint8[int(sizeF)];
								OFString decompressedColorModel=NULL;
								DcmFileCache * cache=NULL;
								if(EC_Normal==element->getUncompressedFrame(dataset,i,startFragment,buffer,sizeF,decompressedColorModel,cache))
								{
									Uint8 * newBuffer = new Uint8[int(sizeF)];
									if(buffer != NULL)
									{
										for(unsigned long y = 0; y < rows; y++)
										{
											for(unsigned long x = 0; x < cols; x++)
											{
												if(planarConfiguration==0)
												{
													if(x>xmin && x<xmax && y>ymin && y<ymax)
													{
														index=(x + y +  y*(cols-1))*samplePerPixel;
														newBuffer[index]  = 0;
														newBuffer[index + 1]  = 0;
														newBuffer[index +2]  = 0;
													}
													else
													{
														index=(x + y +  y*(cols-1))*samplePerPixel;
														newBuffer[index]  = buffer[index];
														newBuffer[index + 1]  = buffer[index + 1];
														newBuffer[index + 2]  = buffer[index + 2];
													}
												}
											}
										}
									}
									delete newBuffer;
								}
								delete buffer;
							}
						}
					}
				}
			}
		}
	}
	return 0;
}
If I just manage to find a way to insert the modified pixel data for each frame, this program will be complete. Please suggest me what I should do.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest