ITK installation and reading DICOM sequence

One: ITK function

The main functions of ITK and OpenCV are similar, both of which are oriented to image processing, but there are certain differences in the field of application between the two; ITK is mainly used for segmentation and registration of medical images (c++ and python versions are available). OPENCV is the basis of computer vision (with c++ and python versions), it can be said that OPENCV will definitely be used in two-dimensional image algorithms. Many pre-processing tasks for machine learning and deep learning are also done by opencv.

Two: compile

environment:

Windows10

VS2019

Download the ITK software package from the official website:

63419f4452bdd1bf48a9cde236161c4e.png

Create the installation directory:

a70ba65fd057919a9d3efb437fcd2312.png

And create build and bin folders in ITK5.2.0

0dd2b3a0fe9003ddcf2c5aecf4a4eb6b.png

Start compiling with Cmake:

source code: Change the directory to the previously downloaded itk decompression file.

binaries: The directory is the previously built build folder.

Click configure to run.

aff6685d38cecd75f3d8d8f48654104f.png

Then choose your own corresponding configuration:

94c0a77e8d615f1e858443f41d14163a.png

After the above is over, a bunch of red will pop up, and then check advanced.

BUILD_SHARED_LIBS is off by default, which means that the library is statically compiled and only lib is generated. If selected, it will be dynamically compiled and a dll file will be generated (selected here)

d96c57e7511f622169fae5806db93f86.png

Find the CMAKE_INSTALL_PREFIX option, which indicates the installation path of ITK (here changed to the bin folder we built before). Then click configure again to run.

2715e2c35f782e64ca62d382e4cda9df.png

Run until there is no red, if there is still red, click and run configure several times.

Then generate, click to run generate.

2895e47a13e0800fe8c94f87b6340440.png

Finally, generating done will be displayed (proving that the generation was successful).

09dcb63de1a4f693241c784303977b76.png

Three: Installation

Open VS2019 as administrator, then open ITK.sln

1ad3194e9804a9ffccd5c26beb7cedd5.png

Find ALL_BUILD in the resource manager, right click to generate

6f70afcb309d8ced5fdadee0d7c0b868.png

8333fda08054995135a80ecb1c352545.png

If you follow the process, generally no errors will be reported.

978066c78011c670e56e1eb75963522e.png

Then find INSTALL and right-click to generate it to start the installation.

4d292970d95b3005003c2513196d9822.png

Four: Environment configuration

First, add the bin file under the previously created bin folder to the environment variable path of the system, and then restart the computer.

5f9b60afa3fd1f076604dafddd2d6b85.png

Then create a new project with vs2019, add bin\include\ITK-5.2 in the VC++ directory---include directory

7622a2d8b2e6789ab857346a0c9f250a.png

Add bin\lib to the VC++ directory---library directory

5299547872871a038bfad39b1768baa4.png

Add many .lib files in the connector --- input --- additional dependencies (that is, all the file names ending in .lib in the bin\lib folder).

Quickly get the name of the .lib file, create a new txt file under the bin\lib folder, and enter it

DIR *.lib* /B >LIST.TXT Then change the suffix to .bat to run the file. Double-click to run, and a LIST.TXT file will be generated, which contains all the .lib file names.

6d8143231a9d89e67a2ac6b2848b3d8d.png

5b06001afcc67c55c2450006e65fbd32.png

Add all .libs in the LIST.TXT file to Additional Dependencies.

f29281dfa6834c84dce9dee19269d7a7.png

The above environment is configured.

Five: Read the DICOM sequence and get the value quickly.

#include<iostream>
#include "itkGDCMImageIO.h"
#include "itkImageSeriesReader.h"//用于读取图像序列
#include "itkGDCMSeriesFileNames.h"//用于读取序列文件名


using namespace std;
int main()
{


  string file = "./GTI5BZZQ";//dicom文件夹


  //初始化待读取的dicom序列的各种参数
  using PixelType = signed short;//像素数据类型
  constexpr unsigned int dims = 3;//3维
  using ImageType = itk::Image<PixelType, dims>;
  using ReaderType = itk::ImageSeriesReader<ImageType>;
  using ImageIOType = itk::GDCMImageIO;
  using NamesGeneratorType = itk::GDCMSeriesFileNames;


  //设置IO,并获取文件名
  ImageIOType::Pointer gdcmIO = ImageIOType::New();
  NamesGeneratorType::Pointer namesGenerator = NamesGeneratorType::New();
  namesGenerator->SetInputDirectory(file);
  const ReaderType::FileNamesContainer& filenames = namesGenerator->GetInputFileNames();


  //输出文件名
  for (int i = 0; i < filenames.size(); i++)
  {
    cout << filenames[i] << endl;
  }


  //读取dcm序列
  ReaderType::Pointer reader = ReaderType::New();
  reader->SetImageIO(gdcmIO);
  reader->SetFileNames(filenames);
  reader->Update();


  //通过直接读取内存的方式获取像素值(高效率
  short* ptr = reader->GetOutput()->GetBufferPointer();//将获得首地址的指针
  //只需偏移就可以获得任何位置像素
  cout << ptr[0] << endl;


  gdcmIO->Delete();
  namesGenerator->Delete();
  reader->Delete();
  return 0;
}

Guess you like

Origin blog.csdn.net/weixin_41202834/article/details/121173765