#include <cstdlib>
#include <iostream>
using itk::simple::operator<<;
template <class T>
struct SliceBySliceDecorator;
template <class R, class ImageArg, class... Args>
struct SliceBySliceDecorator<R(ImageArg, Args...)>
{
using FunctionType = std::function<R(ImageArg, Args...)>;
explicit SliceBySliceDecorator(FunctionType f)
: f_(std::move(f))
{}
R
{
const auto image_size = image.
GetSize();
if (dim <= iter_dim)
{
image = f_(image, args...);
return image;
}
std::vector<unsigned int> extract_size = image.
GetSize();
std::fill(extract_size.begin() + iter_dim, extract_size.end(), 0);
std::vector<int> extract_index(dim, 0);
paster.
SetSourceSize(std::vector<unsigned int>(extract_size.begin(), extract_size.begin() + iter_dim));
while (
static_cast<unsigned int>(extract_index.back()) < image.
GetSize().back())
{
image = paster.
Execute(image, temp_image);
++extract_index[iter_dim];
for (
unsigned int e = iter_dim; e + 1 < dim; ++e)
{
if (
static_cast<unsigned int>(extract_index[e]) > image.
GetSize()[e])
{
extract_index[e] = 0;
++extract_index[e + 1];
}
}
}
return image;
}
FunctionType f_;
constexpr static unsigned int iter_dim = 2;
};
template <class R, class... Args>
SliceBySliceDecorator<R(Args...)> makeSliceBySlice(R (*f)(Args...))
{
using DecoratorType = SliceBySliceDecorator<R(Args...)>;
return DecoratorType(typename DecoratorType::FunctionType(f));
}
int
main(int argc, char * argv[])
{
if (argc < 3)
{
std::cerr << "Usage: " << argv[0] << " <inputImage> <outputImage>" << std::endl;
return 1;
}
float alpha = 0.3f;
float beta = 0.3f;
std::vector<unsigned int> radius(2, 20);
tempImage = AdaptiveHistogramEqualization2D(tempImage, radius, alpha, beta);
return 0;
}