File: MultiComponentImageToScalarLookupTableImageFilter.cxx

package info (click to toggle)
itksnap 3.6.0-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 22,132 kB
  • sloc: cpp: 91,089; ansic: 1,994; sh: 327; makefile: 16
file content (136 lines) | stat: -rw-r--r-- 4,069 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include "MultiComponentImageToScalarLookupTableImageFilter.h"
#include "itkVectorImage.h"
#include "itkImageRegionIteratorWithIndex.h"
#include "IntensityCurveInterface.h"

template<class TInputImage, class TOutputLUT>
MultiComponentImageToScalarLookupTableImageFilter<TInputImage, TOutputLUT>
::MultiComponentImageToScalarLookupTableImageFilter()
{

}

template<class TInputImage, class TOutputLUT>
MultiComponentImageToScalarLookupTableImageFilter<TInputImage, TOutputLUT>
::~MultiComponentImageToScalarLookupTableImageFilter()
{

}

template<class TInputImage, class TOutputLUT>
void
MultiComponentImageToScalarLookupTableImageFilter<TInputImage, TOutputLUT>
::SetMultiComponentImage(InputImageType *image)
{
  // Figure out how many components we have
  this->SetNumberOfIndexedInputs(4);

  // Set the first input
  this->SetNthInput(0, image);
}

template<class TInputImage, class TOutputLUT>
void
MultiComponentImageToScalarLookupTableImageFilter<TInputImage, TOutputLUT>
::SetIntensityCurve(IntensityCurveInterface *curve)
{
  m_IntensityCurve = curve;
  this->SetNthInput(1, curve);
}

template<class TInputImage, class TOutputLUT>
void
MultiComponentImageToScalarLookupTableImageFilter<TInputImage, TOutputLUT>
::SetImageMinInput(InputPixelObject *input)
{
  m_InputMin = input;
  this->SetNthInput(2, input);
}

template<class TInputImage, class TOutputLUT>
void
MultiComponentImageToScalarLookupTableImageFilter<TInputImage, TOutputLUT>
::SetImageMaxInput(InputPixelObject *input)
{
  m_InputMax = input;
  this->SetNthInput(3, input);
}

template<class TInputImage, class TOutputLUT>
void
MultiComponentImageToScalarLookupTableImageFilter<TInputImage, TOutputLUT>
::GenerateOutputInformation()
{
  // We need to compute a global max/min
  InputComponentType gmin = m_InputMin.Get();
  InputComponentType gmax = m_InputMax.Get();

  LookupTableType *output = this->GetOutput();
  typename LookupTableType::IndexType idx = {{gmin}};
  typename LookupTableType::SizeType sz = {{1 + gmax - gmin}};
  typename LookupTableType::RegionType region(idx, sz);
  output->SetLargestPossibleRegion(region);
}

template<class TInputImage, class TOutputLUT>
void
MultiComponentImageToScalarLookupTableImageFilter<TInputImage, TOutputLUT>
::EnlargeOutputRequestedRegion(itk::DataObject *)
{
  LookupTableType *output = this->GetOutput();
  output->SetRequestedRegion(output->GetLargestPossibleRegion());
}

template<class TInputImage, class TOutputLUT>
void
MultiComponentImageToScalarLookupTableImageFilter<TInputImage, TOutputLUT>
::GenerateInputRequestedRegion()
{
  // The input region is the whole image
  InputImageType *input = const_cast<InputImageType *>(this->GetInput());
  input->SetRequestedRegionToLargestPossibleRegion();
}


template<class TInputImage, class TOutputLUT>
void
MultiComponentImageToScalarLookupTableImageFilter<TInputImage, TOutputLUT>
::ThreadedGenerateData(const OutputImageRegionType &region,
                       itk::ThreadIdType threadId)
{
  if(threadId == 0)
    std::cout << "Computing LUT " << region << std::endl;

  InputComponentType gmin = m_InputMin.Get();
  InputComponentType gmax = m_InputMax.Get();

  // Set the intensity mapping for the functor
  float scale, shift;
  shift = gmin;
  scale = 1.0f / (gmax - gmin);

  // Do the actual computation of the cache
  LookupTableType *output = this->GetOutput();
  for(itk::ImageRegionIteratorWithIndex<LookupTableType> it(output, region);
      !it.IsAtEnd(); ++it)
    {
    // Get the lookup value we are seeking
    long pos = it.GetIndex()[0];

    // Map the input value to range of 0 to 1
    float inZeroOne = (pos - shift) * scale;

    // Compute the intensity mapping
    float outZeroOne = m_IntensityCurve->Evaluate(inZeroOne);

    // Map the output to a RGBA pixel
    it.Set(static_cast<OutputPixelType>(255.0 * outZeroOne));
    }
}

// Template instantiation
typedef itk::VectorImage<short, 3> AnatomicImageType;
typedef itk::Image<unsigned char, 1> LUTType;
template class MultiComponentImageToScalarLookupTableImageFilter<AnatomicImageType, LUTType>;