|
| 1 | +""" |
| 2 | +Hisogram of features |
| 3 | +==================== |
| 4 | +""" |
| 5 | + |
| 6 | +importnapari |
| 7 | +importnumpyasnp |
| 8 | +importnumpy.typingasnpt |
| 9 | +fromskimage.measureimportregionprops_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() |