Replacing the pixel data of Dicom

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
avpai
Posts: 7
Joined: Fri, 2016-02-26, 08:21

Replacing the pixel data of Dicom

#1 Post by avpai »

Hi,
I have written a code which I intend to use to replace only the pixel data in the dicom file while keeping the rest of the tags same. The code is:-

Code: Select all

                    dataset_dst = dst_fileformat.getDataset();
		*dataset_dst = *dataset_src;// dataset_src is the dataset of the original dicom file
                  Mat input= imread("image.bmp");
		 Uint16 * pixel;
		const unsigned long  size = input.size().height* input.size().width ;
		pixel = ( Uint16 *)malloc(size);

		for (int i = 0; i < input.rows; i++)
		{
			for (int j = 0; j < input.cols; j++)
			{
				*pixel = (Uint16)input.at<uchar>(i, j);
				cout << *pixel;
			}
		}		
		dataset_dst->putAndInsertUint16Array(DCM_PixelData, pixel, true);/// line for replacement		
		dst_fileformat.saveFile("new.dcm");
A new dcm file is created in the end but it has not data and virtually blank.I am able to change other tags like patient name,ID,etc. If I comment off the "line for replacement",then I get the exact copy of the source dicom. Any chance you guys can help me with this? I use OpenCV to get the pixel data of the bmp/tiff image that I want in the new Dicom file.

Michael Onken
DCMTK Developer
Posts: 2049
Joined: Fri, 2004-11-05, 13:47
Location: Oldenburg, Germany
Contact:

Re: Replacing the pixel data of Dicom

#2 Post by Michael Onken »

Hi,

It seems you missed the third parameter of putAndInsertUint16Array() that should denote the number of values in the array.

Best,
Michael

avpai
Posts: 7
Joined: Fri, 2016-02-26, 08:21

Re: Replacing the pixel data of Dicom

#3 Post by avpai »

Hi,

I gave the 'unsigned long size' but that just gave me an absurd image;-
Image

but it should have been
Image

What kind of windowing/interpolation should I use to get the right image?

Michael Onken
DCMTK Developer
Posts: 2049
Joined: Fri, 2004-11-05, 13:47
Location: Oldenburg, Germany
Contact:

Re: Replacing the pixel data of Dicom

#4 Post by Michael Onken »

The right one :)

avpai
Posts: 7
Joined: Fri, 2016-02-26, 08:21

Re: Replacing the pixel data of Dicom

#5 Post by avpai »

c'mon man :D :D

Michael Onken
DCMTK Developer
Posts: 2049
Joined: Fri, 2004-11-05, 13:47
Location: Oldenburg, Germany
Contact:

Re: Replacing the pixel data of Dicom

#6 Post by Michael Onken »

;) I cannot see any images. You can try out dcm2pnm and enable different window settings to see what renders your image best.

avpai
Posts: 7
Joined: Fri, 2016-02-26, 08:21

Re: Replacing the pixel data of Dicom

#7 Post by avpai »

But that's for getting a jpg image from dicom right? I want to do the reverse. That's why I created a new dicom in the end having the new pixel data

Michael Onken
DCMTK Developer
Posts: 2049
Joined: Fri, 2004-11-05, 13:47
Location: Oldenburg, Germany
Contact:

Re: Replacing the pixel data of Dicom

#8 Post by Michael Onken »

You can try dcmodify and use the -i option to change/insert attributes, including pixel data (use the -if option for that). Make sure you adapt attributes like rows, columns, photometric interpretation, pixel representation as well as bits allocated, bits stored and high bit.

Another way is to use dcmdump, a text editor and dump2dcm.

There is no specific code example in DCMTK how to replace the pixel data (and I am not going to write one). img2dcm creates images from scratch, maybe looking into that code helps too.

Best,
Michael

Post Reply

Who is online

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