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:-
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.
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.