Skip to content

Commit e08cf04

Browse files
committed
fix(tests): add unit test for custom ROI grid spacing parameters
Closes #282 (cherry picked from commit 3bba587) # Conflicts: # doc/locale/fr/LC_MESSAGES/release_notes/release_1.00.po
1 parent 82cead3 commit e08cf04

File tree

3 files changed

+103
-1
lines changed

3 files changed

+103
-1
lines changed

datalab/tests/features/image/roigrid_unit_test.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,81 @@ def test_roi_grid_geometry_headless() -> None:
5555
assert dy == img.height / 2 * 0.5
5656

5757

58+
def test_roi_grid_custom_step() -> None:
59+
"""Test ROI grid with custom xstep/ystep parameters.
60+
61+
This test verifies the bug fix for Issue #XXX where grid ROI extraction
62+
was not working correctly for images with non-uniformly distributed features
63+
(e.g., laser spot arrays with gaps between spots).
64+
65+
The bug was that xstep and ystep parameters were missing, so users couldn't
66+
adjust the spacing between ROIs when spots don't fill the entire image.
67+
"""
68+
img = create_grid_of_gaussian_images()
69+
70+
# Test Case 1: Custom step to simulate tighter spacing (e.g., laser spots)
71+
gp = ROIGridParam()
72+
gp.nx, gp.ny = 3, 3
73+
gp.xsize = gp.ysize = 20 # Small ROI size (20% of cell)
74+
gp.xtranslation = gp.ytranslation = 50 # Centered
75+
gp.xstep = gp.ystep = 75 # Tighter spacing (75% instead of 100%)
76+
gp.xdirection = gp.ydirection = Direction.INCREASING
77+
78+
with qt_app_context():
79+
dlg = ImageGridROIEditor(parent=None, obj=img, gridparam=gp)
80+
dlg.update_obj(update_item=False)
81+
roi = dlg.get_roi()
82+
assert roi is not None
83+
# 9 ROIs for 3x3 grid
84+
assert len(list(roi)) == 9
85+
86+
# Verify spacing is correctly applied
87+
r11 = next(r for r in roi if r.title == "ROI(1,1)")
88+
r12 = next(r for r in roi if r.title == "ROI(1,2)")
89+
x0_r11, _, _, _ = r11.get_physical_coords(img)
90+
x0_r12, _, _, _ = r12.get_physical_coords(img)
91+
92+
# Expected spacing: (width / nx) * (xstep / 100)
93+
expected_spacing = (img.width / gp.nx) * (gp.xstep / 100.0)
94+
actual_spacing = x0_r12 - x0_r11
95+
96+
# Allow 1% tolerance for numerical precision
97+
assert abs(actual_spacing - expected_spacing) / expected_spacing < 0.01
98+
99+
# Test Case 2: Different X and Y steps
100+
gp2 = ROIGridParam()
101+
gp2.nx, gp2.ny = 2, 2
102+
gp2.xsize = gp2.ysize = 30
103+
gp2.xtranslation = gp2.ytranslation = 50
104+
gp2.xstep = 80 # Tighter X spacing
105+
gp2.ystep = 120 # Wider Y spacing
106+
gp2.xdirection = gp2.ydirection = Direction.INCREASING
107+
108+
with qt_app_context():
109+
dlg2 = ImageGridROIEditor(parent=None, obj=img, gridparam=gp2)
110+
dlg2.update_obj(update_item=False)
111+
roi2 = dlg2.get_roi()
112+
assert roi2 is not None
113+
assert len(list(roi2)) == 4
114+
115+
# Verify X spacing (80%)
116+
r11 = next(r for r in roi2 if r.title == "ROI(1,1)")
117+
r12 = next(r for r in roi2 if r.title == "ROI(1,2)")
118+
x0_r11, y0_r11, _, _ = r11.get_physical_coords(img)
119+
x0_r12, _, _, _ = r12.get_physical_coords(img)
120+
expected_x_spacing = (img.width / gp2.nx) * 0.8
121+
actual_x_spacing = x0_r12 - x0_r11
122+
assert abs(actual_x_spacing - expected_x_spacing) / expected_x_spacing < 0.01
123+
124+
# Verify Y spacing (120%)
125+
r21 = next(r for r in roi2 if r.title == "ROI(2,1)")
126+
_, y0_r21, _, _ = r21.get_physical_coords(img)
127+
expected_y_spacing = (img.height / gp2.ny) * 1.2
128+
actual_y_spacing = y0_r21 - y0_r11
129+
assert abs(actual_y_spacing - expected_y_spacing) / expected_y_spacing < 0.01
130+
131+
58132
if __name__ == "__main__":
59133
test_roi_grid_geometry_headless()
134+
test_roi_grid_custom_step()
60135
test_roi_grid(screenshots=True)

