Added a pyramid optimization method and modified the code to support pyramidation of the images.