Skip to content

Commit 6e32ea3

Browse files
committed
Fix accidental removal of resize function
1 parent 6a94827 commit 6e32ea3

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Libs/Image/Image.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,22 @@ Image& Image::resample(double isoSpacing, Image::InterpolationType interp) {
416416
return resample(makeVector({isoSpacing, isoSpacing, isoSpacing}), interp);
417417
}
418418

419+
Image& Image::resize(Dims dims, Image::InterpolationType interp) {
420+
// use existing dims for any that are unspecified
421+
Dims inputDims(this->dims());
422+
if (dims[0] == 0) dims[0] = inputDims[0];
423+
if (dims[1] == 0) dims[1] = inputDims[1];
424+
if (dims[2] == 0) dims[2] = inputDims[2];
425+
426+
// compute new spacing so physical image size remains the same
427+
Vector3 inputSpacing(spacing());
428+
Vector3 spacing(makeVector({inputSpacing[0] * inputDims[0] / dims[0], inputSpacing[1] * inputDims[1] / dims[1],
429+
inputSpacing[2] * inputDims[2] / dims[2]}));
430+
431+
return resample(IdentityTransform::New(), origin(), dims, spacing, coordsys(), interp);
432+
}
433+
434+
419435
Image& Image::toAxisAligned(InterpolationType interp) {
420436
// Check if image is already axis-aligned
421437
auto direction = itk_image_->GetDirection();

0 commit comments

Comments
 (0)