Skip to content

Commit b87f483

Browse files
authored
Merge pull request #245 from dstansby/features-hist-example
Add a features histogram example
2 parents 1e21a93 + 09abee3 commit b87f483

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

examples/features_hist.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""
2+
Hisogram of features
3+
====================
4+
"""
5+
6+
import napari
7+
import numpy as np
8+
import numpy.typing as npt
9+
from skimage.measure import regionprops_table
10+
11+
# make a test label image
12+
label_image: npt.NDArray[np.uint16] = np.zeros((100, 100), dtype=np.uint16)
13+
14+
label_image[10:20, 10:20] = 1
15+
label_image[50:70, 50:70] = 2
16+
17+
feature_table_1 = regionprops_table(
18+
label_image, properties=("label", "area", "perimeter")
19+
)
20+
feature_table_1["index"] = feature_table_1["label"]
21+
22+
# make the points data
23+
n_points = 100
24+
points_data = 100 * np.random.random((100, 2))
25+
points_features = {
26+
"feature_0": np.random.random((n_points,)),
27+
"feature_1": np.random.random((n_points,)),
28+
"feature_2": np.random.random((n_points,)),
29+
}
30+
31+
# create the viewer
32+
viewer = napari.Viewer()
33+
viewer.add_labels(label_image, features=feature_table_1)
34+
viewer.add_points(points_data, features=points_features)
35+
36+
# make the widget
37+
viewer.window.add_plugin_dock_widget(
38+
plugin_name="napari-matplotlib", widget_name="FeaturesHistogram"
39+
)
40+
41+
if __name__ == "__main__":
42+
napari.run()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy