Skip to content

Commit

Permalink
ENH: allow Nifti with wrong scales in sform
Browse files Browse the repository at this point in the history
Allow loading of Nifti files incorrectly written by by VINCI with wrong scales in sform,
s. InsightSoftwareConsortium#3514
  • Loading branch information
issakomi committed Aug 16, 2022
1 parent b9005b8 commit 3e84173
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions Modules/IO/NIFTI/src/itkNiftiImageIO.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1912,22 +1912,27 @@ NiftiImageIO::SetImageIOOrientationFromNIfTI(unsigned short dims)
vnl_matrix_fixed<float, 3, 3> 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<float, 3> 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
Expand Down

0 comments on commit 3e84173

Please sign in to comment.