Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions doc/release_notes/release_1.01.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Version 1.1 #

## Sigima Version 1.1.4 ##

### 🛠️ Bug Fixes since version 1.1.3 ###

* **Ellipse/circle contour detection**: Fixed regression in axis orientation after the v1.1.3 coordinate swap fix. This closes [Issue #27](https://github.com/DataLab-Platform/Sigima/issues/27).
* The sign correction applied in v1.1.3 for the `(row, col)` → `(x, y)` conversion introduced a regression in ellipse axis orientation, causing the semi-major and semi-minor axes to be transposed
* Added ground-truth unit tests for `fit_circle_model` and `fit_ellipse_model` verifying all output parameters (center coordinates, radius/semi-axes, and rotation angle)

## Sigima Version 1.1.3 ##

### 🛠️ Bug Fixes since version 1.1.2 ###
Expand Down
2 changes: 1 addition & 1 deletion sigima/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
# Set validation mode to ENABLED by default (issue warnings for invalid inputs)
set_validation_mode(ValidationMode.ENABLED)

__version__ = "1.1.3"
__version__ = "1.1.4"
__docurl__ = "https://sigima.readthedocs.io/"
__homeurl__ = "https://github.com/DataLab-Platform/Sigima"
__supporturl__ = "https://github.com/DataLab-Platform/sigima/issues/new/choose"
Expand Down
48 changes: 48 additions & 0 deletions sigima/tests/image/preprocessing_tools_unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from sigima.enums import BinningOperation
from sigima.tools.image.preprocessing import (
_USE_NEW_SHAPE_API,
binning,
distance_matrix,
fit_circle_model,
Expand Down Expand Up @@ -84,6 +85,53 @@ def test_fit_ellipse_model_failure() -> None:
assert result is None or isinstance(result, tuple)


def test_fit_circle_model_ground_truth() -> None:
"""Verify that ``fit_circle_model`` recovers **all** circle parameters
(xc, yc, radius) from a noise-free contour.

Note: the functions swap x/y because scikit-image models interpret the
contour columns as (row, col), so the returned ``xc`` corresponds to the
contour's second column and ``yc`` to the first.
"""
if not _USE_NEW_SHAPE_API:
pytest.skip()
xc_in, yc_in, r_in = 7.0, -5.0, 12.0
contour = _circle_contour(xc_in, yc_in, r_in, n=256)
result = fit_circle_model(contour)
assert result is not None
# xc/yc are swapped by the row/col → x/y conversion
yc, xc, r = result
assert xc == pytest.approx(xc_in, abs=1e-6)
assert yc == pytest.approx(yc_in, abs=1e-6)
assert r == pytest.approx(r_in, abs=1e-6)


def test_fit_ellipse_model_ground_truth() -> None:
"""Verify that ``fit_ellipse_model`` recovers **all** ellipse parameters
(xc, yc, a, b, theta) from a noise-free contour.

Note: the functions swap x/y and a/b because scikit-image models interpret
the contour columns as (row, col), so centre and semi-axes are transposed.
"""
if not _USE_NEW_SHAPE_API:
pytest.skip()
xc_in, yc_in = -3.0, 5.0
a_in, b_in = 4.0, 8.0
theta_in = np.pi / 6
contour = _ellipse_contour(xc_in, yc_in, a_in, b_in, theta0=theta_in, n=256)
result = fit_ellipse_model(contour)
assert result is not None
# xc/yc are swapped by the row/col → x/y conversion
yc, xc, a, b, theta = result
assert xc == pytest.approx(xc_in, abs=1e-4)
assert yc == pytest.approx(yc_in, abs=1e-4)
assert a == pytest.approx(a_in, abs=1e-4)
assert b == pytest.approx(b_in, abs=1e-4)
# The fitted angle is expected to differ by π/2,
# theta along y axis instead of x axis
assert theta == pytest.approx(theta_in + np.pi / 2, abs=1e-4)


# ===========================================================================
# get_absolute_level
# ===========================================================================
Expand Down
4 changes: 2 additions & 2 deletions sigima/tools/coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def ellipse_to_diameters(
Ellipse X/Y diameters (major/minor axes) coordinates
"""
dxa, dya = a * np.cos(theta), a * np.sin(theta)
dxb, dyb = -b * np.sin(theta), b * np.cos(theta)
dxb, dyb = b * np.sin(theta), b * np.cos(theta)
x0, y0, x1, y1 = xc - dxa, yc - dya, xc + dxa, yc + dya
x2, y2, x3, y3 = xc - dxb, yc - dyb, xc + dxb, yc + dyb
return x0, y0, x1, y1, x2, y2, x3, y3
Expand All @@ -117,7 +117,7 @@ def array_ellipse_to_diameters(data: np.ndarray) -> np.ndarray:
"""
xc, yc, a, b, theta = data[:, 0], data[:, 1], data[:, 2], data[:, 3], data[:, 4]
dxa, dya = a * np.cos(theta), a * np.sin(theta)
dxb, dyb = -b * np.sin(theta), b * np.cos(theta)
dxb, dyb = b * np.sin(theta), b * np.cos(theta)
x0, y0, x1, y1 = xc - dxa, yc - dya, xc + dxa, yc + dya
x2, y2, x3, y3 = xc - dxb, yc - dyb, xc + dxb, yc + dyb
result = np.column_stack((x0, y0, x1, y1, x2, y2, x3, y3)).astype(float)
Expand Down
Loading