@@ -35,6 +35,48 @@ class Peak:
3535 n_touch : int = 0
3636
3737
38+ def _control_image_size (cpar : ControlPar ) -> tuple [int , int ]:
39+ if hasattr (cpar , "get_image_size" ):
40+ return cpar .get_image_size ()
41+ return cpar .imx , cpar .imy
42+
43+
44+ def _target_thresholds (targ_par : TargetPar ) -> list [int ]:
45+ if hasattr (targ_par , "get_grey_thresholds" ):
46+ return list (targ_par .get_grey_thresholds ())
47+ return list (targ_par .gvthresh )
48+
49+
50+ def _target_discont (targ_par : TargetPar ) -> int :
51+ if hasattr (targ_par , "get_max_discontinuity" ):
52+ return targ_par .get_max_discontinuity ()
53+ return targ_par .discont
54+
55+
56+ def _target_nn_bounds (targ_par : TargetPar ) -> tuple [int , int ]:
57+ if hasattr (targ_par , "get_pixel_count_bounds" ):
58+ return targ_par .get_pixel_count_bounds ()
59+ return targ_par .nnmin , targ_par .nnmax
60+
61+
62+ def _target_nx_bounds (targ_par : TargetPar ) -> tuple [int , int ]:
63+ if hasattr (targ_par , "get_xsize_bounds" ):
64+ return targ_par .get_xsize_bounds ()
65+ return targ_par .nxmin , targ_par .nxmax
66+
67+
68+ def _target_ny_bounds (targ_par : TargetPar ) -> tuple [int , int ]:
69+ if hasattr (targ_par , "get_ysize_bounds" ):
70+ return targ_par .get_ysize_bounds ()
71+ return targ_par .nymin , targ_par .nymax
72+
73+
74+ def _target_min_sum_grey (targ_par : TargetPar ) -> int :
75+ if hasattr (targ_par , "get_min_sum_grey" ):
76+ return targ_par .get_min_sum_grey ()
77+ return targ_par .sumg_min
78+
79+
3880def targ_rec (
3981 img : np .ndarray ,
4082 targ_par : TargetPar ,
@@ -46,12 +88,20 @@ def targ_rec(
4688 num_cam ,
4789) -> List [Target ]:
4890 """Target recognition function."""
91+ imx , imy = _control_image_size (cpar )
92+ thresholds = _target_thresholds (targ_par )
93+ disco = _target_discont (targ_par )
94+ nnmin , nnmax = _target_nn_bounds (targ_par )
95+ nxmin , nxmax = _target_nx_bounds (targ_par )
96+ nymin , nymax = _target_ny_bounds (targ_par )
97+ sumg_min = _target_min_sum_grey (targ_par )
98+
4999 if (
50100 should_use_native ("target_recognition" )
51101 and xmin <= 0
52102 and ymin <= 0
53- and xmax >= cpar . imx
54- and ymax >= cpar . imy
103+ and xmax >= imx
104+ and ymax >= imy
55105 ):
56106 native_tpar = to_native_target_par (targ_par )
57107 native_cpar = to_native_control_par (cpar )
@@ -64,29 +114,23 @@ def targ_rec(
64114 subrange_y = None ,
65115 )
66116 targets = from_native_target_array (native_targets )
67- threshold = targ_par . gvthresh [int (num_cam )]
117+ threshold = thresholds [int (num_cam )]
68118 for target in targets :
69119 target .sumg -= target .n * threshold
70120 return targets
71121
72- thres = targ_par .gvthresh [num_cam ]
73- disco = targ_par .discont
122+ thres = thresholds [num_cam ]
74123
75124 # Make sure the min/max coordinates don't cause us to access memory
76125 # outside the image memory.
77126 if xmin <= 0 :
78127 xmin = 1
79128 if ymin <= 0 :
80129 ymin = 1
81- if xmax >= cpar .imx :
82- xmax = cpar .imx - 1
83- if ymax >= cpar .imy :
84- ymax = cpar .imy - 1
85-
86- nnmin , nnmax = targ_par .nnmin , targ_par .nnmax
87- nxmin , nxmax = targ_par .nxmin , targ_par .nxmax
88- nymin , nymax = targ_par .nymin , targ_par .nymax
89- sumg_min = targ_par .sumg_min
130+ if xmax >= imx :
131+ xmax = imx - 1
132+ if ymax >= imy :
133+ ymax = imy - 1
90134
91135 pix = fast_targ_rec (
92136 img ,
@@ -293,13 +337,18 @@ def peak_fit(
293337 num_cam : int ,
294338) -> List [Target ]:
295339 """Fit the peaks in the image to a gaussian."""
296- imx , imy = cpar .imx , cpar .imy
340+ imx , imy = _control_image_size (cpar )
341+ thresholds = _target_thresholds (targ_par )
342+ disco = _target_discont (targ_par )
343+ nnmin , nnmax = _target_nn_bounds (targ_par )
344+ nxmin , nxmax = _target_nx_bounds (targ_par )
345+ nymin , nymax = _target_ny_bounds (targ_par )
346+ sumg_min = _target_min_sum_grey (targ_par )
297347 n_peaks = 0
298348 n_wait = 0
299349 x8 , y8 = [0 , 1 , 0 , - 1 ], [1 , 0 , - 1 , 0 ]
300350 p2 = 0
301- thres = targ_par .gvthresh [num_cam ]
302- disco = targ_par .discont
351+ thres = thresholds [num_cam ]
303352 intx1 , inty1 = 0 , 0
304353 unify = 0
305354 unified = 0
@@ -525,13 +574,13 @@ def peak_fit(
525574
526575 if (
527576 peaks [i ].unr == 0
528- and peaks [i ].sumg > targ_par . sumg_min
529- and (peaks [i ].xmax - peaks [i ].xmin + 1 ) >= targ_par . nxmin
530- and (peaks [i ].ymax - peaks [i ].ymin + 1 ) >= targ_par . nymin
531- and (peaks [i ].xmax - peaks [i ].xmin ) < targ_par . nxmax
532- and (peaks [i ].ymax - peaks [i ].ymin ) < targ_par . nymax
533- and peaks [i ].n >= targ_par . nnmin
534- and peaks [i ].n <= targ_par . nnmax
577+ and peaks [i ].sumg > sumg_min
578+ and (peaks [i ].xmax - peaks [i ].xmin + 1 ) >= nxmin
579+ and (peaks [i ].ymax - peaks [i ].ymin + 1 ) >= nymin
580+ and (peaks [i ].xmax - peaks [i ].xmin ) < nxmax
581+ and (peaks [i ].ymax - peaks [i ].ymin ) < nymax
582+ and peaks [i ].n >= nnmin
583+ and peaks [i ].n <= nnmax
535584 ):
536585 sumg = peaks [i ].sumg
537586
@@ -641,14 +690,19 @@ def target_recognition(
641690 -------
642691 Number of object holding the targets found.
643692 """
693+ if hasattr (cparam , "get_image_size" ):
694+ imx , imy = cparam .get_image_size ()
695+ else :
696+ imx , imy = cparam .imx , cparam .imy
697+
644698 # Set the subrange (to default if not given):
645699 if subrange_x is None :
646- xmin , xmax = 0 , cparam . imx
700+ xmin , xmax = 0 , imx
647701 else :
648702 xmin , xmax = subrange_x
649703
650704 if subrange_y is None :
651- ymin , ymax = 0 , cparam . imy
705+ ymin , ymax = 0 , imy
652706 else :
653707 ymin , ymax = subrange_y
654708
0 commit comments