Skip to content

Instantly share code, notes, and snippets.

@EKami
Last active June 14, 2018 13:37
Show Gist options
  • Save EKami/1cdc53877efc79c77d6388b8c3f3ac53 to your computer and use it in GitHub Desktop.
Save EKami/1cdc53877efc79c77d6388b8c3f3ac53 to your computer and use it in GitHub Desktop.
mask_img = np.array(Image.open(mask.file, mode='r').convert('1'))
# Absolute WSI coordinates
dx = max(patch_x, mask.x)
dx2 = min(patch_x + self.crop_size, mask.x + mask.width)
dy = max(patch_y, mask.y)
dy2 = min(patch_y + self.crop_size, mask.y + mask.height)
# Make the coordinates relative to the mask position
dx = dx - mask.x
dx2 = dx2 - mask.x
dy = dy - mask.y
dy2 = dy2 - mask.y
# Should get the union area between the patch and the mask
if dx2 > 0 and dy2 > 0:
# Invert x and y because of PIL -> numpy transform
area = mask_img[dy:dy2, dx:dx2]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment