From 859c8b82b47718bf7c8c6a807954a2b0e283f2ce Mon Sep 17 00:00:00 2001
From: Sharon Christine Yates <sharoncy@uio.no>
Date: Wed, 3 Apr 2024 14:16:38 +0200
Subject: [PATCH] Fix for "per_pixel"

PyNutil only worked for method = "all". Fix so that it works for "per_pixel" and "per_object".
---
 PyNutil/coordinate_extraction.py | 1 +
 testOOP.py                       | 4 +++-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/PyNutil/coordinate_extraction.py b/PyNutil/coordinate_extraction.py
index a459c06..761d01e 100644
--- a/PyNutil/coordinate_extraction.py
+++ b/PyNutil/coordinate_extraction.py
@@ -309,6 +309,7 @@ def segmentation_to_atlas_space(
     region_areas = get_region_areas(use_flat, atlas_labels, flat_file_atlas, seg_width, seg_height, slice_dict, atlas_volume, triangulation)
     y_scale, x_scale = transform_to_registration(seg_height, seg_width, reg_height, reg_width)
     centroids, points = None, None
+    scaled_centroidsX, scaled_centroidsY, scaled_x, scaled_y = None, None, None, None 
     if method in ["per_object", "all"]:
         centroids, scaled_centroidsX, scaled_centroidsY = get_centroids(segmentation, pixel_id, y_scale, x_scale, object_cutoff)
     if method in ["per_pixel", "all"]:
diff --git a/testOOP.py b/testOOP.py
index 03b7a21..0cab45c 100644
--- a/testOOP.py
+++ b/testOOP.py
@@ -2,11 +2,13 @@ from PyNutil import PyNutil
 import os
 
 os.chdir("..")
+
+
 pnt = PyNutil(settings_file=r"PyNutil/test/test10_PyNutil_web.json")
 
 ##Use flat can be set to True if you want to use the flat file
 # instead of the visualign json (this is only useful for testing and will be removed)
-pnt.get_coordinates(object_cutoff=0, use_flat=False)
+pnt.get_coordinates(object_cutoff=0, method="per_pixel")
 
 pnt.quantify_coordinates()
 
-- 
GitLab