1
votes

I am trying to load a monochrome dicom image file using DCMTK with the example code provided in the docs

http://support.dcmtk.org/docs/mod_dcmimgle.html

The file I am trying to compile is dcmtest.cxx which contains the following code:

#include "dcmtk/dcmimgle/dcmimage.h"
#include "dcmtk/dcmimgle/dipixel.h"
#include "dcmtk/dcmimgle/diimage.h"
#include "dcmtk/dcmimgle/dimo1img.h"
#include "dcmtk/dcmimgle/dimo2img.h"
#include <iostream>
using namespace std;

int main()
{

    DicomImage *image = new DicomImage("test.dcm");
    if (image != NULL)
    {
      if (image->getStatus() == EIS_Normal)
      {
        if (image->isMonochrome())
        {
          image->setMinMaxWindow();
          Uint8 *pixelData = (Uint8 *)(image->getOutputData(8 /* bits */));
          if (pixelData != NULL)
          {
            /* do something useful with the pixel data */
          }
        }
      } else
        cerr << "Error: cannot load DICOM image (" << DicomImage::getString(image->getStatus()) << ")" << endl;
    }

    delete image;
}

I am trying to compile code with:

g++ dcmtest.cxx -DHAVE_CONFIG_H -I$HOME/dcmtk361_std/include -L$HOME/dcmtk361_std/lib -pthread -ldcmdata -lz -loflog -lofstd -o main

which I got from

How to use Dcmtk in Qt?

However, I am getting the error

/tmp/cchsrh2D.o: In function `main':
dcmtest.cxx:(.text+0x31): undefined reference to `DicomImage::DicomImage(char const*, unsigned long, unsigned long, unsigned long)'
dcmtest.cxx:(.text+0xaf): undefined reference to `DicomImage::getString(EI_Status)'
/tmp/cchsrh2D.o: In function `DicomImage::setMinMaxWindow(int)':
dcmtest.cxx:(.text._ZN10DicomImage15setMinMaxWindowEi[_ZN10DicomImage15setMinMaxWindowEi]+0x6b): undefined reference to `DiMonoImage::setMinMaxWindow(int)'
collect2: error: ld returned 1 exit status

I tried to include any relevant sections of the library but have not been able to resolve the issue. I am running Ubuntu 16.04 and downloaded DCMTK from the latest snapshot at http://dicom.offis.de/dcmtk.php.en

Do you know what is causing the compilation issue?

1
You did not mention: Have you built and installed the dcmtk libraries with CMake before trying to link against them? Furthermore for using the DicomImage class, you need to link to dcmimgle as well (and for non-monochrome images, you need to link to dcmimage)kritzel_sw
Yes I built and installed the dcmtk libraries following these instructions gist.github.com/marcinwol/089d4a91f1a1279e33f9 Linking dcmimgle solved the problem (command below).pdiffley
findAndGetString() vs findAndGetOFString() what's the difference. The former API always returns a null buffer for tags like patient name whereas the latter API returns only one character in ASCII? Any idea why is it like this?Xavier Geoffrey

1 Answers

2
votes

As kritzel_sw already wrote: When you use the DicomImage class from the dcmimgle module, you also have to add the dcmimgle library to your linker call. By the way, it should be sufficient to include the "dcmtk/dcmimgle/dcmimage.h" header to your sample program, i.e. there's no need for the other DCMTK header files.