- put PixelType trait in lib

- use AsArray to make functions more flexible
- less image copying when doing re
This commit is contained in:
Wim Pomp
2025-03-06 22:49:49 +01:00
parent 934f038ea1
commit 0c6a38e4fa
4 changed files with 205 additions and 148 deletions

View File

@@ -286,8 +286,8 @@ reg(
try {
string kind = (t_or_a == false) ? "translation" : "affine";
// std::filesystem::path output_path = std::filesystem::temp_directory_path() / gen_random(12);
std::filesystem::path output_path = std::filesystem::temp_directory_path();
// std::filesystem::create_directory(output_path);
std::filesystem::path output_path = std::filesystem::temp_directory_path();
sitk::ElastixImageFilter tfilter = sitk::ElastixImageFilter();
tfilter.LogToConsoleOff();
@@ -298,11 +298,7 @@ reg(
tfilter.SetParameterMap(sitk::GetDefaultParameterMap(kind));
tfilter.SetParameter("WriteResultImage", "false");
tfilter.SetOutputDirectory(output_path);
// cout << "output_path: " << output_path << endl;
// tfilter.PrintParameterMap();
// cout << "r6 " << std::flush;
tfilter.Execute();
// cout << "r7 " << std::flush;
sitk::ElastixImageFilter::ParameterMapType parameter_map = tfilter.GetTransformParameterMap(0);
for (sitk::ElastixImageFilter::ParameterMapType::iterator parameter = parameter_map.begin(); parameter != parameter_map.end(); ++parameter) {
if (parameter->first == "TransformParameters") {
@@ -323,7 +319,6 @@ reg(
break;
}
}
// cout << "r8 " << std::flush;
} catch (const std::exception &exc) {
cerr << exc.what();
}
@@ -334,14 +329,14 @@ extern "C" void
register_u8(
unsigned int width,
unsigned int height,
uint8_t* fixed_arr,
uint8_t* moving_arr,
uint8_t** fixed_arr,
uint8_t** moving_arr,
bool t_or_a,
double** transform
) {
sitk::PixelIDValueEnum id = sitk::PixelIDValueEnum::sitkUInt8;
sitk::Image fixed = make_image(width, height, fixed_arr, id);
sitk::Image moving = make_image(width, height, moving_arr, id);
sitk::Image fixed = make_image(width, height, *fixed_arr, id);
sitk::Image moving = make_image(width, height, *moving_arr, id);
reg(fixed, moving, t_or_a, transform);
}
@@ -349,14 +344,14 @@ extern "C" void
register_i8(
unsigned int width,
unsigned int height,
int8_t* fixed_arr,
int8_t* moving_arr,
int8_t** fixed_arr,
int8_t** moving_arr,
bool t_or_a,
double** transform
) {
sitk::PixelIDValueEnum id = sitk::PixelIDValueEnum::sitkInt8;
sitk::Image fixed = make_image(width, height, fixed_arr, id);
sitk::Image moving = make_image(width, height, moving_arr, id);
sitk::Image fixed = make_image(width, height, *fixed_arr, id);
sitk::Image moving = make_image(width, height, *moving_arr, id);
reg(fixed, moving, t_or_a, transform);
}
@@ -364,14 +359,14 @@ extern "C" void
register_u16(
unsigned int width,
unsigned int height,
uint16_t* fixed_arr,
uint16_t* moving_arr,
uint16_t** fixed_arr,
uint16_t** moving_arr,
bool t_or_a,
double** transform
) {
sitk::PixelIDValueEnum id = sitk::PixelIDValueEnum::sitkUInt16;
sitk::Image fixed = make_image(width, height, fixed_arr, id);
sitk::Image moving = make_image(width, height, moving_arr, id);
sitk::Image fixed = make_image(width, height, *fixed_arr, id);
sitk::Image moving = make_image(width, height, *moving_arr, id);
reg(fixed, moving, t_or_a, transform);
}
@@ -379,14 +374,14 @@ extern "C" void
register_i16(
unsigned int width,
unsigned int height,
int16_t* fixed_arr,
int16_t* moving_arr,
int16_t** fixed_arr,
int16_t** moving_arr,
bool t_or_a,
double** transform
) {
sitk::PixelIDValueEnum id = sitk::PixelIDValueEnum::sitkInt16;
sitk::Image fixed = make_image(width, height, fixed_arr, id);
sitk::Image moving = make_image(width, height, moving_arr, id);
sitk::Image fixed = make_image(width, height, *fixed_arr, id);
sitk::Image moving = make_image(width, height, *moving_arr, id);
reg(fixed, moving, t_or_a, transform);
}
@@ -394,14 +389,14 @@ extern "C" void
register_u32(
unsigned int width,
unsigned int height,
uint32_t* fixed_arr,
uint32_t* moving_arr,
uint32_t** fixed_arr,
uint32_t** moving_arr,
bool t_or_a,
double** transform
) {
sitk::PixelIDValueEnum id = sitk::PixelIDValueEnum::sitkUInt32;
sitk::Image fixed = make_image(width, height, fixed_arr, id);
sitk::Image moving = make_image(width, height, moving_arr, id);
sitk::Image fixed = make_image(width, height, *fixed_arr, id);
sitk::Image moving = make_image(width, height, *moving_arr, id);
reg(fixed, moving, t_or_a, transform);
}
@@ -409,14 +404,14 @@ extern "C" void
register_i32(
unsigned int width,
unsigned int height,
int32_t* fixed_arr,
int32_t* moving_arr,
int32_t** fixed_arr,
int32_t** moving_arr,
bool t_or_a,
double** transform
) {
sitk::PixelIDValueEnum id = sitk::PixelIDValueEnum::sitkInt32;
sitk::Image fixed = make_image(width, height, fixed_arr, id);
sitk::Image moving = make_image(width, height, moving_arr, id);
sitk::Image fixed = make_image(width, height, *fixed_arr, id);
sitk::Image moving = make_image(width, height, *moving_arr, id);
reg(fixed, moving, t_or_a, transform);
}
@@ -424,14 +419,14 @@ extern "C" void
register_u64(
unsigned int width,
unsigned int height,
uint64_t* fixed_arr,
uint64_t* moving_arr,
uint64_t** fixed_arr,
uint64_t** moving_arr,
bool t_or_a,
double** transform
) {
sitk::PixelIDValueEnum id = sitk::PixelIDValueEnum::sitkUInt64;
sitk::Image fixed = make_image(width, height, fixed_arr, id);
sitk::Image moving = make_image(width, height, moving_arr, id);
sitk::Image fixed = make_image(width, height, *fixed_arr, id);
sitk::Image moving = make_image(width, height, *moving_arr, id);
reg(fixed, moving, t_or_a, transform);
}
@@ -439,14 +434,14 @@ extern "C" void
register_i64(
unsigned int width,
unsigned int height,
int64_t* fixed_arr,
int64_t* moving_arr,
int64_t** fixed_arr,
int64_t** moving_arr,
bool t_or_a,
double** transform
) {
sitk::PixelIDValueEnum id = sitk::PixelIDValueEnum::sitkInt64;
sitk::Image fixed = make_image(width, height, fixed_arr, id);
sitk::Image moving = make_image(width, height, moving_arr, id);
sitk::Image fixed = make_image(width, height, *fixed_arr, id);
sitk::Image moving = make_image(width, height, *moving_arr, id);
reg(fixed, moving, t_or_a, transform);
}
@@ -454,14 +449,14 @@ extern "C" void
register_f32(
unsigned int width,
unsigned int height,
float* fixed_arr,
float* moving_arr,
float** fixed_arr,
float** moving_arr,
bool t_or_a,
double** transform
) {
sitk::PixelIDValueEnum id = sitk::PixelIDValueEnum::sitkFloat32;
sitk::Image fixed = make_image(width, height, fixed_arr, id);
sitk::Image moving = make_image(width, height, moving_arr, id);
sitk::Image fixed = make_image(width, height, *fixed_arr, id);
sitk::Image moving = make_image(width, height, *moving_arr, id);
reg(fixed, moving, t_or_a, transform);
}
@@ -469,13 +464,13 @@ extern "C" void
register_f64(
unsigned int width,
unsigned int height,
double* fixed_arr,
double* moving_arr,
double** fixed_arr,
double** moving_arr,
bool t_or_a,
double** transform
) {
sitk::PixelIDValueEnum id = sitk::PixelIDValueEnum::sitkFloat64;
sitk::Image fixed = make_image(width, height, fixed_arr, id);
sitk::Image moving = make_image(width, height, moving_arr, id);
sitk::Image fixed = make_image(width, height, *fixed_arr, id);
sitk::Image moving = make_image(width, height, *moving_arr, id);
reg(fixed, moving, t_or_a, transform);
}