(slide, rect)
| 440 | return True |
| 441 | |
| 442 | def crop_rect_from_slide(slide, rect): |
| 443 | minx, miny, maxx, maxy = rect.bounds |
| 444 | # Note that the y-axis is flipped in the slide: the top of the shapely polygon is y = ymax, |
| 445 | # but in the slide it is y = 0. Hence: miny instead of maxy. |
| 446 | top_left_coords = (int(minx), int(miny)) |
| 447 | return slide.read_region(top_left_coords, 0, (int(maxx - minx), int(maxy - miny))) |
| 448 | |
| 449 | class BagOfTiles(Dataset): |
| 450 | def __init__(self, wsi, tiles, resize_to=224): |