Skip to content

Define image profiles in physical coordinates - #98

Merged
PierreRaybaut merged 1 commit into
developfrom
fix/image-profiles-physical-coordinates
Oct 25, 2026
Merged

PierreRaybaut merged 1 commit into
developfrom
fix/image-profiles-physical-coordinates

Conversation

@PierreRaybaut

Copy link
Copy Markdown
Contributor

Closes #93

Summary

Image profiles (line_profile, segment_profile, average_profile, radial_profile) are now defined and returned in physical coordinates, consistently with ROIs and analysis results.

  • Renamed parameters (explicit failure for scripts using former names): LineProfileParam.row/col → y/x; SegmentProfileParam / AverageProfileParam row1..col2 → x1, y1, x2, y2 (average: None = image edge instead of -1); RadialProfileParam.x0/y0 → xc/yc.
  • Nearest-pixel selection; coordinates outside the image are refused (no silent clipping).
  • Segment and radial profiles sampled by the smallest pixel spacing (circular radial profile for anisotropic / non-uniform pixels); refused when X and Y units differ.
  • Average profile selects pixels whose center lies in the rectangle (same rule as rectangular ROIs).
  • Profile X axis carries physical coordinates/distances with the matching axis unit and label.
  • Bug fixes: radial profile center on calibrated images (could yield NaN), vertical profile unit, anti-diagonal segments.
  • Contracts bumped to version 2 (rule from Document the contract versioning rule: increase on any change of result, independently of applications #96); get_radial_profile gains xcoords, ycoords, step.
  • Release notes (breaking change + bug fix), FR UI and doc translations, use-case examples updated.

Validation

  • Results identical to the previous implementation on uncalibrated images (origin 0, pixel size 1).
  • New profile_physical_unit_test.py (anisotropic radial, non-uniform coordinates, unit refusal, former names refused, defaults); profile tests rewritten on calibrated anisotropic images.
  • Full suite: 2334 passed; ruff/pylint clean; qualification report OK (4 profile contracts v2).

A DataLab companion PR (same branch name) adapts the profile dialog and tests.

Line, segment, average and radial profiles are now defined and returned in
the image physical coordinates, consistently with ROIs and analysis results:

- parameters renamed (row/col -> y/x, row1..col2 -> x1..y2, x0/y0 -> xc/yc)
  so that scripts using former names fail explicitly;
- nearest pixel selection, coordinates outside the image are refused;
- segment and radial profiles sampled by the smallest pixel spacing
  (circular radial profile for anisotropic or non-uniform pixels),
  refused when X and Y units differ;
- average profile selects pixels whose center lies in the rectangle;
- X axis carries physical coordinates/distances with matching unit/label.

Also fixes the radial profile center on calibrated images, vertical profile
units and anti-diagonal segments. Contracts bumped to version 2.

Closes #93

Assisted-by: Claude Opus 5.5
@PierreRaybaut
PierreRaybaut merged commit 3af8228 into develop Oct 25, 2026
6 checks passed
@PierreRaybaut
PierreRaybaut deleted the fix/image-profiles-physical-coordinates branch October 25, 2026 11:45
PierreRaybaut added a commit that referenced this pull request Oct 26, 2026
Since #98, radial profiles bin the pixels in steps of the smallest distance
between pixel centers, and get_radial_profile accumulated them with
np.bincount on the bin index, which allocates every bin from the center to
the largest distance: a tiny spacing (non-uniform coordinates, strongly
anisotropic pixels) required arrays of several GB for a few pixels.
Coincident pixel centers gave a zero step and an obscure error after
divisions by zero.

Only the bins holding pixels are now accumulated (np.unique with the inverse
index, then np.bincount on it): the memory used never exceeds the size of the
image, and the results are bit-identical (same bins, same order of
accumulation). A bin width that is not positive and finite, non-finite
distances (center or coordinates), and coincident pixel centers are refused
with explicit errors; these inputs already failed. The contract of
radial_profile is unchanged.

Closes #103

Assisted-by: Claude Opus 5.5
@ThomasMalletCodra ThomasMalletCodra added this to the v1.4.0 milestone Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants