Page 1 of 1

Copy randomized rectangles from one directory of images to another

Posted: 2019-08-16T11:24:38-07:00
by aer
Hello. I'm pretty new to ImageMagick, so some of this may be basic or just not possible. If anyone can help with any part of this process or point me in the right direction, it would be helpful for me and I can continue researching if I don't get the whole solution here.

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:

Image

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.

Re: Copy randomized rectangles from one directory of images to another

Posted: 2019-08-16T11:58:08-07:00
by snibgo
What version of Windows, on what platform?

Your script can loop through all the images in datasetA, applying a command to the two files.

What command? You could do it by composing the B image over the A image, with a mask that is black where you want A and white where you want B. So the mask is mostly black, with random white rectangles.

Do you want a fixed number of rectangles, or should that also be random? Do you mind if the rectangles overlap, or do you want to prevent that?

If using v7, you could make rectangles with %[fx:...] expressions.

Re: Copy randomized rectangles from one directory of images to another

Posted: 2019-08-16T12:03:04-07:00
by aer
Thank you very much. I just found a technique to do it all for me a couple of seconds ago. The application was machine learning. If anyone else needs this. Look up an augmentation type called cutmix.

Thanks again