Extract Overlapping Patches from a 3D Medical image and reconstruct the patches back to an Image

I have a 3D CT image size of shape 284,143,143 and I want to extract 3D patches of size 64x64x64.
Is there a way I can extract the patches from this volumetric image and reconstruct patches back. I have been using unfold function from pytorch so far but havent acheived the desired goal . But is there any way to do it using ITK.
The aim is to send these image patches as input to my 3D GANs model. And reconstruct the generated image patches back to an image

Thank you

1 Like

You can use region of interest filter (example) to extract your patches. You will need to be careful in choosing positions (origins) of the patches to have uniform overlap. You will probably want to record region indices (patch origins) so you can reconstruct your generated image later. Maybe use paste image filter, maybe iterators.

I’ve used @fepegar’s TorchIO package for exactly the same purpose. Check its GridSampler and GridAggregator, here’s the documentation for them.


Thanks, @ibro45! @DL_Begin you can also check e.g. the WeightedSampler for that. TorchIO uses ITK a lot under the hood, so the libraries are very compatible.