How to use Dcmtk in Qt?

I am working on a project where I need to read a dicom image.

I can not install dcmtk. I am using win7 64-bit and vs2010.

Please explain how to include dcmtk in my program.

+4
source share
4 answers

To use Windows + DCMTK + QT , you need to follow these steps:

  • Compile DCMTK (step 1.A)
  • Create a sample application (step 2)
  • Create your QT project file, referencing the compiled / installed LibMTK Libs (step 3.B)
  • Compile the application in your IDE (step 4.B)

If you read this and don't want to use Qt, I am responding to a version without Qt.

Windows + VisualStudio + DCMTK: Steps 1.A , 2 , 3.A and 4.A

Linux + GCC + DCMTK: Steps 1.B , 2 , N/A , 4.C


1) Compile DCMTK

First of all, to use the DCMTK library in your application, you must compile the DCMTK source code to create the libraries:

As I write this, the latest available version is 3.6.0. So we have to download it:

ftp://dicom.offis.de/pub/dicom/offis/software/dcmtk/dcmtk360/dcmtk-3.6.0.zip

After the download is complete, you need to unzip the folder. The DCMTK source does not have a project file, but this is not a problem; there is a CMakelist file responsible for creating the project file in the desired operating system / compiler. If you are not familiar with the CMake tool, you can read more here ( https://cmake.org/ )

1.A) Compilation on Windows / Visual Studio 2012

1.A.1) You must have a compiler installed, in my case it was Visual Studio 2012

1.A.2) Run the CMake tool to generate the project file in Visual Studio 2012. You need to be able to populate the source DCMTK directory.

1.A.3) Now start VisualStudio 2012, open the sln file created in the previous step (2), and compile the target ALL_BUILD

1.A.4) Re-execute VisualStudio in Admin mode (due to C:\Program Files permission) to compile the target INSTALL (it will copy and install DCMTK to the default path: C:/Program Files/DCMTK/ , we can reference on it like PATH_WHERE_DCMTK_WAS_INSTALLED )

(1.B) Compilation on GNU / Linux GCC

I tested Ubuntu / CentOS. First, you have to go to DCMTK Source and run the following three commands:

 $ ./configure --prefix=path_to_dcmtk $ make all $ sudo make install 

example: path_to_dcmtk = / home / user / dcmtk


2) Create your sample application

Create a file called your_sample/testapp.cxx with the following contents. This is a demo found in the DCMTK Forum to open a DICOM file and print the patient name.

 #include "dcmtk/dcmdata/dctk.h" #include <iostream> using namespace std; int main() { DcmFileFormat fileformat; OFCondition status = fileformat.loadFile("test.dcm"); if (status.good()) { OFString patientsName; if (fileformat.getDataset()->findAndGetOFString(DCM_PatientName, patientsName).good()) { cout << "Patient Name: " << patientsName << endl; }else{ cerr << "Error: cannot access Patient Name!" << endl; } }else{ cerr << "Error: cannot read DICOM file (" << status.text() << ")" << endl; } return 0; } 

3) Creating an application project using VisuaStudio as a compiler

The created file in the previous step should be placed in the project. You can choose one of the options for Windows VisualStudio (3.1) and Windows Qt (3.2) . If you are using Linux, you can skip this step.

3.A) Windows with Visual Studio 2012 IDE

To create a Visual Studio project, you can use the Wizard and set the necessary parameters: Linker , Libraries , etc. However, to facilitate this answer, I will use CMakeList.txt to create a project for Visual Studio 2012. So, create a file called your_sample/CmakeList.txt with the following contents:

 PROJECT(testapp) SET(DCMTK_DIR ABSOLUTE_PATH_WHERE_DCMTK_WAS_INSTALLED) #an example: SET(DCMTK_DIR "C:\\Users\\test\\test_dcmtk\\DCMTK") # settings for Microsoft Visual C++ 6 SET(CMAKE_C_FLAGS "/nologo /W3 /GX /Gy /YX") SET(CMAKE_C_FLAGS_DEBUG "/MTd /Z7 /Od") SET(CMAKE_C_FLAGS_RELEASE "/MT /O2") SET(CMAKE_CXX_FLAGS "/nologo /W3 /GX /Gy /YX") SET(CMAKE_CXX_FLAGS_DEBUG "/MTd /Z7 /Od") SET(CMAKE_CXX_FLAGS_RELEASE "/MT /O2") ADD_DEFINITIONS(-D_REENTRANT) INCLUDE_DIRECTORIES(${DCMTK_DIR}/include) LINK_DIRECTORIES(${DCMTK_DIR}/lib) ADD_EXECUTABLE(testapp testapp) TARGET_LINK_LIBRARIES(testapp netapi32 wsock32 ofstd dcmdata) 

3.B) Windows QtCreator IDE using VisuaStudio as a compiler

To create a project file for the QtCreator IDE. You need to create a file called your_sample/my_project.pro with the following contents:

 SOURCES += testapp.cxx CONFIG += debug console DEFINES += _REENTRANT QMAKE_CFLAGS_RELEASE -= -MD QMAKE_CFLAGS_RELEASE = -MT QMAKE_CFLAGS_DEBUG -= -MDd QMAKE_CFLAGS_DEBUG = -MTd QMAKE_CXXFLAGS_RELEASE -= -MD QMAKE_CXXFLAGS_RELEASE += -MT QMAKE_CXXFLAGS_DEBUG -= -MDd QMAKE_CXXFLAGS_DEBUG += -MTd INCLUDEPATH += (RELATIVE_PATH_WHERE_DCMTK_WAS_INSTALLED)/include #an example: INCLUDEPATH += ../../../test_dcmtk/DCMTK/include LIBS += -L"(RELATIVE_PATH_WHERE_YOU_INSTALLED_DCMTK)/lib" \ -ladvapi32 \ -ldcmdata \ -loflog \ -lofstd \ -lws2_32 \ -lnetapi32 \ -lwsock32 #an example: LIBS += -L"../../../test_dcmtk/DCMTK/lib" \ 

4.A) Windows with Visual Studio 2012 IDE

Open the project file in VisualStudio and click Build .

4.B) Windows with QtCreator IDE using VisuaStudio as a compiler

Open the project file in QT and click Build .

4.C) GNU / Linux - Command line with GCC

 g++ testapp.cxx -DHAVE_CONFIG_H -I/path_to_dcmtk/include -L/path_to_dcmtk/lib -pthread -ldcmdata -lz -loflog -lofstd -o main 

Note that if you compiled libraries in DEBUG mode, your application must also be compiled in DEBUG mode.


References

+15
source

Try the installation instructions for Dcmtk. If you do not know how to include the library in your project, check out the qmake manual.

+2
source

The guys from the Common Toolkit addressed some of these issues. You can also use the Insight Toolkit

http://www.commontk.org/index.php/Main_Page

http://itk.org

In fact, there is little documentation in the ITK wiki, but ITK uses gdcm instead of dcmtk.

http://www.itk.org/Wiki/ITK_FAQ#How_to_read_a_volume_from_a_DICOM_series

+1
source

We have a project that implements DCMTk in Qt - we call it QtDICOM, and it forms the basis of many of our products ( http://fluxinc.ca/medical)/ . Worth a look ( https://bitbucket.org/fluxinc/qt-dicom ). We did not document the configuration particularly well, but you can probably mark it if you look.

Note. It depends on DCMTk, which is built and included in various ways.

+1
source

Source: https://habr.com/ru/post/1340458/


All Articles