Repository: SciKit-Surgery/scikit-surgeryvtk (language: python)

Issue:
Test failure and move to scikit-surgery org
I'm getting a bunch of test failures, probably regression tests that use opencv. Let's also take the opportunity to move this to scikit-surgery org.


Discussion / hints:

Fix patch:
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index ca1705c6..41e48a2e 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -20,7 +20,6 @@ jobs:
             python-ver: 3.6
             experimental: true
 
-
     runs-on: ${{ matrix.os }}
     continue-on-error: ${{ matrix.experimental }}
 
@@ -71,6 +70,13 @@ jobs:
           coverage run -a --source ./sksurgeryvtk -m pytest
           coverage report -m
 
+      - name: archive projected images
+        if: startsWith(matrix.os, 'ubuntu')
+        uses: actions/upload-artifact@v2
+        with:
+          name: image
+          path: tests/output/fig06_case1b_overlay.png
+
       - name: Linting
         run: |
           pylint --rcfile=tests/pylintrc sksurgeryvtk
diff --git a/requirements.txt b/requirements.txt
index daaa2186..947edea5 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -7,4 +7,4 @@ vtk<=9.0.1
 PySide2<5.15.0
 opencv-contrib-python>=4.1.1.26
 scikit-surgerycore>=0.1.7
-scikit-surgeryimage>=0.2.0
+scikit-surgeryimage>=0.9.0
diff --git a/setup.py b/setup.py
index 370b6319..00357462 100644
--- a/setup.py
+++ b/setup.py
@@ -55,7 +55,7 @@
         'PySide2<5.15.0',
         'opencv-contrib-python>=4.1.1.26',
         'scikit-surgerycore>=0.1.7',
