Closed kaczmarj closed 1 year ago
the ROI would be in geojson format. it could include multiple regions potentially. here's a tentative plan:
def get_patches_in_rois(geojson_path: str, coords: np.ndarray, patch_size: int):
with open(geojson_path) as f:
geo = geojson.load(f)
num_rois = len(geo["features"])
print(f"Processing {num_rois} rois")
for roi in geo["features"]:
assert roi.is_valid, "an ROI geometry is not valid"
# Each geom is a shapely Polygon type.
geoms_rois = [shape(roi["geometry"]) for roi in geo["features"]]
boxes = [box(x, y, x+patch_size, y+patch_size) for x, y in coords]
tree = shapely.STRtree(boxes)
_, intersecting_ids = tree.query([geom, geom], predicate="intersects")
intersecting_ids = np.sort(np.unique(intersecting_ids))
return coords[intersecting_ids]
it works!
use case here is in qupath. one would be in qupath and would annotate a region of interest. this roi would be run by wsinfer.
the roi would be encoded as geojson. we can check if the patches overlap with the ROI and apply the model to those patches.