mercure-imaging / mercure

mercure DICOM Orchestrator
https://mercure-imaging.org
MIT License
66 stars 32 forks source link

getdcmtags compilation guide #52

Closed alipairon closed 1 year ago

alipairon commented 1 year ago

Hello everyone! I've decided to contribute to community a little by creating this guide, which details how I compile getdcmtags after making some modifications. I hope I didn't forget anything.

getdcmtags with libiconv compilation Guide

This guide will help you to compile the getdcmtags application on Ubuntu 20.04 with libiconv. The steps may be similar for other Linux distributions. I prefer doing this on clean dedicated Ubuntu VM.

Prerequisites

  1. cmake and ccmake installed on your Ubuntu 20.04 system.
  2. Download the libiconv library from the DCMTK official website.
  3. Download DCMTK (version 3.6.7 or later, not tested with earlier versions) from the DCMTK official website.

Installing libiconv

  1. Extract the downloaded libiconv archive.
  2. Navigate into the extracted directory:
    cd <path-to-unpacked-dir>
  3. Build and install libiconv:
    sudo ./configure && sudo make && sudo make install && sudo ldconfig

Installing DCMTK

  1. Extract the downloaded DCMTK archive.
  2. Navigate into the extracted directory:
    cd <path-to-unpacked-dcmtk-dir>
  3. Configure the build:
    cmake .
  4. Launch the CMake configuration tool:
    ccmake .
    • In the configuration menu, ensure that libiconv is available and has been located correctly in the system.
  5. If the previous step is successful, build and install DCMTK:
    sudo make && sudo make install
  6. Verify the installation by running any DCMTK utility, such as dcmdump.

Building getdcmtags

With the prerequisites installed, you can now compile the getdcmtags application.

  1. Navigate to the directory containing the getdcmtags main.cpp file.
  2. Compile the application using g++:
    g++ -o getdcmtags main.cpp -I/usr/local/include/dcmtk -ldcmdata -loflog -lofstd -lz -ldl -lpthread -liconv -lcharset

    The compilation process should not take long. Once complete, you will have a getdcmtags binary ready for use.

tblock79 commented 1 year ago

Many thanks for sharing this information! Moving it to the Discussion Board, as it's not a bug or issue.

tblock79 commented 1 year ago

Compiling the getdcmtags binary can be done using the following commands:

sudo apt-get update
sudo apt-get install qt5-qmake qtbase5-dev qtbase5-dev-tools libdcmtk-dev
cd /opt/mercure/app/getdcmtags
qmake
make
aarontovars commented 7 months ago

Could you please provide more information on the compilation of DCMTK process with libiconv? @tblock79 @alipairon @joshy @RoyWiggins

This is the output of my ccmake . command:

 BUILD_APPS                       ON
 BUILD_SHARED_LIBS                OFF
 CMAKE_BUILD_TYPE                 Release
 CMAKE_INSTALL_PREFIX             /usr/local
 DCMTK_DEFAULT_DICT               external
 DCMTK_ENABLE_CHARSET_CONVERSIO   libiconv
 DCMTK_ENABLE_LFS                 lfs64
 DCMTK_ENABLE_PRIVATE_TAGS        OFF
 DCMTK_ENABLE_STL                 OFF
 DCMTK_LINK_STATIC                OFF
 DCMTK_MODULES                    ofstd;oflog;dcmdata;dcmimgle;dcmimage;dcmjpeg;dcmjpls;dcmtls;dcmnet;dcmsr;dcmsign;dcmwlm;dcmqrdb;dcmpstat;dcmrt;dcmiod;dcmfg;dcmseg;dc
 DCMTK_PORTABLE_LINUX_BINARIES    OFF
 DCMTK_WITH_DOXYGEN               OFF
 DCMTK_WITH_ICONV                 ON
 DCMTK_WITH_ICU                   OFF
 DCMTK_WITH_OPENSSL               ON
 DCMTK_WITH_PNG                   OFF
 DCMTK_WITH_STDLIBC_ICONV         OFF
 DCMTK_WITH_THREADS               ON
 DCMTK_WITH_TIFF                  OFF
 DCMTK_WITH_WRAP                  OFF
 DCMTK_WITH_XML                   OFF
 DCMTK_WITH_ZLIB                  ON
 ICU_INCLUDE_DIR                  ICU_INCLUDE_DIR-NOTFOUND
 OpenJPEG_DIR                     OpenJPEG_DIR-NOTFOUND

And this is the output of my dcmdump --version command:

