A method for optimizing focus of an optical system passively comprising the steps of; - discretizing optical positions (focus distances) of the optical system , - initializing an idle counter, which holds the number of iterations that optical system is unable to improve focus performance, to zero; driving optical system to a predetermined initial optical position; initializing best position, which holds the best focusing distance came across up until the current execution iteration, to current position; clearing a sharpness array, which holds sharpness values of already processed images , - calculating correspondence for at least one image as a value pair in 2-tuple format where the first entry corresponds to the focus distance of the optical system for the image and the second entry corresponds to a sharpness value calculated for the image , - adding at least one sharpness value to sharpness array and ordering sharpness value entries in the sharpness array consecutively to represent consecutive focus distances, - calculating longest increasing subsequence on said consecutively ordered sharpness value entries in the sharpness array , - checking if the longest increasing subsequence length increases , - clearing idle counter if longest increasing subsequence length increases , - setting best position to current position , - incrementing idle counter if longest increasing subsequence length doesn't increase , - checking if the idle counter has reached a predetermined termination threshold , - checking if the current position corresponds to the end of discrete optical positions if the idle counter has not reached the termination threshold , - driving motors to the next position if the current position doesn't correspond to the end of discrete optical positions , - going to the best position and terminating process if the idle counter has reached the termination threshold or if the current position corresponds to the end of discrete optical positions . - discretizing optical positions (focus distances) of the optical system , - initializing an idle counter, which holds the number of iterations that optical system is unable to improve focus performance, to zero; driving optical system to a predetermined initial optical position; initializing best position, which holds the best focusing distance came across up until the current execution iteration, to current position; clearing a sharpness array, which holds sharpness values of already processed images , - calculating correspondence for at least one image as a value pair in 2-tuple format where the first entry corresponds to the focus distance of the optical system for the image and the second entry corresponds to a sharpness value calculated for the image , - adding at least one sharpness value to sharpness array and ordering sharpness value entries in the sharpness array consecutively to represent consecutive focus distances, - calculating longest increasing subsequence on said consecutively ordered sharpness value entries in the sharpness array , - checking if the longest increasing subsequence length increases , - clearing idle counter if longest increasing subsequence length increases , - setting best position to current position , - incrementing idle counter if longest increasing subsequence length doesn't increase , - checking if the idle counter has reached a predetermined termination threshold , - checking if the current position corresponds to the end of discrete optical positions if the idle counter has not reached the termination threshold , - driving motors to the next position if the current position doesn't correspond to the end of discrete optical positions , - going to the best position and terminating process if the idle counter has reached the termination threshold or if the current position corresponds to the end of discrete optical positions . <EOS>