changeset 411:db6e17881cd1

improved detection of pixel spacing
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 06 Nov 2025 15:49:15 +0100
parents 6e838900498a
children 1451264fe393
files ViewerPlugin/viewer.js
diffstat 1 files changed, 5 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/ViewerPlugin/viewer.js	Thu Nov 06 15:18:40 2025 +0100
+++ b/ViewerPlugin/viewer.js	Thu Nov 06 15:49:15 2025 +0100
@@ -23,7 +23,7 @@
 
 function IsNear(a, b)
 {
-  return Math.abs(a - b) <= 0.000000001;
+  return Math.abs(a - b) <= 0.01;
 }
 
 
@@ -42,16 +42,17 @@
       imagedVolumeHeight !== undefined) {
     var metersPerUnitX = parseFloat(imagedVolumeWidth) / (1000.0 * parseFloat(width));
     var metersPerUnitY = parseFloat(imagedVolumeHeight) / (1000.0 * parseFloat(height));
-    if (IsNear(metersPerUnitX, metersPerUnitY)) {
+    if (IsNear(metersPerUnitX / metersPerUnitY, 1)) {
       metersPerUnit = metersPerUnitX;
     } else {
       // Backward compatibility with OrthancWSIDicomizer <= 3.2, where X/Y were swapped
       metersPerUnitX = parseFloat(imagedVolumeWidth) / (1000.0 * parseFloat(height));
       metersPerUnitY = parseFloat(imagedVolumeHeight) / (1000.0 * parseFloat(width));
-      if (IsNear(metersPerUnitX, metersPerUnitY)) {
+      if (IsNear(metersPerUnitX / metersPerUnitY, 1)) {
         metersPerUnit = metersPerUnitX;
       } else {
-        console.error('Inconsistency in the imaged volume size, not showing the scale');
+        console.error('Anisotropic pixel spacing (may result from an inconsistency ' +
+                      'in the imaged volume size), not showing the scale');
       }
     }
   }