convert 24bit bmp to dicom, picture's color changed,why?

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
abchjb
Posts: 6
Joined: Fri, 2005-12-23, 15:47

convert 24bit bmp to dicom, picture's color changed,why?

#1 Post by abchjb »

hello,
I use the code below,convert 24bit bmp to dicom,but dicom file's color error, can u help me?(windows xp+vc6+gui plus+dcmtk):
void CImage2dcmDlg::OnBtnSave()
{
Bitmap* pbitmap;

pbitmap=Bitmap::FromFile(L"c:\\demo.bmp");
long iheight=pbitmap->GetHeight();
long iwidth=pbitmap->GetWidth();
long iarea=iheight*iwidth*3;

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));

dataset->putAndInsertString(DCM_StudyInstanceUID,dcmGenerateUniqueIdentifier(uid, SITE_INSTANCE_UID_ROOT));
dataset->putAndInsertString(DCM_StudyDate,"20051231");
dataset->putAndInsertString(DCM_StudyTime,"20051231");
dataset->putAndInsertString(DCM_StudyID,"1234567");

////////////////////////////////
dataset->putAndInsertString(DCM_SeriesInstanceUID,dcmGenerateUniqueIdentifier(uid, SITE_INSTANCE_UID_ROOT));
dataset->putAndInsertString(DCM_SeriesNumber,"0");
dataset->putAndInsertString(DCM_Modality,"SC");
dataset->putAndInsertString(DCM_ConversionType,"DV");
dataset->putAndInsertString(DCM_AccessionNumber,"123456");

dataset->putAndInsertString(DCM_Manufacturer,"DCMTK");
dataset->putAndInsertString(DCM_InstitutionName,"DCMTK");

dataset->putAndInsertString(DCM_PatientsName, "Doe^John");
dataset->putAndInsertString(DCM_PatientID,"DEMOID");
dataset->putAndInsertString(DCM_PatientsBirthDate,"20051231");
dataset->putAndInsertString(DCM_PatientsSex,"M");

dataset->putAndInsertUint16(DCM_SamplesPerPixel,3);
dataset->putAndInsertString(DCM_PhotometricInterpretation,"RGB");
dataset->putAndInsertUint16(DCM_BitsAllocated,8);
dataset->putAndInsertUint16(DCM_BitsStored,8);
dataset->putAndInsertUint16(DCM_HighBit,7);
dataset->putAndInsertUint16(DCM_PixelRepresentation,0);
dataset->putAndInsertUint16(DCM_PlanarConfiguration,0);
dataset->putAndInsertUint16(DCM_Rows,iheight);
dataset->putAndInsertUint16(DCM_Columns,iwidth);

//add more tags here

BitmapData bmData;
Rect rect(0, 0, iwidth, iheight);

pbitmap->LockBits(&rect,ImageLockModeRead,PixelFormat24bppRGB,&bmData);
pbitmap->UnlockBits(&bmData);

dataset->putAndInsertUint8Array(DCM_PixelData, (BYTE *)(bmData.Scan0), iarea);

OFCondition status = fileformat.saveFile(m_dstfile, EXS_LittleEndianImplicit,EET_UndefinedLength,EGL_recalcGL);

if (status.bad())
AfxMessageBox("Error: cannot write DICOM file ");
else
AfxMessageBox("Success: write DICOM file ");

}

Genghis86
Posts: 10
Joined: Mon, 2005-08-29, 13:50
Location: Toronto, Canada
Contact:

#2 Post by Genghis86 »

Check if the Red and Blue channels might have been swapped accidentally.

abchjb
Posts: 6
Joined: Fri, 2005-12-23, 15:47

thanks

#3 Post by abchjb »

thank u very much! why or under what circumstance does it happen ?

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

#4 Post by Michael Onken »

BMP uses internally b,g,r order for storing the colour components, DICOM uses "standard" RGB (r,g,b) order for RGB images.

Regards,
Michael

abchjb
Posts: 6
Joined: Fri, 2005-12-23, 15:47

thanks, It work fine!

#5 Post by abchjb »

thanks!

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 1 guest