Copy randomized rectangles from one directory of images to another

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
aer
Posts: 5
Joined: 2014-06-30T18:30:14-07:00
Authentication code: 6789

Copy randomized rectangles from one directory of images to another

Post by aer » 2019-08-16T11:24:38-07:00

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.

snibgo
Posts: 12024
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post by snibgo » 2019-08-16T11:58:08-07:00

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.
snibgo's IM pages: im.snibgo.com

aer
Posts: 5
Joined: 2014-06-30T18:30:14-07:00
Authentication code: 6789

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

Post by aer » 2019-08-16T12:03:04-07:00

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

Post Reply