I am working on a project where I have to read a dicom image.
I am unable to install dcmtk. I am using win7 64-bit and vs2010.
Please explain the procedure to include dcmtk in my program.
To use the Windows
+ DCMTK
+ QT
, you need to execute these follow steps:
If you are reading this and don't want to use the Qt, I am answering a version without Qt as well.
Windows+VisualStudio+DCMTK: Steps
1.A
,2
,3.A
and4.A
Linux+GCC+DCMTK: Steps
1.B
,2
,N/A
,4.C
First of all, to use the DCMTK library in your application, you should compile the DCMTK source code to generate the libraries:
While I am writing this, the last available version is 3.6.0. So, we should download it:
ftp://dicom.offis.de/pub/dicom/offis/software/dcmtk/dcmtk360/dcmtk-3.6.0.zip
After the download is finished, you need to unzip the folder. The DCMTK source doesn't have a project file, but it is not a problem, there is a CMakelist file responsible for generating a project file in your desirable Operational System/Compiler. If you are not familiar with CMake tool, you can read more here (https://cmake.org/)
1.A.1) You need to have an installed compiler, in my case, it was the Visual Studio 2012
1.A.2) Run the CMake tool
to generate a project file to Visual Studio 2012. You need be able to fill the source
DCMTK directory.
1.A.3) Now, execute the VisualStudio 2012, open the file sln
created in the previous step (2) and compile the target ALL_BUILD
1.A.4) Re-Execute VisualStudio in Admin
mode (because of permission C:\Program Files
) to compile the target INSTALL
(it will copy and install the DCMTK to default path: C:/Program Files/DCMTK/
, we can reference it such PATH_WHERE_DCMTK_WAS_INSTALLED)
I have tested at Ubuntu/CentOS. The first, you should go to DCMTK Source
and run these following three commands:
$ ./configure --prefix=path_to_dcmtk
$ make all
$ sudo make install
example: path_to_dcmtk = /home/user/dcmtk
Create a file called your_sample/testapp.cxx
with the following content. This a demonstration found in DCMTK Forum to open a DICOM file and print the patient's 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's Name: " << patientsName << endl;
}else{
cerr << "Error: cannot access Patient's Name!" << endl;
}
}else{
cerr << "Error: cannot read DICOM file (" << status.text() << ")" << endl;
}
return 0;
}
The created file at the previous step needs to be placed in a project. You can choose between the option Windows VisualStudio (3.1)
and Windows Qt (3.2)
. If you are using Linux, you can skip this step.
To create a Visual Studio project, you can use the Wizard
and set the necessary settings such: Linker
, Libraries
, etc. However, to make easier on this answer, I will use the CMakeList.txt
to create a Project for Visual Studio 2012. So, please, create a file called your_sample/CmakeList.txt
with the following content:
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)
To create a project file for QtCreator IDE. You need to create a file called your_sample/my_project.pro
with the following content:
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" \
Open the project file at VisualStudio
and click on Build
.
Open the project file at QT
and click on Build
.
g++ testapp.cxx -DHAVE_CONFIG_H -I/path_to_dcmtk/include -L/path_to_dcmtk/lib -pthread -ldcmdata -lz -loflog -lofstd -o main
Please, note that whether you have compiled the libraries in
DEBUG
mode, your application should be compiled inDEBUG
mode as well.
How Install http://support.dcmtk.org/docs/file_install.html
DCMTK Docs http://support.dcmtk.org/docs/
FAQ #40: How do I use the DCMTK libraries in my own application? [MSVC] http://forum.dcmtk.org/viewtopic.php?f=4&t=652
CMake Configuration http://support.dcmtk.org/wiki/dcmtk/howto/cmakeconfiguration360
Try to follow the instructions for the Dcmtk installation. If you don't know how to include the library in your project, study the qmake manual.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With