Basically, I want to take two folders of images, let's call them dataset A, and datasetB. All the images are named to correspond to eachother, so if there's a file called img100.png in dataset A, there's another in the folder datasetB with the same name that corresponds to it. I want to create a new folder with images of the same names that consist of the image from datasetA with random rectangles copied from the image in datasetB over the image in datasetA, like this:

To be clear, this is just an example. The images I'm actually using are not black and white vs color, so I can't use a technique that just applies grayscale to portions of datasetB.