$dcmtk: dcmdump v3.6.7 2022-04-22 $

dcmdump: Dump DICOM file and data set

Host type: x86_64-Linux
Character encoding: UTF-8
Build options: shared threads lfs extern-dict dcmdictpath char-conv

External libraries used:
- ZLIB, Version 1.2.11
- LIBICONV, Version 1.16

If I try to execute dcmdump /vagrant/0.dcm --convert-to-utf8 I still get:

F: Cannot select source character set: SpecificCharacterSet (0008,0005) value 'ISO 2022 IR 100' not supported: converting file to UTF-8: /vagrant/0.dcm
alipairon commented 7 months ago

Could you please provide more information on the compilation of DCMTK process? @tblock79 @alipairon @joshy @RoyWiggins

This is the output of my ccmake . command:

 BUILD_APPS                       ON
 BUILD_SHARED_LIBS                OFF
 CMAKE_BUILD_TYPE                 Release
 CMAKE_INSTALL_PREFIX             /usr/local
 DCMTK_DEFAULT_DICT               external
 DCMTK_ENABLE_CHARSET_CONVERSIO   libiconv
 DCMTK_ENABLE_LFS                 lfs64
 DCMTK_ENABLE_PRIVATE_TAGS        OFF
 DCMTK_ENABLE_STL                 OFF
 DCMTK_LINK_STATIC                OFF
 DCMTK_MODULES                    ofstd;oflog;dcmdata;dcmimgle;dcmimage;dcmjpeg;dcmjpls;dcmtls;dcmnet;dcmsr;dcmsign;dcmwlm;dcmqrdb;dcmpstat;dcmrt;dcmiod;dcmfg;dcmseg;dc
 DCMTK_PORTABLE_LINUX_BINARIES    OFF
 DCMTK_WITH_DOXYGEN               OFF
 DCMTK_WITH_ICONV                 ON
 DCMTK_WITH_ICU                   OFF
 DCMTK_WITH_OPENSSL               ON
 DCMTK_WITH_PNG                   OFF
 DCMTK_WITH_STDLIBC_ICONV         OFF
 DCMTK_WITH_THREADS               ON
 DCMTK_WITH_TIFF                  OFF
 DCMTK_WITH_WRAP                  OFF
 DCMTK_WITH_XML                   OFF
 DCMTK_WITH_ZLIB                  ON
 ICU_INCLUDE_DIR                  ICU_INCLUDE_DIR-NOTFOUND
 OpenJPEG_DIR                     OpenJPEG_DIR-NOTFOUND

And this is the output of my dcmdump --version command:

$dcmtk: dcmdump v3.6.7 2022-04-22 $

dcmdump: Dump DICOM file and data set

Host type: x86_64-Linux
Character encoding: UTF-8
Build options: shared threads lfs extern-dict dcmdictpath char-conv

External libraries used:
- ZLIB, Version 1.2.11
- LIBICONV, Version 1.16

If I try to execute dcmdump /vagrant/0.dcm --convert-to-utf8 I still get:

F: Cannot select source character set: SpecificCharacterSet (0008,0005) value 'ISO 2022 IR 100' not supported: converting file to UTF-8: /vagrant/0.dcm

I've encountered a similar problem.

The SpecificCharacterSet is incorrect in this DICOM file, It can have 'ISO 2022 IR 100' value only when extensions are used. For example ISO 2022 IR 100 \ ISO 2022 IR 37 -> is correct bold ISO 2022 IR 100 -> is incorrect and this is causes the error. That's why dcmconv stumbles on such datasets.

In your case you need to either change the encoding to ISO_IR 100 in dataset manually, then dcmconv will work. Or create some workaround for such annoying problems in getdcmtags to mitigate such problems. I've done fix like that, it's not perfect but works for me:

if (tagSpecificCharacterSet.compare("ISO_IR 6") == 0)
    {
        // To prevent annoying DCMTK Warning in logs about charset 
        tagSpecificCharacterSet = "";
    }    

if (!charsetConverter.selectCharacterSet(tagSpecificCharacterSet).good())
{
    // If the first attempt fails, try with "ISO_IR 100"
    tagSpecificCharacterSet = "ISO_IR 100";
    if (!charsetConverter.selectCharacterSet(tagSpecificCharacterSet).good())
    {
        std::cout << "ERROR: Unable to perform character set conversion with both character sets! " << std::endl;
        std::cout << "ERROR: Incoming charset is " << tagSpecificCharacterSet << std::endl;
        return 1;
    }
}