Sampling image patches based on object densities

Hello everyone, I am working on an image segmentation project where I handle high-resolution images with relatively small objects. So, my approach was to first tile the image such that I deal with smaller patches without loosing the details. However, instead of tiling the images as an offline step, I want to implement a sampling transformation that takes random crops from my image but I do not want empty crops, instead I want the sampling to be based on the number of objects within the crop. Is this doable? Can you guys point me in the right direction? I hope I made my point clear, and thanks in advance!