17#ifndef __filter_mask_clean_h__
18#define __filter_mask_clean_h__
26#include "filter/base.h"
59 template <
class HeaderType>
64 check_3D_nonunity (in);
68 template <
class HeaderType>
73 check_3D_nonunity (in);
77 template <
class InputImageType,
class OutputImageType>
78 void operator() (InputImageType& input, OutputImageType& output)
87 for (
auto l =
Loop (0,3) (input, temp_in); l; ++l)
88 temp_in.value() = input.value();
98 while (
differ(temp_in, temp_out)) {
100 for (
auto l =
Loop (0,3) (temp_out, temp_in); l; ++l)
101 temp_in.value() = temp_out.value();
110 for (
auto l =
Loop (0,3) (temp_out, output); l; ++l)
111 output.value() = temp_out.value();
116 void set_scale (
unsigned int scales)
125 template <
class InputImageType,
class OutputImageType>
129 for (
auto l =
Loop (0,3) (input, temp_image); l; ++l)
130 temp_image.value() = input.value();
132 for (
unsigned int s =
scale; s > 0; --s)
136 connected_filter.set_largest_only (
true);
137 connected_filter (temp_image, temp_image);
139 for (
auto l =
Loop (0,3) (temp_image, output); l; ++l)
140 output.value() = temp_image.value();
144 template <
class InputImageType,
class OutputImageType>
145 void single_scale (InputImageType& input, OutputImageType& output,
const int ss)
148 Erode erosion_filter (input);
149 erosion_filter.set_npass(ss);
150 erosion_filter (input, del_image);
154 connected_filter.set_largest_only (
true);
155 connected_filter (del_image, largest_image);
157 for (
auto l =
Loop (0,3) (del_image, largest_image); l; ++l)
158 if (largest_image.value())
159 del_image.value() = 0;
161 Dilate dilation_filter (del_image);
162 dilation_filter.set_npass(ss+1);
163 dilation_filter (del_image, del_image);
165 for (
auto l =
Loop (0,3) (input, largest_image, del_image); l; ++l)
166 largest_image.value() = del_image.value() ? 0 : input.value();
168 for (
auto l =
Loop (0,3) (largest_image, output); l; ++l)
169 output.value() = largest_image.value();
172 template <
class InputImageType,
class OutputImageType>
173 bool differ (InputImageType& ima, OutputImageType& imb)
175 for (
auto l =
Loop (0,3) (ima, imb); l; ++l)
176 if (ima.value() != imb.value())
static constexpr uint8_t Bit
a filter to dilate a mask
a filter to clean up masks typically output by DWIBrainMask filter
void single_pass(InputImageType &input, OutputImageType &output)
bool differ(InputImageType &ima, OutputImageType &imb)
void single_scale(InputImageType &input, OutputImageType &output, const int ss)
static Image scratch(const Header &template_header, const std::string &label="scratch image")
implements a progress meter to provide feedback to the user
FORCE_INLINE LoopAlongAxes Loop()