-2

I would like to be able to display in a Dicom image in a Qt project with the same render as a Dicom Viewer Program could give.

I was able to do it but with a very bad contrast. I heard you need to operate on the pixels but I'm not sure. Do you have a working example ?

EDIT: I add my code in case it helps you, I commented a lot of things because I noticed the result was exactly the same

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <iostream>
#undef UNICODE
#undef _UNICODE
#include <dcmtk/config/osconfig.h>
#include <dcmtk/dcmdata/dctk.h>
#include <dcmtk/dcmimgle/dcmimage.h>
#include <QPixmap>
#include <QLabel>
#include <QImageReader>

using namespace std;

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    //int sizeX = 600;
   // int sizeY = 600;


    //initialize random seed
    //srand (time(NULL));


    //QImage image = QImage( sizeX, sizeY, QImage::Format_RGB32 );

    /*for( int l=0; l<sizeX; l++ )
    {
        for( int c=0; c<sizeY; c++ )
        {
            ///Random color for each pixel
            //image.setPixel( l, c, qRgb(rand() % 256, rand() % 256, rand() % 256) );

            ///Fixed color for each pixel
            image.setPixel( l, c, qRgb(100, 150, 200) );
        }
    }*/
    const char *file = "/home/x4rkz/project/Laura/QTImage/IMG00000";
    DicomImage *image = new DicomImage(file);


    if (image != NULL)
        {
          if (image->getStatus() == EIS_Normal)
          {
            Uint8 *pixelData = (Uint8 *)(image->getOutputData(8 )); // bits per sample
            // Uint8 is a pointer to internal memory buffer
            if (pixelData != NULL)
            {
                // do something useful with the pixel data
                QImage img(pixelData,image->getWidth(), image->getHeight(), QImage::Format_Indexed8 );
                /*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->setColorCount(256);
                    // define gray palette here
                    for (int 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 < (long) width; x++)
                        {
                            px[x] = (unsigned char) (*pd);
                            pd++;
                        }
                    }*/


                    QGraphicsScene * graphic = new QGraphicsScene( this );

                    graphic->addPixmap( QPixmap::fromImage( img ) );

                    ui->graphicsView->setScene(graphic);

               /* }else
                    cout << "Non monochrome image" << endl;*/


            }
          } else
            cerr << "Error: cannot load DICOM image (" << DicomImage::getString(image->getStatus()) << ")" << endl;
        }
  }

MainWindow::~MainWindow()
{
    delete ui;
}









#include "mainwindow.h"
#include <QApplication>
#include <iostream>
#undef UNICODE
#undef _UNICODE
#include <dcmtk/config/osconfig.h>
#include <dcmtk/dcmdata/dctk.h>
#include <dcmtk/dcmimgle/dcmimage.h>
#include <QPixmap>
#include <QLabel>
#include <QImageReader>

using namespace std;

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec();
}

enter image description here

As you cant see, the result has no constrast.

x4rkz
  • 513
  • 4
  • 19
  • 1
    Please share your current code, so that we can see, what you have already achieved. Otherwise the question is too broad. – Tarmo R Jun 29 '18 at 05:37
  • I added the source, it is a mix of stuff I found on the internet because I haven’t been to find proper documentation/examples so far – x4rkz Jun 29 '18 at 10:25
  • You are using indexed, or palette image format. Your commented out code sets palette to be linear grayscale. If you get the same result with that piece of code commented out, then it means that is the default color table. Try a different one, for example `color.setRgb(i, (i & 0x0F) << 4, i>>4);` (just a random untested example which should give you a bit of color...). – hyde Jul 02 '18 at 06:55

1 Answers1

1

As you cant see, the result has no constrast.

If the rendered image has such a low contrast, you should try to set an appropriate VOI (Value of Interest) window, e.g. using image->setMinMaxWndow(). See API documentation for details.

J. Riesmeier
  • 1,641
  • 10
  • 14