I would want to read a DICOM image and to save the matrix of raw pixel intensities in a txt file. Running the following code everything works fine with DICOM images that have a pixel representation = EPR_Uint16 (so I think it corresponds to BitsAllocated = 16):
Code: Select all
string fin="mydicom.dcm"
DicomImage *image = new DicomImage(fIn.c_str());
int width = (int)image->getWidth();
int height = (int)image->getHeight();
if (image->getStatus() == EIS_Normal){
const DiPixel *pixeldata = image->getInterData();
Uint16 *pd = (Uint16*)pixeldata->getData();
if (pixeldata != NULL){
/*create the ASCII file*/
fstream rawData;
string rawDataFielName = "out.txt";
rawData.open(rawDataFielName.c_str(), ios::out);
for (int i=0; i< width*height;i++) {
rawData << pd[i] << " " ;
if (i % width == 0 && i != 0) {
rawData << endl;
}
}
}
} else
CERR << "cannot load file: " << fIn << endl;
If in the above code I replace:
Code: Select all
Uint16 *pd = (Uint16*)pixeldata->getData();
Code: Select all
Uint8 *pd = (Uint8*)pixeldata->getData();
Any help?
Thanks,
regards.
Matteo