Skip to content

Commit

Permalink
Allow mean pixel value inference from int arrays, not just float (#220)
Browse files Browse the repository at this point in the history
1. Now only passes None to self.pixel_values i ncsr.py if subdtype is
np.bool_ rather than only collecting pixel_values when subdtype is
np.float_ allowing for pixel_values to be obtained from int and uint
images.
2. add skeletonlabel to _testdata.py to have an example int array
3. add test_skeletonlabel to test_csr.py to confirm int array behaves as
expected with csr.summarize

---------

Co-authored-by: Juan Nunez-Iglesias <jni@fastmail.com>
  • Loading branch information
TimMonko and jni authored Oct 30, 2023
1 parent 20ab48d commit e248c51
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ all = [
testing = [
'coverage',
'hypothesis',
'napari[pyqt5]!=0.4.18',
'napari[pyqt5]>=0.4.19rc1',
'pytest',
'pytest-cov',
'pytest-qt',
'seaborn<1.0',
'tifffile',
]
docs = [
'napari[all]<0.4.18',
'napari[all]>=0.4.19rc1',
'sphinx',
'jupyter',
'notebook',
Expand Down
7 changes: 7 additions & 0 deletions src/skan/_testdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,10 @@
[1, 0, 1, 0, 0],
[1, 0, 0, 1, 0],
[1, 0, 0, 0, 1]], dtype=bool)

skeletonlabel = np.array([[1, 1, 0, 0, 2, 2, 0],
[0, 0, 1, 0, 0, 0, 2],
[3, 0, 0, 1, 0, 0, 2],
[3, 0, 0, 1, 0, 0, 0],
[3, 0, 0, 0, 1, 1, 1],
[0, 3, 0, 0, 0, 1, 0]], dtype=int)
4 changes: 3 additions & 1 deletion src/skan/csr.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,9 @@ def __init__(
)
if np.issubdtype(skeleton_image.dtype, np.float_):
self.pixel_values = skeleton_image[coords]
else:
elif np.issubdtype(skeleton_image.dtype, np.int_):
self.pixel_values = skeleton_image.astype(float)[coords]
elif np.issubdtype(skeleton_image.dtype, np.bool_):
self.pixel_values = None
self.graph = graph
self.nbgraph = csr_to_nbgraph(graph, self.pixel_values)
Expand Down
7 changes: 6 additions & 1 deletion src/skan/test/test_csr.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from skan import csr, summarize
from skan._testdata import (
tinycycle, tinyline, skeleton0, skeleton1, skeleton2, skeleton3d,
topograph1d, skeleton4
topograph1d, skeleton4, skeletonlabel
)


Expand Down Expand Up @@ -311,3 +311,8 @@ def test_skeleton_path_image_no_keep_image():
s = csr.Skeleton(skeleton2, keep_images=False)
pli = s.path_label_image()
assert np.max(pli) == s.n_paths

def test_skeletonlabel():
stats = csr.summarize(csr.Skeleton(skeletonlabel))
assert stats['mean-pixel-value'].max() == skeletonlabel.max()
assert stats['mean-pixel-value'].max() > 1

0 comments on commit e248c51

Please sign in to comment.