Slicer 5.9
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
Loading...
Searching...
No Matches
itkPluginUtilities.h
Go to the documentation of this file.
1#ifndef itkPluginUtilities_h
2#define itkPluginUtilities_h
3
4// ITK includes
5#include <itkContinuousIndex.h>
6#include <itkCommonEnums.h>
7#include <itkImageFileReader.h>
9
10// STD includes
11#include <vector>
12#include <string>
13
14namespace itk
15{
16//-----------------------------------------------------------------------------
18void GetImageType(std::string fileName, IOPixelEnum& pixelType, IOComponentEnum& componentType)
19{
20 using ImageType = itk::Image<unsigned char, 3>;
21 using ReaderType = itk::ImageFileReader<ImageType>;
22 ReaderType::Pointer imageReader = ReaderType::New();
23 imageReader->SetFileName(fileName);
24 imageReader->UpdateOutputInformation();
25
26 pixelType = imageReader->GetImageIO()->GetPixelType();
27 componentType = imageReader->GetImageIO()->GetComponentType();
28}
29
30//-----------------------------------------------------------------------------
32void GetImageTypes(std::vector<std::string> fileNames, std::vector<IOPixelEnum>& pixelTypes, std::vector<IOComponentEnum>& componentTypes)
33{
34 pixelTypes.clear();
35 componentTypes.clear();
36
37 // For each file, find the pixel and component type
38 for (std::vector<std::string>::size_type i = 0; i < fileNames.size(); i++)
39 {
40 IOPixelEnum pixelType;
41 IOComponentEnum componentType;
42
43 GetImageType(fileNames[i], pixelType, componentType);
44 pixelTypes.push_back(pixelType);
45 componentTypes.push_back(componentType);
46 }
47}
48
49//-----------------------------------------------------------------------------
50template <class T>
51void AlignVolumeCenters(T* fixed, T* moving, typename T::PointType& origin)
52{
53 // compute the center of fixed
54 typename T::PointType fixedCenter;
55 {
56 itk::ContinuousIndex<double, T::ImageDimension> centerIndex;
57 typename T::SizeType size = fixed->GetLargestPossibleRegion().GetSize();
58 for (unsigned int i = 0; i < T::ImageDimension; i++)
59 {
60 centerIndex[i] = static_cast<double>((size[i] - 1) / 2.0);
61 }
62 fixed->TransformContinuousIndexToPhysicalPoint(centerIndex, fixedCenter);
63 }
64
65 // compute the center of moving
66 typename T::PointType movingCenter;
67 {
68 itk::ContinuousIndex<double, T::ImageDimension> centerIndex;
69 typename T::SizeType size = moving->GetLargestPossibleRegion().GetSize();
70 for (unsigned i = 0; i < T::ImageDimension; i++)
71 {
72 centerIndex[i] = static_cast<double>((size[i] - 1) / 2.0);
73 }
74 moving->TransformContinuousIndexToPhysicalPoint(centerIndex, movingCenter);
75 }
76
77 for (unsigned int j = 0; j < fixedCenter.Size(); j++)
78 {
79 origin[j] = moving->GetOrigin()[j] - (movingCenter[j] - fixedCenter[j]);
80 }
81}
82
83} // end namespace itk
84
85#endif
Simplified inverse ITK transforms.
void GetImageType(std::string fileName, IOPixelEnum &pixelType, IOComponentEnum &componentType)
Get the PixelType and ComponentType from fileName.
void AlignVolumeCenters(T *fixed, T *moving, typename T::PointType &origin)
void GetImageTypes(std::vector< std::string > fileNames, std::vector< IOPixelEnum > &pixelTypes, std::vector< IOComponentEnum > &componentTypes)
Get the PixelTypes and ComponentTypes from fileNames.