Composite - Images in different folder with similar filenames

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
burt46
Posts: 20
Joined: 2016-06-06T11:48:45-07:00
Authentication code: 1151

Composite - Images in different folder with similar filenames

Post by burt46 »

Hi,
I have recently discovered ImageMagick and the ability to overlay images. I am terrible with scripts and not familiar with the scripting language used. I am trying to run ImageMagick from the command line (actually in a dos batch file) to merge (using the Composite function) which works well for selecting particular images. However, I have a folder with 200 images that I want to merge with 200 images in another folder. The filenames are very similar whereby the date in the filename is the same for the two images to combine.

So is it possible to composite two images that have a similar filename (or the same) from different folders and process the folder automatically?

Thanks in advance,
Burt
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Composite - Images in different folder with similar filenames

Post by snibgo »

ImageMagick contains very limited facilities for finding "similar" filenames. The obvious solution is to have a shell script that loops through files in one directory. For each one, it finds the corresponding file in the other directory, then calls ImageMagick with the two filenames.
snibgo's IM pages: im.snibgo.com
burt46
Posts: 20
Joined: 2016-06-06T11:48:45-07:00
Authentication code: 1151

Re: Composite - Images in different folder with similar filenames

Post by burt46 »

Thanks for the quick reply. When you say limited, could ImageMagick do it if the file names were the identical in each folder?

The Shell script sound interesting. Any ideas on how i would apply this to my particular situation? I guess i wont find it on a beach....thats my limited knowledge of a Shell script.

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

Re: Composite - Images in different folder with similar filenames

Post by snibgo »

I suggest you set aside a day or so to read "help for" and experiment with it.
snibgo's IM pages: im.snibgo.com
burt46
Posts: 20
Joined: 2016-06-06T11:48:45-07:00
Authentication code: 1151

Re: Composite - Images in different folder with similar filenames

Post by burt46 »

Would it be expensive to pay an expert to write the code for me?
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Composite - Images in different folder with similar filenames

Post by GeeMack »

burt46 wrote:Thanks for the quick reply. When you say limited, could ImageMagick do it if the file names were the identical in each folder?
That would make it fairly easy, yep. It would also be pretty simple if a DIR command for both folders output the listing in the order needed for the composites. In other words, if the first image listed with the DIR command for your overlay images will be composited onto the first image in the DIR command for the background images, and the second onto the second, and so on. Also, if you can output the DIR /B command of both folders to text files, and edit one or both so they are in corresponding order, that would make it pretty easy, too.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Composite - Images in different folder with similar filenames

Post by fmw42 »

What version of IM and what platform?

Then as Geemack says, how would one coordinate the file names? What are examples of names from both folders and what parts are the same?
burt46
Posts: 20
Joined: 2016-06-06T11:48:45-07:00
Authentication code: 1151

Re: Composite - Images in different folder with similar filenames

Post by burt46 »

Hi thanks for the comments. I am using Windows 7 and ImageMagick 7.0.2-8.

The problem is that the number of images in each of the two folders to join is different, so i only want to composite two images that share the same filename. An example of the image names are>

Folder1

TEXT-C_R_19S_LC5126472013333_ND_B4B7_Color.png
TEXT-C_R_19S_LC5126472014002_ND_B4B7_Color.png
TEXT-C_R_19S_LC5126472014102_ND_B4B7_Color.png

Folder2

TEXT-C_R_19S_LC5146472013317_B895_Final.png
TEXT-C_R_19S_LC5146472013333_B895_Final.png
TEXT-C_R_19S_LC5146472014102_B895_Final.png

Note the differences in filenames where only the 201XXXX is similar between the two folders. I can however change the files names to be the same in each folder if this was easier, but each file wont necesariliy be in the order, as Folder 1 may have 200 images and Folder 2 60 images, so i need to extract the 60 images from the first to do the composite.

Bit more difficult than i thought.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Composite - Images in different folder with similar filenames

Post by snibgo »

The trick is to break it down into sub-problems. Something like this.

1. Loop through all the files in Folder1. For each file:
2. Extract the characters from position 22, length 7 characters. (I may have mis-counted.)
3. If Folder2 contains exactly one file that matches in those characters:
3a. Do a convert command with those two directory/filenames.
4. Continue from step 1.
snibgo's IM pages: im.snibgo.com
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Composite - Images in different folder with similar filenames

Post by GeeMack »

burt46 wrote:Hi thanks for the comments. I am using Windows 7 and ImageMagick 7.0.2-8.

The problem is that the number of images in each of the two folders to join is different, so i only want to composite two images that share the same filename [...] Bit more difficult than i thought.
I still think I'd do something like "DIR /B >> folderlist.txt" to list both of those folders to a text file, and sort the text file which will put the corresponding pairs adjacent to each other in the list. Then I'd manually delete all the ones that aren't pairs (or more automated with a slightly fancy text editor like Notepad++). There are some not so difficult ways to have ImageMagick read the remaining text file and composite every other image onto every other one (think "modulo 2").
Post Reply