1. A method for searching a gradient of a function over a target object, comprising: selecting a first location of the target object; performing a sensing or measuring operation at the first location to obtain a respective value of the function; selecting a first loop having multiple first loop locations of the target object that are different from the first location; performing a sensing or measuring operation at the multiple first loop locations of the first loop, without performing the sensing or measuring operation at other locations, to obtain values of the function at the respective multiple first loop locations; selecting one of the multiple first loop locations that has the maximum or minimum value for the function among the multiple first locations; using the first location and the selected first loop location that has the maximum or minimum value for the function among the multiple first loop locations, and corresponding values of the function to determine a first gradient between the first location and the selected first loop location; selecting a second location of the target object along a direction of the first gradient; performing a sensing or measuring operation at the second location to obtain a respective value of the function; selecting a second loop having multiple second loop locations of the target object that are different from the second location; performing a sensing or measuring operation at the multiple second loop locations, without performing the sensing or measuring operation at other locations, to obtain values of the function at the respective multiple second loop locations; selecting one of the multiple second loop locations that has the maximum or minimum value for the function among the multiple second locations; and using the second location and the selected second loop location that has the maximum or minimum value for the function among the multiple second t loop locations, and corresponding values of the function to determine a second gradient between the second location and the selected second loop location; wherein the sensing or measuring operation at a location of the target object to obtain a respective value of the function includes optically imaging the location of the target object to obtain information regarding the respective value of the function; wherein the target object is a target tissue of a patient and the function is a function of a height, depth or thickness of the target tissue with respect to location; wherein the steps of the method performed each comprise an operation of a controller and an imaging system coupled to the controller.