representative embodiments according to the inventive subject matter are shown in fig1 - 5 , wherein the same or generally similar features share common reference numerals . fig1 is a schematic , pictorial illustration of a system 20 for endoscopic imaging , in accordance with an embodiment of the inventive subject matter . a video camera 22 captures images 30 of anatomical structures within the body of a patient 26 via an endoscope 24 . in the example shown in the figure , endoscope 24 is a rigid laparoscope , and camera 22 is coupled to the proximal end of the laparoscope , outside the patient &# 39 ; s body . alternatively , endoscope 24 may comprise a rigid or flexible endoscope of any other suitable type , and the camera may be located at either the proximal or the distal end ( assuming the camera is configured to allow automatic focal adjustment ). further alternatively , the principles of the inventive subject matter may be implemented in video imaging systems of other types , such as systems for machine vision and microscopy , and are by no means limited to endoscopic applications . camera 22 comprises imaging optics 36 , which focus an image onto an image sensor 38 . the image sensor may comprise any suitable type of sensing device , such as a ccd or cmos - type sensor , in either a single - sensor or multi - sensor configuration . optics 36 are adjustable , under external control , in order to vary the focal distance of the images that are formed on the image sensor . the adjustment may be carried out , for example , by motorized motion of one or more lenses in optics 36 , or alternatively using any other suitable method of focal adjustment that is known in the art . a user 28 , typically a medical practitioner , aims endoscope 24 so that the sensor captures images of the desired anatomical structures . a console 32 processes the output of sensor 38 in order to produce video images 30 in the appropriate format . after inserting endoscope 24 into the patient &# 39 ; s body and aiming the endoscope toward the anatomical structure of interest , user 28 actuates auto - focus controls 34 and 35 . alternatively , this focusing procedure may be carried out simultaneously with color balancing (“ white balance ”), while the user aims the endoscope toward a calibration target , such as a white pad ( not shown ). controls 34 and 35 may comprise dual push - buttons , as is illustrated in the figure , for toggling the focal mechanism forward and back . alternatively , system 20 may comprise a single auto - focus control or multiple push - buttons or switches or controls of any other suitable type . actuation of controls 34 and 35 invokes an auto - focus process , in which optics 36 are set to an optimal focal distance , as described with reference to the figures that follow . this auto - focus process may be carried out under the control of console 32 and / or by another suitable controller ( not shown ) that is contained within camera 22 or in another housing . fig2 is a flow chart that schematically illustrates a method for user - actuated auto - focus , in accordance with an embodiment of the inventive subject matter . the method is initiated when user 28 presses auto - focus control 34 or 35 , at an actuation step 40 . while the user presses the controls , the controller ( such as console 32 ) drives the focal adjustment mechanism of optics 36 so as to gradually scan ( increase and / or decrease ) the focal distance . meanwhile , image sensor 38 captures a succession of images 30 , which are typically output for viewing by the user . the controller measures one or more characteristics of the images that are indicative of image focal quality , and records the measurement it has made as a function of focal distance , at an image measurement step 42 . for example , the controller may measure image “ edginess ,” i . e ., a measure of the sharpness , or contrast , of edges in the image . for this purpose , the controller may digitally filter the image using a suitable kernel , and then sum the resulting output values . one kernel that may be used for this purpose is alternatively , the filter may output at each pixel the difference between the maximum and minimum pixel values in a certain neighborhood ( such as a 3 × 3 neighborhood ) of the pixel . alternatively , the controller may measure any other suitable image characteristic or group of characteristics that are indicative of focal quality . the user - actuated scan of focal distance terminates when the user releases the auto - focus controls , at a release step 44 . ( alternatively , the user may terminate the scan by actuating the controls in a certain way , or by any other suitable action or sequence of actions .) for best results , it is desirable that the user observe images 30 and terminate the scan immediately after reaching the setting at which the perceived image quality is best . in this case , the controller will generally have to perform little or no additional scanning in order to reach the final focal setting , and the likelihood is increased that the scan will result in a setting at which the image features of interest to the user are sharply focused . alternatively , however , the user may terminate the scan at any other desired point . at the conclusion of steps 40 - 44 , the controller will have collected measurements of focal quality as a function of focal distance setting over a range of focal distances . the controller evaluates these collected measurements in order to decide what additional , automatic focal adjustment may still be needed , at a decision step 46 . if the current setting is the one that gave the optimal ( typically maximal ) quality measure , the controller stops the auto - focus process and takes no further action . otherwise , the controller chooses the direction for adjustment that should , according to the collected measurements , lead to an increase in the focal quality . the controller drives the auto - focus mechanism to adjust the focus of optics 36 in the chosen direction , at an automatic adjustment step 48 . the adjustment continues until the controller passes a significant maximum of the focal quality measure . “ significant ” in this context means , for example , that the maximal measure exceeds a certain baseline value by a predetermined threshold or percentage . after passing and identifying the maximum , the controller drives the focal adjustment mechanism back to the setting that gave the optimal quality measure , at a concluding step 50 . the controller may return to this setting either by tracking the focal quality measure until it returns to the maximal value or by running the adjustment mechanism for the required time or distance to reach the optimal setting . fig3 a and 3b are a flow chart that schematically shows details of an exemplary implementation of the method of fig2 , in accordance with an embodiment of the inventive subject matter . as explained above , after the user actuates controls 34 and / or 35 at step 40 , the controller runs the auto - focus motor ( or other mechanism ) and computes an image edginess measure ( iem ) as a function of focal setting , at an iem collection step 60 . the controller analyzes the iem results to find the maximum and baseline values , wherein the baseline may typically be set to the minimum iem value . the iem may be computed over the entire image or , alternatively , over a certain window within the image , such as a selected area in the center of the image . the window size and shape may be adjusted according to the needs of the application . the window may be chosen dynamically from among a number of options in order to give the strongest maximum or best contrast between maximum and baseline , or to give a focal distance ( maximum iem value ) that is closest to the setting at which the user subsequently releases controls 34 and 35 at step 44 . additionally or alternatively , the iem may be computed over each of a number of different windows , and the focal distance may be set on the basis of a combination of iem values taken from the different windows . the initial scan of focal distance ends , as noted above , when the user releases controls 34 and 35 at step 42 or , alternatively , if the auto - focus mechanism previously reaches the end of its range , at a range limit step 62 . in this latter event , the controller stops the scan at the limit , at a search termination step 64 . if the user is satisfied with the end - of - range setting , the user may release the controls , and the process will terminate at this point . otherwise , the user may actuate the controls once more , thus returning to step 40 . the controller will then repeat step 60 , this time running the auto - focus mechanism in the opposite direction from the previous scan . when the user releases the focus controls at step 42 , the controller checks whether the duration of step 60 was sufficient to collect iem data for a certain minimal number of video frames , at an iem availability checking step 66 . typically , for reliable results , the controller uses data from at least ten frames , for example . if the user released the controls before a sufficient number of frames was collected , the controller may continue to run the auto - focus mechanism and collect iem data , at a continued running step 68 , until it has a sufficient number of frames or until it reaches the focus limit . in an alternative embodiment , the search may terminate at step 64 if the user has actuated the auto - focus controls for less than the minimal number of frames . this option permits the user to perform manual focus adjustment . after the focal scan has terminated , having collected a sufficient number of frames , the controller checks whether the scan of focal distance passed through an optimal focal point , at a focus checking step 70 . in other words , in the present embodiment , the controller determines whether the scan passed through a significant local maximum . for example , the difference between the maximal and minimal values of the iem may be compared with an average background level of the images ( which may be either a measured value or a predefined level ). for example , the background level may be defined as level of ien when image is not in focus or when no edges present . the maximum may be considered significant if the difference between maximal and minimal iem values exceeds the average background level by a certain factor , such as three . alternatively or additionally , other conditions may be used in identifying significant maxima , such as the profile of the iem curve , as explained below in reference to fig5 . in any case , if the scan did not pass through a significant maximum , the search terminates at step 64 , and the user is prompted to actuate the focus controls once again to resume the search . if the controller finds a significant maximum at step 70 , it determines whether the maximum occurred within the last few frames of the scan , at a maximum identification step 72 . if so , the controller continues to run the auto - focus mechanism in the same direction as in the most recent pass through step 60 , at a scan continuation step 74 . the purpose of this step is to ensure that the frame that was found to have the maximum iem value is the true focal point , and not an inferior local maximum . otherwise , if the maximum was passed more than a few frames before the end of the most recent pass through step 60 , the controller runs the auto - focus mechanism in the opposite direction , at a scan reversal step 76 . typically , the controller seeks to scan over a sufficient range of frames to have at least ten frames on either side of the frame with the maximum iem value ( assuming that the maximum is not found at or very near the end of the focal range of the auto - focus mechanism ). in either case ( step 74 or 76 ), the controller continues to collect iem values and to seek the maximum and minimum iem values , at an iem collection step 78 . based on the collected iem values , the controller sets a threshold ( threshold 1 ) for use in identifying the optimal focal point , at a threshold setting step 80 . for example , the threshold may be set to the iem value measured a certain number ( k ) of frames after the maximum was reached , such as k = 4 frames after the maximum . focal scanning and iem collection at step 80 continue until either the mechanism reaches the focus limit , at a limit checking step 82 , or until a termination criterion is satisfied , at a scan termination step 84 . typically , this termination criterion requires that a sufficient number of frames ( for example , ten frames ) have elapsed beyond the frame with maximum iem , and that the iem value of the current frame is sufficiently far beneath the maximum value , for example , 25 % below the maximum . when the controller determines that it has reached the focal range limit at step 82 or satisfied the criterion of step 84 , it again reverses the scan direction of the auto - focus mechanism , at a further scan reversal step 86 . the controller now drives the auto - focus mechanism to scan back and forth over the range around the setting with maximum iem until it converges on the optimal focus . as an initial step in this process , the controller sets a countdown timer to a number of frames that is equal to the current distance ( in frames ) from the maximum iem value found in the scan of step 78 , plus an overshoot of m1 additional frames , at a countdown setting step 88 . typically , m1 may be set to 10 frames , for example . the countdown timer is used , as explained below , in order to prevent excessive scanning back and forth , which may occur , for example , if the scene imaged by camera 22 has changed . such a scene change may result in a change in iem values as a function of the focal setting . following the scan direction reversal at step 86 , the controller runs the auto - focus mechanism , at a convergent scanning step 90 . the controller computes the iem values of the captured images and seeks the point at which the iem value of the current frame passes the threshold ( threshold 1 ), at a threshold checking step 94 . the controller stops the search at this point , where the focal setting will likely be within a short distance of the optimal setting , at a process termination step 96 . in the meanwhile , for each video frame that passes while scanning the auto - focus mechanism at step 90 , the controller decrements the countdown timer that was set previously . if the threshold condition of step 94 is not satisfied , the controller terminates the current scan when the timer reaches zero , at a timer checking step 98 . ( as noted above , this sort of timeout may occur if the scene imaged by camera 22 has changed .) in this case , the controller again reverses the scan direction , at a final reversal step 100 . for purposes of the reverse scan that is to follow , the controller finds the maximum iem value of the scan performed at step 90 , and sets a new threshold ( threshold 2 ) to the iem value of the kth frame following the maximum of this latter scan , at a new threshold setting step 92 . the controller also resets the countdown timer to a final value m2 , at a final timer setting step 102 . m2 is typically set to a value greater than the overshoot value m1 that was set previously . m2 is chosen so that , if a significant maximum of the iem value is not found in the subsequent scan , the auto - focus mechanism will be set at or near the focal setting for which the maximum iem value was found previously . after reversing the scan direction at step 100 , the controller again runs the auto - focus mechanism , computes iem values , and decrements the countdown timer , at a final scanning step 104 . the scan terminates , at step 96 , either when the iem value of the current frame passes the threshold , at a final threshold checking step 106 , or when the countdown reaches zero , at a final timer checking step 108 . the focus of camera 22 should now be set at or near the optimal value for viewing the anatomical structures of interest to the user . if not , or if readjustment of the focal distance is needed subsequently for any reason , the user may again press control 34 or 35 in order to restart the auto - focus process . fig4 is a flow chart that schematically illustrates a method for user - actuated auto - focus , in accordance with an alternative embodiment of the inventive subject matter . in this case ( as well as in the embodiment of fig5 , described below ), the user actuates auto - focus control 34 or 35 only to initiate the auto - focus process , at an initiation step 110 . the controller does not rely on the user to release the control at or near the optimal focus , but rather scans the auto - focus mechanism autonomously , at a scanning step 112 . the controller computes and records edginess ( iem ) values of the image frames during the scan , and then decides whether it has found a significant maximum value , at a decision step 114 . if the scan passed a significant maximum , the controller reverses the scan direction and repeats the search , at a reverse scanning step 116 , in a manner similar to that described above with reference to fig3 a and 3b . finally , the controller returns the auto - focus mechanism to the optimal setting , giving the maximal iem value , either by time ( countdown ) or by iem measurement , at a final setting step 118 . fig5 is a flow chart that schematically illustrates a method for user - actuated auto - focus , in accordance with another alternative embodiment of the inventive subject matter . as in the embodiment of fig4 , the user in the present embodiment actuates the auto - focus control once , at an initiation step 120 . the controller scans the auto - focus mechanism , typically all the way to the focus limit , at a scanning step 122 . as in the preceding embodiments , the controller computes and collects the edginess measure of the image frames . in the embodiment of fig5 , however , the controller searches not simply for a local maximum , but for a maximum with a defocus profile that has a shape similar to the expected shape for transition from focused to defocused optics , at a defocus assessment step 124 . in other words , the controller evaluates the shape of the iem curve as a function of focal distance ( or equivalently , as a function of time or frame number ). in particular , the controller tests the gradient of the curve against the expected range of gradients . the sort of test helps to ensure that the auto - focus process finds a true focal point , and does not converge to a local maximum in the iem curve that is the result of artifacts , rather than optical focus . such a test may also be incorporated in the method of fig2 , 3 a and 3 b , as noted above . if the controller finds a maximum in the iem curve with the desired profile , it drives the auto - focus mechanism back to the setting that yielded this maximum , at a final setting step 126 . otherwise , the controller may repeat the scan of focal distance in the opposite direction , at a scan reversal step 128 . the controller again computes and analyzes the iem values to search for a local maximum with the desired profile , at a reverse assessment step 130 . if the controller does not find a local maximum with the desired profile , it simply determines the global maximum of the iem over the entire focal range , and then sets the focal distance at step 126 to give this global maximum vale . in addition to the methods and systems disclosed herein , the inventive subject matter also contemplates a computer readable medium storing a set of instructions ( i . e ., software ) executable by conventional computing devices and processors to perform the disclosed method steps . the inventive subject matter also contemplates methods of manufacture and assembly of systems apparatuses , and components disclosed herein . it will be appreciated that the embodiments described above are cited by way of example , and that the inventive subject matter is not limited to what has been particularly shown and described hereinabove . rather , the scope of the inventive subject matter includes both combinations and subcombinations of the various features described hereinabove , as well as variations and modifications thereof which would occur to persons skilled in the art upon reading the foregoing description and which are not disclosed in the prior art .
methods and systems for adjusting a video imaging system that includes an auto - focus mechanism wherein an input from a user of the video imaging system invokes an auto - focus procedure . responsive to the input , the auto - focus mechanism is scanned over a range of focal distance from a first setting to a second setting indicated by the input . a sequence of images using the video imaging system is captured while scanning the auto - focus mechanism over the range . the images in the sequence are processed so as to compute a measure of focal quality with respect to each of the images . the measure of the focal quality is analyzed so as to select an optimal focal distance , and the auto - focus mechanism is set to the selected focal distance .