How to convert 16-bit GrayScale Dicom file with 16bit Tif ?

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
booklayer
Posts: 1
Joined: Wed, 2006-11-08, 05:02

How to convert 16-bit GrayScale Dicom file with 16bit Tif ?

#1 Post by booklayer »

How to convert 16-bit (12-bit) GrayScale Dicom file Image with 16-bit Tif(PNG) file or a memory buffer?

ex)

CxImage::Load("c:\\16bitGraySclae.tif",CXIMAGE_FORMAT_BMP)

char uid[100];
DcmFileFormat fileformat;
DcmDataset *dataset = fileformat.getDataset();
dataset->putAndInsertString(DCM_SOPClassUID, UID_SecondaryCaptureImageStorage);
dataset->putAndInsertString(DCM_SOPInstanceUID, dcmGenerateUniqueIdentifier(uid, SITE_INSTANCE_UID_ROOT));
//add more tags here~~~~~~
dataset->putAndInsertUint16(DCM_SamplesPerPixel,1);
dataset->putAndInsertString(DCM_PhotometricInterpretation,"MONOCHROME2");
dataset->putAndInsertUint16(DCM_BitsAllocated,16);
dataset->putAndInsertUint16(DCM_BitsStored,16);
dataset->putAndInsertUint16(DCM_HighBit,15);
dataset->putAndInsertUint16(DCM_PixelRepresentation,0);
dataset->putAndInsertUint16(DCM_PlanarConfiguration,0);
dataset->putAndInsertUint16(DCM_Rows,GetHeight());
dataset->putAndInsertUint16(DCM_Columns,GetWidth());

//add more tags here

dataset->putAndInsertUint8Array(DCM_PixelData,(UINT8 *)GetBits(), (GetHeight()*info.dwEffWidth)/4);
// GetBits() <<=CxImage /// info.dwEffWidth <<=CxImage

OFCondition status = fileformat.saveFile("C:\\16bit.dcm", EXS_LittleEndianImplicit,EET_UndefinedLength,EGL_withoutGL);
if (status.bad())
AfxMessageBox("Error: cannot write DICOM file ");

Jörg Riesmeier
ICSMED DICOM Services
ICSMED DICOM Services
Posts: 2217
Joined: Fri, 2004-10-29, 21:38
Location: Oldenburg, Germany

#2 Post by Jörg Riesmeier »

You need to extract the pixel data from the TIFF image. I guess, the libtiff that DCMTK uses for the TIFF export also provides an API for this purpose.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest