Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
- also exclude solidity cause it also relies on convex_area
  • Loading branch information
zoccoler committed Jan 16, 2023
1 parent dbe5743 commit 7c98c07
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
8 changes: 4 additions & 4 deletions napari_skimage_regionprops/_regionprops.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ def standard_deviation_intensity(region, intensities):
warnings.warn("Perimeter measurements are not supported in 3D")

if shape:
properties = properties + ['solidity', 'extent', 'local_centroid']
properties = properties + ['extent', 'local_centroid']
# Workaround to avoid existing scikit-image bug
# See https://github.com/scikit-image/scikit-image/issues/6432
if (len(labels.shape) == 3) and (_check_2D_labels_in_3D_images(labels)):
warnings.warn("2D labels are present in 3D label image, 'feret_diameter_max' not calculated")
warnings.warn("2D labels are present in 3D label image, 'feret_diameter_max' and 'solidity' not calculated")
else:
properties = properties + ['feret_diameter_max']
properties = properties + ['solidity', 'feret_diameter_max']
if len(labels.shape) == 2:
properties = properties + ['major_axis_length', 'minor_axis_length', 'orientation', 'eccentricity']
# we need these two to compute some shape descriptors
Expand Down Expand Up @@ -108,7 +108,7 @@ def standard_deviation_intensity(region, intensities):
# weighted_moments_central
# weighted_moments_hu
# weighted_moments_normalized

print('PROPERTIES = ', properties)
# quantitative analysis using scikit-image's regionprops
from skimage.measure import regionprops_table as sk_regionprops_table
table = sk_regionprops_table(np.asarray(labels).astype(int), intensity_image=np.asarray(image),
Expand Down
18 changes: 18 additions & 0 deletions napari_skimage_regionprops/_tests/test_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,3 +397,21 @@ def test_measure_points():
points = np.random.random((100, 2)) * 99

nsr.measure_points(points, image)

def test_2d_labels_in_3d_image():
import numpy as np
labels = np.zeros((6,6,6), dtype=np.uint8)
labels[1:4, 1:4, 1:4] = 1 # 3D label
labels[4, 1:4, 1:4] = 2 # 2D label

from napari_skimage_regionprops import regionprops_table
table = regionprops_table(labels, labels, size=True, intensity=True, perimeter=True, shape=True, position=True,
moments=True)

# check one measurement
assert np.array_equal(table['area'], [27, 9])

# check that measurements that depend on convex_area are absent in this case
assert "convex_area" not in table.keys()
assert "feret_max_diameter" not in table.keys()
assert "solidity" not in table.keys()

0 comments on commit 7c98c07

Please sign in to comment.