getOutputData slow?

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
martinrame
Posts: 347
Joined: Mon, 2009-02-23, 19:57

getOutputData slow?

#1 Post by martinrame »

Hi I'm using this method to show dicom images in Qt, but it is slow when I change the Window Level/Window Width on large images, i.e. CR images.

Code: Select all

    uchar* pixelData = (uchar *)(d->m_dicomImage->getOutputData(QDicomImagePrivate::IMG_DEPTH, p_frame, p_planar));
    if (d->m_dicomImage->isMonochrome())
    {
      //Monochroom images
      //transform representation from dcmtk(gray) to qimage (gray)
      for(unsigned y=0; y < d->m_dicomImage->getHeight(); y++)
      {
        uchar* scanLine = d->m_qimage.scanLine(y);
        for(unsigned x = d->m_dicomImage->getWidth(); x != 0; --x)
        {
          *(scanLine++) = *(pixelData++);
        }
      }
    }
This returns a QImage, wich is converted to a QPixmap, then shown in a QGraphicsPixmapItem who is part of a QGraphicsView.

The question is, is there a way to speed up the performance of this?

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 don't think that getOutputData() is the reason for the bad performance. About 8 or 9 years ago, I used the code snippet described in the following posting for much larger (mammography) images!

martinrame
Posts: 347
Joined: Mon, 2009-02-23, 19:57

#3 Post by martinrame »

Thanks Jörg, you are right, is not getOutputData what is causing the slow performance, the bottleneck is loadFromData.

I used a QTimer to measure the time loadFromData consumes, an I'm getting 125ms aprox on each call. This is too much while doing W/L transformations, compared to Aeskulap, for example.

This is the code I'm using to paint the pixmap. Do you find something that can be improved/optimized?.

Code: Select all

void QDicomImage::getQPixmap(QPixmap &pixmap)
{

    QTime myTimer;
    myTimer.start();
    QString s;
    s.setNum(myTimer.elapsed());
    qDebug("Start:" + s.toAscii());

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

    const int width = (int)(d->m_dicomImage->getWidth());
    const int height = (int)(d->m_dicomImage->getHeight());
    char header[32];
    int PPM = 0;
    if (PPM!=0 &&PPM!=2)
        sprintf(header, "P6\n%i %i\n65535\n",width, height);
    else
        sprintf(header, "P5\n%i %i\n65535\n",width, height);

    int offset = strlen(header);

    unsigned int length=(d->m_dicomImage->getOutputDataSize (8));

    Uint8 *buffer = new Uint8[length+offset];
    if (buffer != NULL)
    {
        OFBitmanipTemplate<Uint8>::copyMem((const Uint8 *)header, buffer, offset);

        bool t=d->m_dicomImage->getOutputData((buffer+offset), length, 8);

        if (PPM!=0){//on a un PPM
            s.setNum(myTimer.elapsed());
            qDebug("before loadFromData:" + s.toAscii());

              if (!pixmap.loadFromData((const unsigned char *)buffer, (length+offset), "PPM",Qt::AvoidDither))
              {
              // delete pixmap;
                 pixmap = NULL;
              }
              s.setNum(myTimer.elapsed());
              qDebug("after loadFromData:" + s.toAscii());

          }
          else//on charge un PGM
          {
              s.setNum(myTimer.elapsed());
              qDebug("before loadFromData:" + s.toAscii());

              if (!pixmap.loadFromData((const unsigned char *)buffer,(length+offset), "PGM", Qt::AvoidDither))
              {
              // delete pixmap;
                 pixmap = NULL;
              }
              s.setNum(myTimer.elapsed());
              qDebug("after loadFromData:" + s.toAscii());
              
          }
    }

    DJDecoderRegistration::cleanup();
    DcmRLEDecoderRegistration::cleanup();
}

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

#4 Post by Jörg Riesmeier »

As for monochrome/grayscale image, QT was always doing a palette analysis when I used it 8 or 9 years ago. Therefore, I patched the QT sources to avoid this time-consuming step. I also made sure that my display system (monitor and graphics adapter) only supported the output of grayscale images (i.e. no color).

Unfortunately, I didn't use QT for many years, so I cannot tell whether there is a better solution in a more recent version of this toolkit. Maybe, you should ask other QT users or the people at Nokia ...

martinrame
Posts: 347
Joined: Mon, 2009-02-23, 19:57

#5 Post by martinrame »

Ok, I'll ask in the Qt forums.

BTW, can I ask wich toolkit do you use in case of developing a Dicom Viewer for Linux/Unix?

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

#6 Post by Jörg Riesmeier »

I would use QT :-)

Post Reply

Who is online

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