| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
#ifndef itkNonLocalPatchBasedImageFilter_h |
| 19 |
#define itkNonLocalPatchBasedImageFilter_h |
| 20 |
|
| 21 |
#include <iostream> |
| 22 |
#include "itkImageToImageFilter.h" |
| 23 |
|
| 24 |
#include "itkConstNeighborhoodIterator.h" |
| 25 |
|
| 26 |
namespace itk |
| 27 |
{ |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
class NonLocalPatchBasedImageFilterEnums |
| 36 |
{ |
| 37 |
public: |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
enum class SimilarityMetric : uint8_t |
| 43 |
{ |
| 44 |
PEARSON_CORRELATION = 0, |
| 45 |
MEAN_SQUARES = 1 |
| 46 |
}; |
| 47 |
}; |
| 48 |
|
| •49 |
extern std::ostream & |
| 50 |
operator<<(std::ostream & out, const NonLocalPatchBasedImageFilterEnums::SimilarityMetric value); |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
template <typename TInputImage, typename TOutputImage = TInputImage> |
| 61 |
class ITK_TEMPLATE_EXPORT NonLocalPatchBasedImageFilter : public ImageToImageFilter<TInputImage, TOutputImage> |
| 62 |
{ |
| 63 |
public: |
| 64 |
ITK_DISALLOW_COPY_AND_MOVE(NonLocalPatchBasedImageFilter); |
| 65 |
|
| 66 |
|
| 67 |
using Self = NonLocalPatchBasedImageFilter<TInputImage, TOutputImage>; |
| 68 |
using Superclass = ImageToImageFilter<TInputImage, TOutputImage>; |
| 69 |
using Pointer = SmartPointer<Self>; |
| 70 |
using ConstPointer = SmartPointer<const Self>; |
| 71 |
|
| 72 |
|
| 73 |
itkTypeMacro(NonLocalPatchBasedImageFilter, ImageToImageFilter); |
| 74 |
|
| 75 |
|
| 76 |
itkNewMacro(Self); |
| 77 |
|
| 78 |
|
| 79 |
itkStaticConstMacro(ImageDimension, unsigned int, TInputImage::ImageDimension); |
| 80 |
|
| 81 |
|
| 82 |
using InputImageType = TInputImage; |
| 83 |
using InputPixelType = typename InputImageType::PixelType; |
| 84 |
using InputImagePointer = typename InputImageType::Pointer; |
| 85 |
using InputImageList = std::vector<InputImagePointer>; |
| 86 |
using InputImageSetList = std::vector<InputImageList>; |
| 87 |
using RegionType = typename InputImageType::RegionType; |
| 88 |
|
| 89 |
using OutputImageType = TOutputImage; |
| 90 |
using OutputPixelType = typename OutputImageType::PixelType; |
| 91 |
|
| 92 |
using InputImagePixelVectorType = std::vector<InputPixelType>; |
| 93 |
|
| 94 |
using RealType = float; |
| 95 |
using RealImageType = Image<RealType, ImageDimension>; |
| 96 |
using RealImagePointer = typename RealImageType::Pointer; |
| 97 |
using IndexType = typename RealImageType::IndexType; |
| 98 |
|
| 99 |
using NeighborhoodType = Neighborhood<InputPixelType, ImageDimension>; |
| 100 |
using NeighborhoodSizeType = SizeValueType; |
| 101 |
|
| 102 |
using ConstNeighborhoodIteratorType = ConstNeighborhoodIterator<InputImageType>; |
| 103 |
using NeighborhoodRadiusType = typename ConstNeighborhoodIteratorType::RadiusType; |
| 104 |
using NeighborhoodOffsetType = typename ConstNeighborhoodIteratorType::OffsetType; |
| 105 |
|
| 106 |
using NeighborhoodOffsetListType = std::vector<NeighborhoodOffsetType>; |
| 107 |
|
| 108 |
using SimilarityMetricEnum = NonLocalPatchBasedImageFilterEnums::SimilarityMetric; |
| 109 |
#if !defined(ITK_LEGACY_REMOVE) |
| 110 |
using SimilarityMetricType = SimilarityMetricEnum; |
| 111 |
static constexpr SimilarityMetricType PEARSON_CORRELATION = SimilarityMetricEnum::PEARSON_CORRELATION; |
| 112 |
static constexpr SimilarityMetricType MEAN_SQUARES = SimilarityMetricEnum::MEAN_SQUARES; |
| 113 |
#endif |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
itkSetMacro(NeighborhoodSearchRadius, NeighborhoodRadiusType); |
| 120 |
itkGetConstMacro(NeighborhoodSearchRadius, NeighborhoodRadiusType); |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
itkSetMacro(NeighborhoodSearchSize, NeighborhoodSizeType); |
| 126 |
itkGetConstMacro(NeighborhoodSearchSize, NeighborhoodSizeType); |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
virtual void |
| 132 |
SetNeighborhoodSearchOffsetList(const NeighborhoodOffsetListType list) |
| 133 |
{ |
| 134 |
this->m_NeighborhoodSearchOffsetList = list; |
| 135 |
this->Modified(); |
| 136 |
} |
| 137 |
itkGetConstMacro(NeighborhoodSearchOffsetList, NeighborhoodOffsetListType); |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
itkSetMacro(NeighborhoodPatchRadius, NeighborhoodRadiusType); |
| 144 |
itkGetConstMacro(NeighborhoodPatchRadius, NeighborhoodRadiusType); |
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
itkSetMacro(NeighborhoodPatchSize, NeighborhoodSizeType); |
| 150 |
itkGetConstMacro(NeighborhoodPatchSize, NeighborhoodSizeType); |
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
virtual void |
| 156 |
SetNeighborhoodPatchOffsetList(const NeighborhoodOffsetListType list) |
| 157 |
{ |
| 158 |
this->m_NeighborhoodPatchOffsetList = list; |
| 159 |
this->Modified(); |
| 160 |
} |
| 161 |
itkGetConstMacro(NeighborhoodPatchOffsetList, NeighborhoodOffsetListType); |
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
itkSetMacro(SimilarityMetric, SimilarityMetricEnum); |
| 167 |
itkGetConstMacro(SimilarityMetric, SimilarityMetricEnum); |
| 168 |
|
| 169 |
protected: |
| 170 |
NonLocalPatchBasedImageFilter(); |
| 171 |
~NonLocalPatchBasedImageFilter() override = default; |
| 172 |
|
| 173 |
void |
| 174 |
BeforeThreadedGenerateData() override; |
| 175 |
|
| 176 |
void |
| 177 |
PrintSelf(std::ostream & os, Indent indent) const override; |
| 178 |
|
| 179 |
RealType |
| 180 |
ComputeNeighborhoodPatchSimilarity(const InputImageList &, |
| 181 |
const IndexType, |
| 182 |
const InputImagePixelVectorType &, |
| 183 |
const bool); |
| 184 |
|
| 185 |
InputImagePixelVectorType |
| 186 |
VectorizeImageListPatch(const InputImageList &, const IndexType, const bool); |
| 187 |
|
| 188 |
InputImagePixelVectorType |
| 189 |
VectorizeImagePatch(const InputImagePointer, const IndexType, const bool); |
| 190 |
|
| 191 |
void |
| 192 |
GetMeanAndStandardDeviationOfVectorizedImagePatch(const InputImagePixelVectorType &, RealType &, RealType &); |
| 193 |
|
| 194 |
itkSetMacro(TargetImageRegion, RegionType); |
| 195 |
itkGetConstMacro(TargetImageRegion, RegionType); |
| 196 |
|
| 197 |
SimilarityMetricEnum m_SimilarityMetric; |
| 198 |
|
| 199 |
SizeValueType m_NeighborhoodSearchSize; |
| 200 |
NeighborhoodRadiusType m_NeighborhoodSearchRadius; |
| 201 |
NeighborhoodOffsetListType m_NeighborhoodSearchOffsetList; |
| 202 |
|
| 203 |
SizeValueType m_NeighborhoodPatchSize; |
| 204 |
NeighborhoodRadiusType m_NeighborhoodPatchRadius; |
| 205 |
NeighborhoodOffsetListType m_NeighborhoodPatchOffsetList; |
| 206 |
|
| 207 |
RegionType m_TargetImageRegion; |
| 208 |
}; |
| 209 |
|
| 210 |
} |
| 211 |
|
| 212 |
#ifndef ITK_MANUAL_INSTANTIATION |
| 213 |
# include "itkNonLocalPatchBasedImageFilter.hxx" |
| 214 |
#endif |
| 215 |
|
| 216 |
#endif |