1616 <https://cdlapp.readthedocs.io/en/latest/features/general/plugins.html>`_).
1717"""
1818
19+ import numpy as np
20+ import skimage .draw
21+
22+ import cdl .obj
1923import cdl .param
2024import cdl .plugins
2125
@@ -29,6 +33,24 @@ class ExtractBlobs(cdl.plugins.PluginBase):
2933 description = "This is an example plugin" ,
3034 )
3135
36+ def generate_test_image (self ) -> None :
37+ """Generate test image"""
38+ # Create a NumPy array:
39+ arr = np .random .normal (10000 , 1000 , (2048 , 2048 ))
40+ for _ in range (10 ):
41+ row = np .random .randint (0 , arr .shape [0 ])
42+ col = np .random .randint (0 , arr .shape [1 ])
43+ rr , cc = skimage .draw .disk ((row , col ), 40 , shape = arr .shape )
44+ arr [rr , cc ] -= np .random .randint (5000 , 6000 )
45+ icenter = arr .shape [0 ] // 2
46+ rr , cc = skimage .draw .disk ((icenter , icenter ), 200 , shape = arr .shape )
47+ arr [rr , cc ] -= np .random .randint (5000 , 8000 )
48+ data = np .clip (arr , 0 , 65535 ).astype (np .uint16 )
49+
50+ # Create a new image object and add it to the image panel
51+ image = cdl .obj .create_image ("Test image" , data , units = ("mm" , "mm" , "lsb" ))
52+ self .proxy .add_object (image )
53+
3254 def preprocess (self ) -> None :
3355 """Preprocess image"""
3456 panel = self .imagepanel
@@ -40,6 +62,9 @@ def detect_blobs(self) -> None:
4062 """Detect circular blobs"""
4163 panel = self .imagepanel
4264 param = cdl .param .BlobOpenCVParam ()
65+ param .filter_by_color = False
66+ param .min_area = 600.0
67+ param .max_area = 6000.0
4368 param .filter_by_circularity = True
4469 param .min_circularity = 0.8
4570 param .max_circularity = 1.0
@@ -49,5 +74,10 @@ def create_actions(self) -> None:
4974 """Create actions"""
5075 acth = self .imagepanel .acthandler
5176 with acth .new_menu (self .PLUGIN_INFO .name ):
77+ acth .new_action (
78+ "Generate test image" ,
79+ triggered = self .generate_test_image ,
80+ select_condition = "always" ,
81+ )
5282 acth .new_action ("Preprocess image" , triggered = self .preprocess )
5383 acth .new_action ("Detect circular blobs" , triggered = self .detect_blobs )
0 commit comments