diff --git a/Modules/IO/NIFTI/src/itkNiftiImageIO.cxx b/Modules/IO/NIFTI/src/itkNiftiImageIO.cxx index b442b951c57..3a2d4e6c6e7 100644 --- a/Modules/IO/NIFTI/src/itkNiftiImageIO.cxx +++ b/Modules/IO/NIFTI/src/itkNiftiImageIO.cxx @@ -1912,22 +1912,27 @@ NiftiImageIO::SetImageIOOrientationFromNIfTI(unsigned short dims) vnl_matrix_fixed rotation = sto_xyz.extract(3, 3, 0, 0); { // Ensure that the scales are approximately the same for spacing directions + bool sform_scales_ok{ true }; vnl_vector_fixed scale; scale[0] = rotation.get_column(0).magnitude(); + scale[1] = rotation.get_column(1).magnitude(); + scale[2] = rotation.get_column(2).magnitude(); constexpr float large_value_tolerance = 1e-3; // Numerical precision of sform is not very good if (itk::Math::abs(this->m_NiftiImage->dx - scale[0]) > large_value_tolerance) { - return false; + sform_scales_ok = false; } - scale[1] = rotation.get_column(1).magnitude(); - if (itk::Math::abs(this->m_NiftiImage->dy - scale[1]) > large_value_tolerance) + else if (itk::Math::abs(this->m_NiftiImage->dy - scale[1]) > large_value_tolerance) { - return false; + sform_scales_ok = false; } - scale[2] = rotation.get_column(2).magnitude(); - if (itk::Math::abs(this->m_NiftiImage->dz - scale[2]) > large_value_tolerance) + else if (itk::Math::abs(this->m_NiftiImage->dz - scale[2]) > large_value_tolerance) + { + sform_scales_ok = false; + } + if (!sform_scales_ok) { - return false; + itkWarningMacro(<< this->GetFileName() << " has unexpected scales in sform"); } } // Remove scale from columns