Add function that tune minlen according to image size