Finish implementation of image sampling