dcmtk with QT

All other questions regarding DCMTK

Moderator: Moderator Team

Message
Author
cxl2253
Posts: 10
Joined: Mon, 2007-03-19, 05:38

#31 Post by cxl2253 »

i use follwing code to show image in QT,Almost is ok

DJDecoderRegistration::registerCodecs();
DcmRLEDecoderRegistration::registerCodecs();

QPixmap *pixmap = NULL;

DcmFileFormat *dfile = new DcmFileFormat();
QString fileName = QFileDialog::getOpenFileName(
0,
"Select one or more files to open",
"D:\\gdcmData",
"Images (*.*)");
OFCondition cond = dfile->loadFile(fileName.toAscii().data(), EXS_Unknown, EGL_withoutGL, DCM_MaxReadLength, ERM_autoDetect);
if (cond.bad())
{
printf("eror"); return;

}

E_TransferSyntax xfer = dfile->getDataset()->getOriginalXfer();
DicomImage *image = new DicomImage(dfile, xfer);

int i;
QColor color;
QImage* img;
void * pDicomDibits;
uchar *px;
uchar pixel[4];
const int width = (int)(image->getWidth());
const int height = (int)(image->getHeight());
if (image->isMonochrome())
{
img=new QImage(width,height,QImage::Format_Indexed8);
img->setNumColors(256);
// define gray palette here
for (i=0; i<256; i++) {
color.setRgb(i, i, i);
img->setColor(i, color.rgb());
}
image->createWindowsDIB(pDicomDibits, 0, 0, 8, 0, 1);
unsigned char * pd;
pd=(unsigned char *)pDicomDibits;
for (int y=0; y < (long) height; y++)
{
px = img->scanLine(y);
for (int x=0; x < (ulong) width; x++)
{
px[x] = (unsigned char) (*pd);
pd++;

}
}
}
else
{
img=new QImage(width,height,QImage::Format_RGB32);
image->createWindowsDIB(pDicomDibits, 0, 0, 24, 0, 1);
unsigned char * pd;
pd=(unsigned char *)pDicomDibits;
for (int y=0; y < (long) height; y++)
{
px = img->scanLine(y);
for (int x=0; x < (ulong) width; x++)
{
QRgb *row = (QRgb*) px;

pixel[2] = (unsigned char) (*(pd+3*y*width+3*x));
pixel[1] = (unsigned char) (*(pd+3*y*width+3*x+1));
pixel[0] = (unsigned char) (*(pd+3*y*width+3*x+2));

//pixel[3] = (unsigned char) (*pd++);

row[x] = qRgb(pixel[0], pixel[1], pixel[2]);

}
}

}

img->save("c:\\test2.bmp"); // now can show on QLable or save
DJDecoderRegistration::cleanup();
DcmRLEDecoderRegistration::cleanup();

Géant Vert
Posts: 18
Joined: Fri, 2007-04-13, 08:40

#32 Post by Géant Vert »

Thanks for your help. But I 've got the same problem to read my image with your code.

This image are:

-16bits
-grayscale not rgb
-Hight bits:15
-Monochrome2
-Pixel representation 0

if you are other idea,i listen you :idea: .

Géant Vert
Posts: 18
Joined: Fri, 2007-04-13, 08:40

#33 Post by Géant Vert »

I can give my image if you want test because I don't understand why it don't load correctly.

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

#34 Post by Jörg Riesmeier »

Did you already check the image with "dcm2pnm" in verbose/debug mode?

cxl2253
Posts: 10
Joined: Mon, 2007-03-19, 05:38

#35 Post by cxl2253 »

dear Géant Vert
you can send the test image to me . My emails : cxl2253@gmail.com

Post Reply

Who is online

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