Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 09abee3

Browse filesBrowse files
committed
Add a features histogram example
1 parent 1e21a93 commit 09abee3
Copy full SHA for 09abee3

File tree

1 file changed

+42
-0
lines changed
Filter options

1 file changed

+42
-0
lines changed

‎examples/features_hist.py

Copy file name to clipboard
+42Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.