doc/locale/fr/LC_MESSAGES/release_notes/release_1.00.po

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ msgid ""
77
msgstr ""
88
"Project-Id-Version: DataLab \n"
99
"Report-Msgid-Bugs-To: \n"
10-
"POT-Creation-Date: 2025-12-13 17:07+0100\n"
10+
"POT-Creation-Date: 2025-12-13 17:28+0100\n"
1111
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1212
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1313
"Language: fr\n"
@@ -215,6 +215,24 @@ msgstr "Correction du suffixe en double dans le titre de l'image résultante lor
215215
msgid "This fix is provided by Sigima 1.0.4"
216216
msgstr "Ce correctif est fourni par Sigima 1.0.4"
217217

218+
msgid "**Grid ROI - Missing spacing parameters for non-uniform grids:**"
219+
msgstr "**ROI de grille - Paramètres d'espacement manquants pour les grilles non uniformes :**"
220+
221+
msgid "Fixed grid ROI feature not working correctly for images where subimages don't fill the entire image area (e.g., laser spot arrays with gaps between spots)"
222+
msgstr "Correction de la fonctionnalité ROI de grille ne fonctionnant pas correctement pour les images où les sous-images ne remplissent pas toute la zone de l'image (par exemple, les réseaux de points laser avec des espaces entre les points)"
223+
224+
msgid "Added missing `xstep` and `ystep` parameters to control horizontal and vertical spacing between ROI centers, as a percentage of the automatically computed cell width/height (default 100% = evenly distributed grid)"
225+
msgstr "Ajout des paramètres manquants `xstep` et `ystep` pour contrôler l'espacement horizontal et vertical entre les centres des ROI, en pourcentage de la largeur/hauteur de cellule calculée automatiquement (par défaut 100 % = grille uniformément répartie)"
226+
227+
msgid "Previously, the grid was always assumed to be evenly distributed across the entire image, which failed when there was significant offset or gaps between features"
228+
msgstr "Auparavant, la grille était toujours supposée être uniformément répartie sur toute l'image, ce qui échouait lorsqu'il y avait un décalage ou des espaces importants entre les caractéristiques"
229+
230+
msgid "Users can now adjust ROI spacing independently from ROI size to accurately extract grids from real-world data like laser spot arrays, diffraction patterns, or any regularly spaced features with gaps"
231+
msgstr "Les utilisateurs peuvent désormais ajuster l'espacement des ROI indépendamment de la taille des ROI pour extraire avec précision des grilles à partir de données réelles telles que des réseaux de points laser, des motifs de diffraction ou toute caractéristique régulièrement espacée avec des espaces"
232+
233+
msgid "This closes [Issue #282](https://github.com/datalab-platform/datalab/issues/282) - Grid ROI Missing Spacing Parameters"
234+
msgstr "Ceci clôture [Issue #282](https://github.com/datalab-platform/datalab/issues/282) - Paramètres d'espacement manquants pour la ROI de grille"
235+
218236
msgid "**Result visualization - Analysis result segments hard to see:**"
219237
msgstr "**Visualisation des résultats - Segments de résultats d'analyse difficiles à voir :**"
220238

doc/release_notes/release_1.00.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,15 @@
9494
* Fixed duplicate suffix in result image title when extracting radial profile from an image (e.g., `radial_profile(i019)|center=(192.500, 192.500)|center=(192.500, 192.500)` instead of `radial_profile(i019)|center=(192.500, 192.500)`)
9595
* This fix is provided by Sigima 1.0.4
9696

97+
**Grid ROI - Missing spacing parameters for non-uniform grids:**
98+
99+
* Fixed grid ROI feature not working correctly for images where subimages don't fill the entire image area (e.g., laser spot arrays with gaps between spots)
100+
* Added missing `xstep` and `ystep` parameters to control horizontal and vertical spacing between ROI centers, as a percentage of the automatically computed cell width/height (default 100% = evenly distributed grid)
101+
* Previously, the grid was always assumed to be evenly distributed across the entire image, which failed when there was significant offset or gaps between features
102+
* Users can now adjust ROI spacing independently from ROI size to accurately extract grids from real-world data like laser spot arrays, diffraction patterns, or any regularly spaced features with gaps
103+
* This fix is provided by Sigima 1.0.4
104+
* This closes [Issue #282](https://github.com/datalab-platform/datalab/issues/282) - Grid ROI Missing Spacing Parameters
105+
97106
**Result visualization - Analysis result segments hard to see:**
98107

99108
* Fixed analysis result markers (FWHM, pulse features, etc.) being difficult or impossible to see on signal plots

0 commit comments

Comments
 (0)