From 91091b3da7705dfa4523c73937f6228a802321ee Mon Sep 17 00:00:00 2001
From: Christopher Rhodes <christopher.rhodes@embl.de>
Date: Wed, 6 Sep 2023 11:53:48 +0200
Subject: [PATCH] Pixel classification in 3D works, but pixel maps are not
 aligned with original image, suspect X-Y flipped

---
 examples/ilastik3d.py | 45 ++++++++++++++++---------------------------
 1 file changed, 17 insertions(+), 28 deletions(-)

diff --git a/examples/ilastik3d.py b/examples/ilastik3d.py
index c377a507..8733d0e6 100644
--- a/examples/ilastik3d.py
+++ b/examples/ilastik3d.py
@@ -30,21 +30,22 @@ if __name__ == '__main__':
     resp_paths = requests.get(uri + 'paths')
     paths = resp_paths.json()
 
+    def request_put(endpoint, params):
+        resp = requests.put(uri + endpoint, params=params)
+        assert resp.status_code == 200, resp.content.decode()
+        return resp.json()
+
     # load ilastik pixel model
-    resp_load_px = requests.put(
-        uri + 'models/ilastik/pixel_classification/load/',
-        params={'project_file': px3d_ilp},
-    )
-    assert resp_load_px.status_code == 200, resp_load_px.content.decode()
-    model_id_px = resp_load_px.json()['model_id']
+    model_id_px = request_put(
+        'models/ilastik/pixel_classification/load/',
+        {'project_file': px3d_ilp}
+    )['model_id']
 
     # load ilastik object model
-    resp_load_ob = requests.put(
-        uri + 'models/ilastik/object_classification/load/',
-        params={'project_file': ob3d_ilp},
-    )
-    assert resp_load_ob.status_code == 200, resp_load_ob.content.decode()
-    model_id_ob = resp_load_ob.json()['model_id']
+    model_id_ob = request_put(
+        'models/ilastik/object_classification/load/',
+        {'project_file': ob3d_ilp}
+    )['model_id']
 
     # copy files from network storage to processing directory
     for ff in czis:
@@ -53,26 +54,14 @@ if __name__ == '__main__':
         copyfile(infile, outfile)
 
         # infer pixel maps
-        resp_infer_px = requests.put(
-            uri + f'infer/from_image_file',
-            params={
+        request_put(
+            'infer/from_image_file',
+            {
                 'model_id': model_id_px,
                 'input_filename': ff,
                 'channel': channel,
-            },
-        )
-        assert resp_infer_px == 200, resp_load_px.content.decode()
-
-        # infer object maps
-        resp_infer_ob = requests.put(
-            uri + f'infer/from_image_file',
-            params={
-                'model_id': model_id_ob,
-                'input_filename': ff,
-                'channel': channel,
-            },
+            }
         )
-        assert resp_infer_ob == 200, resp_infer_ob.content.decode()
 
     resp_models = requests.get(uri + 'models')
 
-- 
GitLab