-        'scikit-surgeryimage>=0.2.0',
+        'scikit-surgeryimage>=0.9.0',
     ],
 
     entry_points={


Test patch:
diff --git a/tests/camera/test_liver_overlay.py b/tests/camera/test_liver_overlay.py
index 243d81ae..c2ec4841 100644
--- a/tests/camera/test_liver_overlay.py
+++ b/tests/camera/test_liver_overlay.py
@@ -1,12 +1,14 @@
 # -*- coding: utf-8 -*-
 
+import os
+import sys
 import copy
 import pytest
 import vtk
 import cv2
 import numpy as np
+from sksurgeryimage.utilities.utilities import are_similar
 import sksurgeryvtk.models.vtk_surface_model as sm
-import os
 
 
 def reproject_and_save(image,
@@ -58,10 +60,19 @@ def test_overlay_liver_points(setup_vtk_overlay_window):
     if not os.path.exists(output_name):
         os.mkdir(output_name)
 
+    ref_image_path  = 'tests/data/liver/fig06_case1b_overlay.png'
     # We aren't using 'proper' hardware rendering on GitHub CI, so skip
     in_github_ci = os.environ.get('CI')
     if in_github_ci:
-        pytest.skip("Don't run rendering test on GitHub CI")
+        ref_image_path = 'tests/data/liver/fig06_case1b_overlay_for_ci.png'
+        if 'linux' in sys.platform:
+            ref_image_path = 'tests/data/liver/fig06_case1b_overlay_for_linux_ci.png'
+
+    print ("\nenviron = " , os.environ.get('CI'))
+    print ("platform = ", sys.platform)
+    print ("using : ", ref_image_path)
+    reference_image = cv2.imread(ref_image_path)
+    #pytest.skip("Don't run rendering test on GitHub CI")
 
     intrinsics_file = 'tests/data/liver/calib.left.intrinsics.txt'
     intrinsics = np.loadtxt(intrinsics_file)
@@ -113,10 +124,10 @@ def test_overlay_liver_points(setup_vtk_overlay_window):
     vtk_overlay.save_scene_to_file('tests/output/fig06_case1b_overlay.png')
 
     # Compare with expected result.
-    reference_image = cv2.imread('tests/data/liver/fig06_case1b_overlay.png')
     rendered_image = cv2.imread('tests/output/fig06_case1b_overlay.png')
 
-    assert np.allclose(reference_image, rendered_image, atol=1)
+    assert are_similar (reference_image, rendered_image, threshold = 0.995,
+                        metric = cv2.TM_CCOEFF_NORMED, mean_threshold = 0.005)
 
     # Just for interactive testing.
     # app.exec_()
diff --git a/tests/data/liver/fig06_case1b_overlay.png b/tests/data/liver/fig06_case1b_overlay.png
index 623786f9..c7287b4d 100644
Binary files a/tests/data/liver/fig06_case1b_overlay.png and b/tests/data/liver/fig06_case1b_overlay.png differ
diff --git a/tests/data/liver/fig06_case1b_overlay_for_ci.png b/tests/data/liver/fig06_case1b_overlay_for_ci.png
new file mode 100644
index 00000000..623786f9
Binary files /dev/null and b/tests/data/liver/fig06_case1b_overlay_for_ci.png differ
diff --git a/tests/data/liver/fig06_case1b_overlay_for_linux_ci.png b/tests/data/liver/fig06_case1b_overlay_for_linux_ci.png
new file mode 100644
index 00000000..6bc0810d
Binary files /dev/null and b/tests/data/liver/fig06_case1b_overlay_for_linux_ci.png differ
diff --git a/tests/models/test_vtk_surface_model.py b/tests/models/test_vtk_surface_model.py
index f018d097..e9b4711c 100644
--- a/tests/models/test_vtk_surface_model.py
+++ b/tests/models/test_vtk_surface_model.py
@@ -5,6 +5,7 @@
 import numpy as np
 from vtk.util import colors
 from sksurgeryvtk.models.vtk_surface_model import VTKSurfaceModel
+from sksurgeryimage.utilities.utilities import are_similar
 import cv2
 import sys
 import os
@@ -269,16 +270,19 @@ def test_set_texture_regression(vtk_overlay_with_gradient_image):
     print("Github CI: " + str(in_github_ci))
 
     if sys.platform == "darwin":
-        pytest.skip("Test not working on Mac runner \
-                    because the widget size is different")
+        pass
+        #pytest.skip("Test not working on Mac runner \
+                #           because the widget size is different")
 
     if in_github_ci and sys.platform.startswith("linux"):
-        pytest.skip("Test not working on Linux runner \
-                    because of unknown issue, see #60.")
+        pass
+    #pytest.skip("Test not working on Linux runner \
+            #                because of unknown issue, see #60.")
     
     if in_github_ci and sys.platform.startswith("win"):
-        pytest.skip("Skip on Windows on GitHub CI (use of MESA messes up \
-                     result")
+        pass
+    #pytest.skip("Skip on Windows on GitHub CI (use of MESA messes up \
+            #                 result")
 
     input_file = 'tests/data/models/liver.ply'
     model = VTKSurfaceModel(input_file, colors.red)
@@ -303,17 +307,11 @@ def test_set_texture_regression(vtk_overlay_with_gradient_image):
     cv2.imwrite(os.path.join(tmp_dir, 'screenshot.png'), screenshot)
     cv2.imwrite(os.path.join(tmp_dir, 'current_scene.png'), current_scene)
 
-    # As the rendered images in Ubuntu, Mac and Windows are different,
-    # i.e., the pixel values are slightly different at the same location,
-    # we add some threshold for comparison.
-    # It checks if the number of values (in any channel)
-    # that are different by more than 3 is less than 5 per cent
-    # of the total number of pixels in the image.
+    # As the rendered images in Ubuntu, Mac and Windows are different, we'll
+    # use the are similar function from sksurgery image
 
-    diff = abs(screenshot - current_scene)
-
-    assert (np.sum((diff > 3).astype(int))
-            / (screenshot.shape[0] * screenshot.shape[1]) * screenshot.shape[2]) < 0.05
+    assert are_similar (screenshot, current_scene, threshold = 0.995,
+                        metric = cv2.TM_CCOEFF_NORMED, mean_threshold = 0.005)
 
     #app.exec_()