Created
April 9, 2019 14:48
-
-
Save Blaizzy/1a3e792bf6d02d80f6935b4b9eedd9b7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Rescale(object): | |
| """Rescale the image in a sample to a given size. | |
| Args: | |
| output_size (tuple or int): Desired output size. If tuple, output is | |
| matched to output_size. If int, smaller of image edges is matched | |
| to output_size keeping aspect ratio the same. | |
| """ | |
| def __init__(self, output_sz): | |
| assert isinstance(output_sz,(int,tuple)) | |
| self.output_sz = output_sz | |
| def __call__(self, image): | |
| h,w = image.shape[:2] | |
| if isinstance(self.output_sz, int): | |
| if h > w: | |
| new_h, new_w = self.output_sz * h / w, self.output_sz | |
| else: | |
| new_h, new_w = self.output_sz, self.output_sz * w / h | |
| else: | |
| new_h, new_w = self.output_sz | |
| new_h, new_w = int(new_h), int(new_w) | |
| img = transform.resize(image, (new_h, new_w)) | |
| return img |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment