Can not create a dcm file from bmp file

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
candy
Posts: 24
Joined: Mon, 2008-10-20, 08:37

Can not create a dcm file from bmp file

#1 Post by candy »

HI,I Want to create a dcm file from a 8-bits bmp file which was converted from a dcm file. The bmp file's biCompression is 0.
There are my codes:

Code: Select all

void main()
{
	

	

DcmFileFormat fileformat; 
DcmDataset *dataset = fileformat.getDataset(); 

dataset->putAndInsertString(DCM_ImageType,"ORIGINAL");
dataset->putAndInsertString(DCM_SOPClassUID,"1.2.1.2.840.10008.5.1.4.1.1.2");
dataset->putAndInsertString(DCM_SOPInstanceUID, "1.12.123.1234.12345"); 
dataset->putAndInsertString(DCM_StudyDate,"19950608");
dataset->putAndInsertString(DCM_SeriesDate,"19950608");
dataset->putAndInsertString(DCM_ContentDate,"19950608");
dataset->putAndInsertString(DCM_StudyTime,"19950608");
dataset->putAndInsertString(DCM_ContentTime,"133132.0");
dataset->putAndInsertString(DCM_AccessionNumber,"THU9948");
dataset->putAndInsertString(DCM_Modality,"CT");
dataset->putAndInsertString(DCM_Manufacturer,"WS");
dataset->putAndInsertString(DCM_InstitutionName,"HOSPITAL");
dataset->putAndInsertString(DCM_ReferringPhysiciansName,"S LISOOK");
dataset->putAndInsertString(DCM_StationName,"WS");
dataset->putAndInsertString(DCM_StudyDescription,"CHEST/ABD");

dataset->putAndInsertString(DCM_PatientsName,"WILKINS^CHARLES");
dataset->putAndInsertString(DCM_PatientID,"GE0514");
dataset->putAndInsertString(DCM_PatientsBirthDate,"19780126");
dataset->putAndInsertString(DCM_PatientsSex,"M");
dataset->putAndInsertString(DCM_PatientsAge,"31");
dataset->putAndInsertString(DCM_PatientsWeight,"0");
dataset->putAndInsertString(DCM_ContrastBolusAgent,"180CC HYPAQUE");
dataset->putAndInsertString(DCM_ScanOptions,"");
dataset->putAndInsertString(DCM_SliceThickness,"10.000000");
dataset->putAndInsertString(DCM_KVP,"120");
dataset->putAndInsertString(DCM_GantryDetectorTilt ,"0.000000");
dataset->putAndInsertString(DCM_TableHeight,"164.699997");
dataset->putAndInsertString(DCM_ExposureTime,"1000");
dataset->putAndInsertString(DCM_XRayTubeCurrent,"290");
dataset->putAndInsertString(DCM_Exposure,"120");
dataset->putAndInsertString(DCM_PatientPosition,"FFS");


dataset->putAndInsertString(DCM_StudyInstanceUID,"1.2.840.113674.514.212.200");
dataset->putAndInsertString(DCM_SeriesInstanceUID,"1.2.840.113674.514.212.82.200");
dataset->putAndInsertString(DCM_StudyID,"1784");
dataset->putAndInsertString(DCM_SeriesNumber,"2");
dataset->putAndInsertString(DCM_AcquisitionNumber,"2");
dataset->putAndInsertString(DCM_InstanceNumber,"18");

//dataset->putAndInsertString(DCM_PatientOrientation,"L\P");
dataset->putAndInsertString(DCM_PatientOrientation,"\P");
dataset->putAndInsertString(DCM_ImagePositionPatient,"-202.000000\-200.000000\-245.699997");
dataset->putAndInsertString(DCM_ImageOrientationPatient,"1.000000\0.000000\0.000000\0.000000\1.000000\0.000000");
dataset->putAndInsertString(DCM_FrameOfReferenceUID,"1.2.840.113619.2.1.1.2702582133.1041.802576484.625");
dataset->putAndInsertString(DCM_Laterality,"L");
dataset->putAndInsertString(DCM_PositionReferenceIndicator,"SN");
dataset->putAndInsertString(DCM_SliceLocation,"-245.699997");
dataset->putAndInsertString(DCM_PixelSpacing,"0.781250\0.781250");
dataset->putAndInsertString(DCM_PixelRepresentation,"1");

dataset->putAndInsertString(DCM_Rows, "512"); 
dataset->putAndInsertString(DCM_Columns, "512"); 
dataset->putAndInsertString(DCM_SamplesPerPixel, "1"); 
//dataset->putAndInsertString(DCM_PhotometricInterpretation, "1"); 
//dataset->putAndInsertString(DCM_SamplesPerPixel, "1"); 
dataset->putAndInsertString(DCM_PhotometricInterpretation, "MONOCHROME2"); 
dataset->putAndInsertString(DCM_RescaleIntercept,"0");
dataset->putAndInsertString(DCM_BitsAllocated, "16"); 
dataset->putAndInsertString(DCM_BitsStored, "16"); 
dataset->putAndInsertString(DCM_HighBit, "15"); 
dataset->putAndInsertString(DCM_WindowCenter, "0"); 
dataset->putAndInsertString(DCM_WindowWidth, "400"); 
dataset->putAndInsertString(DCM_RescaleIntercept,"0");
dataset->putAndInsertString(DCM_RescaleSlope,"1");



BITMAPFILEHEADER bmpFH; 
BITMAPINFOHEADER bmpIH;
BITMAPINFOHEADER *pbmpIH=&bmpIH;


unsigned char buf[512*512]; 
FILE *image; 

if ( (imagen = fopen("IMAGE13.bmp","r+")) == NULL ) 
{ 
   printf("no existe"); 
   exit(0); 
} 

fread(&bmpFH,sizeof(bmpFH),1,image); 
fread(&bmpIH,sizeof(bmpIH),1,image); 
fseek(imagen, bmpFH.bfOffBits, SEEK_SET);
long size=bmpFH.bfSize-bmpFH.bfOffBits;
fread(buf,size ,1,image);


dataset->putAndInsertUint8Array(DCM_PixelData, buf,size );
  
OFCondition status = fileformat.saveFile("test.dcm", EXS_LittleEndianExplicit); 
if (status.bad()) 
cerr << "Error: cannot write DICOM file (" << status.text() << ")" << endl;
}
At last ,I got a wrong dcm file which was displayed wrong.I have tried some ways to find out why failed,But I failed. :cry:
Please tell me what's wrong with it.
Regards,
Candy

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 »

I hope you understand that we are not going to debug your code.

However, if the BMP file has really a depth of 8 bits (monochrome palette?) why are you setting Bits Stored to 16? Additionally, I don't think that your BMP pixel data is signed, so you should set Pixel Representation to "0". Please also note that the rows of pixel data in a BMP file are often stored upside-down (see description of the format).

Btw, all these issues are not related to the DCMTK but to the DICOM standard. So, I would recommend to read the relevants parts of the standard very thoroughly ...
Last edited by Jörg Riesmeier on Wed, 2009-04-15, 09:57, edited 1 time in total.

candy
Posts: 24
Joined: Mon, 2008-10-20, 08:37

#3 Post by candy »

Thank you so much! I will read the standards thoroughly. You are right! Forgive my so simple questions! I will keep on going to study DICOM with your dcmtk toolkit!

Post Reply

Who is online

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