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 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
|
/*=========================================================================
*
* Copyright UMC Utrecht and contributors
*
* 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 elxRegistrationBase_h
#define elxRegistrationBase_h
/** Needed for the macros */
#include "elxMacro.h"
#include "elxBaseComponentSE.h"
#include "itkMultiResolutionImageRegistrationMethod2.h"
/** Mask support. */
#include "itkImageMaskSpatialObject.h"
#include "itkErodeMaskImageFilter.h"
namespace elastix
{
/**
* \class RegistrationBase
* \brief This class is the elastix base class for all Registration schemes.
*
* This class contains all the common functionality for Registrations.
*
* \parameter ErodeMask: a flag to determine if the masks should be eroded
* from one resolution level to another. Choose from {"true", "false"} \n
* example: <tt>(ErodeMask "false")</tt> \n
* The default is "true". The parameter may be specified for each
* resolution differently, but that's not obliged. The actual amount of
* erosion depends on the image pyramid. \n
* Erosion of the mask prevents the border / edge of the mask taken into account.
* This can be useful for example for ultrasound images,
* where you don't want to take into account values outside
* the US-beam, but where you also don't want to match the
* edge / border of this beam.
* For example for MRI's of the head, the borders of the head
* may be wanted to match, and there erosion should be avoided.
* \parameter ErodeFixedMask: a flag to determine if the fixed mask(s) should be eroded
* from one resolution level to another. Choose from {"true", "false"} \n
* example: <tt>(ErodeFixedMask "true" "false")</tt>
* This setting overrules ErodeMask.\n
* \parameter ErodeMovingMask: a flag to determine if the moving mask(s) should be eroded
* from one resolution level to another. Choose from {"true", "false"} \n
* example: <tt>(ErodeMovingMask "true" "false")</tt>
* This setting overrules ErodeMask.\n
* \parameter ErodeFixedMask\<i\>: a flag to determine if the i-th fixed mask should be eroded
* from one resolution level to another. Choose from {"true", "false"} \n
* example: <tt>(ErodeFixedMask2 "true" "false")</tt>
* This setting overrules ErodeMask and ErodeFixedMask.\n
* \parameter ErodeMovingMask\<i\>: a flag to determine if the i-th moving mask should be eroded
* from one resolution level to another. Choose from {"true", "false"} \n
* example: <tt>(ErodeMovingMask2 "true" "false")</tt>
* This setting overrules ErodeMask and ErodeMovingMask.\n
*
* \ingroup Registrations
* \ingroup ComponentBaseClasses
*/
template <class TElastix>
class ITK_TEMPLATE_EXPORT RegistrationBase : public BaseComponentSE<TElastix>
{
public:
ITK_DISALLOW_COPY_AND_MOVE(RegistrationBase);
/** Standard ITK stuff. */
using Self = RegistrationBase;
using Superclass = BaseComponentSE<TElastix>;
/** Run-time type information (and related methods). */
itkTypeMacro(RegistrationBase, BaseComponentSE);
/** Typedef's from Elastix. */
using typename Superclass::ElastixType;
using typename Superclass::RegistrationType;
/** Other typedef's. */
using FixedImageType = typename ElastixType::FixedImageType;
using MovingImageType = typename ElastixType::MovingImageType;
/** Get the dimension of the fixed image. */
itkStaticConstMacro(FixedImageDimension, unsigned int, FixedImageType::ImageDimension);
/** Get the dimension of the moving image. */
itkStaticConstMacro(MovingImageDimension, unsigned int, MovingImageType::ImageDimension);
/** Typedef for ITKBaseType. */
using ITKBaseType = itk::MultiResolutionImageRegistrationMethod2<FixedImageType, MovingImageType>;
/** Typedef for mask erosion options */
using UseMaskErosionArrayType = std::vector<bool>;
/** Retrieves this object as ITKBaseType. */
ITKBaseType *
GetAsITKBaseType()
{
return &(this->GetSelf());
}
/** Retrieves this object as ITKBaseType, to use in const functions. */
const ITKBaseType *
GetAsITKBaseType() const
{
return &(this->GetSelf());
}
/** Function to read the mask parameters from the configuration object.
* \todo: move to RegistrationBase
* Input:
* \li an array that will contain a bool for each mask, saying if it needs erosion or not
* \li the number of masks
* \li whichMask: "Fixed" or "Moving"
* \li the current resolution level
* Output:
* \li The function returns a bool that says if any mask needs erosion. If the number of masks
* is zero, this bool will be false.
* \li The useMaskErosionArray, which indicates for each mask whether it should be eroded.
* If the number of masks is zero, this array will be empty.
*
* The function first checks Erode<Fixed,Moving>Mask\<i\>, with i the mask number,
* then Erode<Fixed,Moving>Mask, and finally ErodeMask. So, if you do not specify
* Erode<Fixed,Moving>Mask\<i\>, Erode<Fixed,Moving>Mask is tried, and then ErodeMask.
* If you specify ErodeMask, that option will be used for all masks, fixed and moving!
* All options can be specified for each resolution specifically, or at once for all
* resolutions.
*/
virtual bool
ReadMaskParameters(UseMaskErosionArrayType & useMaskErosionArray,
const unsigned int nrOfMasks,
const std::string & whichMask,
const unsigned int level) const;
protected:
/** The constructor. */
RegistrationBase() = default;
/** The destructor. */
~RegistrationBase() override = default;
/** Typedef's for mask support. */
using MaskPixelType = typename ElastixType::MaskPixelType;
using FixedMaskImageType = typename ElastixType::FixedMaskType;
using MovingMaskImageType = typename ElastixType::MovingMaskType;
using FixedMaskImagePointer = typename FixedMaskImageType::Pointer;
using MovingMaskImagePointer = typename MovingMaskImageType::Pointer;
using FixedMaskSpatialObjectType = itk::ImageMaskSpatialObject<Self::FixedImageDimension>;
using MovingMaskSpatialObjectType = itk::ImageMaskSpatialObject<Self::MovingImageDimension>;
using FixedMaskSpatialObjectPointer = typename FixedMaskSpatialObjectType::Pointer;
using MovingMaskSpatialObjectPointer = typename MovingMaskSpatialObjectType::Pointer;
using FixedImagePyramidType = typename ITKBaseType::FixedImagePyramidType;
using MovingImagePyramidType = typename ITKBaseType::MovingImagePyramidType;
/** Some typedef's used for eroding the masks */
using FixedMaskErodeFilterType = itk::ErodeMaskImageFilter<FixedMaskImageType>;
using FixedMaskErodeFilterPointer = typename FixedMaskErodeFilterType::Pointer;
using MovingMaskErodeFilterType = itk::ErodeMaskImageFilter<MovingMaskImageType>;
using MovingMaskErodeFilterPointer = typename MovingMaskErodeFilterType::Pointer;
/** Generate a spatial object from a mask image, possibly after eroding the image
* Input:
* \li the mask as an image, consisting of 1's and 0's;
* \li a boolean that determines whether mask erosion is needed
* \li the image pyramid, which is needed to determines the amount of erosion
* (can be set to 0 if useMaskErosion == false
* \li the resolution level
* Output:
* \li the mask as a spatial object, which can be set in a metric for example
*
* This function is used by the registration components
*/
FixedMaskSpatialObjectPointer
GenerateFixedMaskSpatialObject(const FixedMaskImageType * maskImage,
bool useMaskErosion,
const FixedImagePyramidType * pyramid,
unsigned int level) const;
/** Generate a spatial object from a mask image, possibly after eroding the image
* Input:
* \li the mask as an image, consisting of 1's and 0's;
* \li a boolean that determines whether mask erosion is needed
* \li the image pyramid, which is needed to determines the amount of erosion
* (can be set to 0 if useMaskErosion == false
* \li the resolution level
* Output:
* \li the mask as a spatial object, which can be set in a metric for example
*
* This function is used by the registration components
*/
MovingMaskSpatialObjectPointer
GenerateMovingMaskSpatialObject(const MovingMaskImageType * maskImage,
bool useMaskErosion,
const MovingImagePyramidType * pyramid,
unsigned int level) const;
private:
elxDeclarePureVirtualGetSelfMacro(ITKBaseType);
};
} // end namespace elastix
#ifndef ITK_MANUAL_INSTANTIATION
# include "elxRegistrationBase.hxx"
#endif
#endif // end #ifndef elxRegistrationBase_h
|