/usr/include/ITK-4.5/itkMRASlabIdentifier.hxx is in libinsighttoolkit4-dev 4.5.0-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | /*=========================================================================
*
* Copyright Insight Software Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#ifndef __itkMRASlabIdentifier_hxx
#define __itkMRASlabIdentifier_hxx
#include <algorithm>
#include <vector>
#include <queue>
#include "itkMRASlabIdentifier.h"
#include "itkImageRegionIterator.h"
#include "vnl/vnl_math.h"
namespace itk
{
template< typename TInputImage >
MRASlabIdentifier< TInputImage >
::MRASlabIdentifier()
{
m_Image = 0;
m_NumberOfSamples = 10;
m_BackgroundMinimumThreshold = NumericTraits< ImagePixelType >::min();
m_Tolerance = 0.0;
// default slicing axis is z
m_SlicingDirection = 2;
}
template< typename TInputImage >
void
MRASlabIdentifier< TInputImage >
::GenerateSlabRegions(void)
{
// this method only works with 3D MRI image
if ( ImageType::ImageDimension != 3 )
{
itkExceptionMacro("ERROR: This algorithm only works with 3D images.");
}
ImageSizeType size;
ImageRegionType region;
ImageIndexType index;
region = m_Image->GetLargestPossibleRegion();
size = region.GetSize();
index = region.GetIndex();
IndexValueType firstSlice = index[m_SlicingDirection];
IndexValueType lastSlice = firstSlice + size[m_SlicingDirection];
SizeValueType totalSlices = size[m_SlicingDirection];
double sum;
std::vector< double > avgMin(totalSlices);
// calculate minimum intensities for each slice
ImagePixelType pixel;
for ( int i = 0; i < 3; i++ )
{
if ( i != m_SlicingDirection )
{
index[i] = 0;
}
}
size[m_SlicingDirection] = 1;
region.SetSize(size);
SizeValueType count = 0;
IndexValueType currentSlice = firstSlice;
while ( currentSlice < lastSlice )
{
index[m_SlicingDirection] = currentSlice;
region.SetIndex(index);
ImageRegionConstIterator< TInputImage > iter(m_Image, region);
iter.GoToBegin();
std::priority_queue< ImagePixelType > mins;
for ( unsigned int i = 0; i < m_NumberOfSamples; ++i )
{
mins.push( NumericTraits< ImagePixelType >::max() );
}
while ( !iter.IsAtEnd() )
{
pixel = iter.Get();
if ( pixel > m_BackgroundMinimumThreshold )
{
if ( mins.top() > pixel )
{
mins.pop();
mins.push(pixel);
}
}
++iter;
}
sum = 0.0;
while ( !mins.empty() )
{
sum += mins.top();
mins.pop();
}
avgMin[count] = sum / (double)m_NumberOfSamples;
++count;
++currentSlice;
}
// calculate overall average
sum = 0.0;
std::vector< double >::iterator am_iter = avgMin.begin();
while ( am_iter != avgMin.end() )
{
sum += *am_iter;
++am_iter;
}
double average = sum / (double)totalSlices;
// determine slabs
am_iter = avgMin.begin();
double prevSign = *am_iter - average;
double avgMinValue;
ImageIndexType slabIndex;
ImageRegionType slabRegion;
ImageSizeType slabSize;
SizeValueType slabLength = 0;
IndexValueType slabBegin = firstSlice;
slabSize = size;
slabIndex = index;
while ( am_iter != avgMin.end() )
{
avgMinValue = *am_iter;
double sign = avgMinValue - average;
if ( ( sign * prevSign < 0 ) && ( vnl_math_abs(sign) > m_Tolerance ) )
{
slabIndex[m_SlicingDirection] = slabBegin;
slabSize[m_SlicingDirection] = slabLength;
slabRegion.SetSize(slabSize);
slabRegion.SetIndex(slabIndex);
m_Slabs.push_back(slabRegion);
prevSign = sign;
slabBegin += slabLength;
slabLength = 0;
}
am_iter++;
slabLength++;
}
slabIndex[m_SlicingDirection] = slabBegin;
slabSize[m_SlicingDirection] = slabLength;
slabRegion.SetIndex(slabIndex);
slabRegion.SetSize(slabSize);
m_Slabs.push_back(slabRegion);
}
template< typename TInputImage >
typename MRASlabIdentifier< TInputImage >::SlabRegionVectorType
MRASlabIdentifier< TInputImage >
::GetSlabRegionVector(void)
{
return m_Slabs;
}
template< typename TInputImage >
void
MRASlabIdentifier< TInputImage >
::PrintSelf(std::ostream & os, Indent indent) const
{
Superclass::PrintSelf(os, indent);
if ( m_Image )
{
os << indent << "Image: " << m_Image << std::endl;
}
else
{
os << indent << "Image: " << "(None)" << std::endl;
}
os << indent << "NumberOfSamples: " << m_NumberOfSamples << std::endl;
os << indent << "SlicingDirection: " << m_SlicingDirection << std::endl;
os << indent << "Background Pixel Minimum Intensity Threshold: "
<< m_BackgroundMinimumThreshold << std::endl;
os << indent << "Tolerance: " << m_Tolerance << std::endl;
}
} // end namespace itk
#endif /* __itkMRASlabIdentifier_hxx */
|