Zeroing batch of images according to given coordinates

Dear Pytorch enthusiasts;

I have an interesting problem to solve.

I am searching for an efficient way of cropping images by given coordinates.

For example;

Let’s say there is a coords tensor with (N, 4) size, and images tensors with (N, 640, 640) size.

By using given coords and their corresponding images, how can I keep the crop regions, and zero out the remaining? Is there any possible batch operation for that?

Thanks,