Linked Questions

Popular Questions

Tiling a matrix with a given overlap

Asked by At

I have two 3 dimensional matrices that have exactly the same shape. One of these matrices is an image and the other is a label mask. I am trying to tile the image and label masks into smaller sections to analyse separately, essentially trying to recreate the output from patchextraction.get_patch_extractor in tiatoolox. This patch extractor extracts tiles of a given size with a given overlap. It works exactly like I want it to for the image, code here:

wsi_patch_extractor = patchextraction.get_patch_extractor(
    input_img = image,
    method_name = "slidingwindow",
    patch_size = (tile_size_x, tile_size_y),
    stride = (stride_x, stride_y)

But when I do the same for my label mask this function seems to only output value between 0 and 255, when my label mask has values up into the hundreds of thousands. How can I write a similar function that will take the shape of the image/label mask matrix, the size of the desired patches (or the number of patches to split the matrix into) and the desired amount of overlap and will return the correct indices of the overlapping submatrices?

I need this to work exactly like the patch extractor from tiatoolbox but not to change the values inside the matrix.

Related Questions