2121# guitest: show,skip
2222
2323import sigima .objects
24- import sigima .params as sigima_param
24+ import sigima .params
2525from sigima .tests .data import get_test_image
2626
27+ from datalab .config import Conf
2728from datalab .tests import datalab_test_app_context
2829
2930
@@ -39,7 +40,7 @@ def run_beautiful_scenario(screenshots: bool = False) -> None:
3940 panel .processor .run_feature ("wiener" )
4041 panel .processor .run_feature ("derivative" )
4142 panel .processor .run_feature ("integral" )
42- panel .processor .run_feature ("gaussian_filter" , sigima_param .GaussianParam ())
43+ panel .processor .run_feature ("gaussian_filter" , sigima . params .GaussianParam ())
4344 panel .processor .run_feature ("fft" )
4445 panel .processor .run_feature ("derivative" )
4546 if screenshots :
@@ -51,16 +52,16 @@ def run_beautiful_scenario(screenshots: bool = False) -> None:
5152 ima = sigima .objects .create_image_from_param (param )
5253 ima .set_metadata_option ("colormap" , "jet" )
5354 panel .add_object (ima )
54- panel .processor .run_feature ("equalize_hist" , sigima_param .EqualizeHistParam ())
55+ panel .processor .run_feature ("equalize_hist" , sigima . params .EqualizeHistParam ())
5556 panel .processor .run_feature (
56- "equalize_adapthist" , sigima_param .EqualizeAdaptHistParam ()
57+ "equalize_adapthist" , sigima . params .EqualizeAdaptHistParam ()
5758 )
58- panel .processor .run_feature ("denoise_tv" , sigima_param .DenoiseTVParam ())
59+ panel .processor .run_feature ("denoise_tv" , sigima . params .DenoiseTVParam ())
5960 panel .processor .run_feature (
60- "denoise_wavelet" , sigima_param .DenoiseWaveletParam ()
61+ "denoise_wavelet" , sigima . params .DenoiseWaveletParam ()
6162 )
62- panel .processor .run_feature ("white_tophat" , sigima_param .MorphologyParam ())
63- panel .processor .run_feature ("denoise_tv" , sigima_param .DenoiseTVParam ())
63+ panel .processor .run_feature ("white_tophat" , sigima . params .MorphologyParam ())
64+ panel .processor .run_feature ("denoise_tv" , sigima . params .DenoiseTVParam ())
6465 n = data_size // 3
6566 roi = sigima .objects .create_image_roi (
6667 "rectangle" , [n , n , data_size - 2 * n , data_size - 2 * n ]
@@ -71,13 +72,15 @@ def run_beautiful_scenario(screenshots: bool = False) -> None:
7172 win .take_menu_screenshots ()
7273
7374
74- def run_circle_detection_scenario (screenshots : bool = False ) -> None :
75+ def run_blob_detection_on_flower_image (screenshots : bool = False ) -> None :
7576 """High-level test scenario for flower image with ROI extraction
7677
7778 This scenario creates:
7879 - A flower test image
7980 - Roberts edge detection filter applied
8081 - A rectangular ROI extraction
82+ - A closing morphological filter to clean up the result
83+ - Blob detection using OpenCV algorithm
8184 """
8285 with datalab_test_app_context (console = False , exec_loop = not screenshots ) as win :
8386 # Create an image panel
@@ -86,59 +89,33 @@ def run_circle_detection_scenario(screenshots: bool = False) -> None:
8689 # Load the flower test image
8790 ima = get_test_image ("flower.npy" )
8891 ima .title = "Test image 'flower.npy'"
89- ima .set_metadata_option ("colormap" , "jet" )
9092 panel .add_object (ima )
9193
9294 # Apply Roberts filter for edge detection
9395 panel .processor .run_feature ("roberts" )
9496
9597 # Extract a rectangular ROI
96- roi = sigima .objects .create_image_roi ("rectangle" , [32 , 128 , 448 , 256 ])
98+ roi = sigima .objects .create_image_roi ("rectangle" , [32 , 64 , 448 , 384 ])
9799 panel .processor .compute_roi_extraction (roi )
98100
99- if screenshots :
100- win .statusBar ().hide ()
101- win .take_screenshot ("i_flower_roi" )
102-
103-
104- def test_contour_detection_limits () -> None :
105- """Test scenario to verify result truncation limits work correctly
106-
107- This scenario tests:
108- - Contour detection on flower.npy (generates many contours)
109- - Result truncation at max_result_rows limit
110- - Shape drawing truncation at max_shapes_to_draw limit
111- - Label display truncation at max_cells_in_label & max_cols_in_label limits
112- - Warning dialog at max_cells_in_dialog limit
113- """
114- with datalab_test_app_context (console = False , exec_loop = False ) as win :
115- # Create an image panel
116- panel = win .imagepanel
117-
118- # Load the flower test image
119- ima = get_test_image ("flower.npy" )
120- ima .title = "Test image 'flower.npy' - Contour Detection Limit Test"
121- ima .set_metadata_option ("colormap" , "jet" )
122- panel .add_object (ima )
123-
124- # Run contour detection which should trigger the limits
125- # This will detect many contours and test our safety mechanisms
126- print ("\n Running contour detection on flower.npy..." )
127- print ("This should trigger result truncation and shape drawing limits." )
128- panel .processor .run_feature ("contour_shape" , sigima_param .ContourShapeParam ())
129-
130- print ("\n Test completed successfully!" )
131- print ("Expected behavior:" )
132- print (" 1. Results truncated to max_result_rows (default: 1000)" )
133- print (" 2. Only max_shapes_to_draw shapes drawn (default: 50)" )
134- print (" 3. Warning label on plot showing truncation" )
135- print (" 4. Result dialog warning if > max_cells_in_dialog (default: 50000)" )
136- print (" 5. Merged label: max_cells_in_label (100) & max_cols_in_label (15)" )
101+ # Apply a closing morphological filter to clean up the result
102+ closing_param = sigima .params .MorphologyParam .create (radius = 10 )
103+ panel .processor .run_feature ("closing" , closing_param )
104+
105+ # Detect blobs using OpenCV algorithm
106+ param = sigima .params .BlobOpenCVParam ()
107+ param .filter_by_color = False
108+ param .min_area = 400
109+ param .max_area = 1000
110+ param .filter_by_circularity = True
111+ param .min_circularity = 0.7
112+ with Conf .proc .show_result_dialog .temp (False ):
113+ with Conf .view .show_result_label .temp (False ):
114+ panel .processor .run_feature ("blob_opencv" , param )
115+ if screenshots :
116+ win .statusBar ().hide ()
117+ win .take_screenshot ("i_blob_detection_flower" )
137118
138119
139120if __name__ == "__main__" :
140- # Uncomment to run the original scenarios:
141- # run_circle_detection_scenario()
142-
143- # Run the test for result limits
144- test_contour_detection_limits ()
121+ run_blob_detection_on_flower_image (screenshots = False )
0 commit comments