I am doing a few image transformations - resize, offset, and crop. I am doing all these operations separately, but I feel like they can be better combined to get a speed improvement. This is happening hundreds of times in a loop, so I am looking to optimize this code. Any suggestions would be great - I am somewhat new to numpy. Here is my code as it is now:
# original image is only loaded into memory once: self.original_image = cv2.imread(self.file_path, cv2.IMREAD_UNCHANGED) # image is resized... image_resize = cv2.resize(self.original_image, (0, 0), fx=zoom, fy=zoom) # offset image M = np.float32([[1, 0, x_total], [0, 1, y_total]]) image_offset = cv2.warpAffine(image_resize, M, (self.original_image_width, self.original_image_width)) #image crop image = image_offset[0:self.output_raster_height, 0:self.output_raster_width].copy() #numpy to pil and away! corrected_img = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) from_pil = PImage.fromarray(corrected_img) from_pil.save(p.stdin, 'JPEG')
Suggestions would be much appreciated!