added stepwise image downsampling to improve the resulting image quality