How can I merge several images via loop using the information of a dataframe? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: How can I merge several images via loop using the information of a dataframe? (/thread-35897.html) |
How can I merge several images via loop using the information of a dataframe? - noahverner1995 - Dec-27-2021 I have the following dictionary: the_dictionary_list = {'Fondo': ['Oceano.png'], 'Cuerpo': ['Cuerpo_cangrejo.png'], 'Ojos': ['Antenas.png', 'Pico.png', 'Verticales.png'], 'Color': ['Amarillo.png', 'Blanco.png', 'Rojirosado.png', 'Turquesa.png', 'Verde_oscuro.png', 'Zapote.png'], 'Pinzas': ['None', 'Pinzitas.png', 'Pinzotas.png', 'Pinzota_pinzita.png'], 'Puas': ['None', 'Arena.png', 'Marron.png', 'Purpura.png', 'Verde.png']}To get each possible permutation without repetition in a specific order (i.e. cartesian products) I use the following code: import itertools as it AllKeysNames = ['Fondo', 'Cuerpo', 'Ojos', 'Color', 'Pinzas', 'Puas'] Combinations = list(it.product(*(the_dictionary_list[Name] for Name in AllKeysNames))) print(f'{Combinations}')Then, for saving each iteration to a dataframe such as it throws an output like this one: I use the following code:new = ['+'.join(x) for x in it.product(*(the_dictionary_list[Name] for Name in AllKeysNames))] df = pd.DataFrame({'Permutations':"+".join(AllKeysNames), 'FilePermutations':new})Now, suppose that the above program is located in the same path (i.e. r"./" ) in which coincidentally the following folders are also located:These folders only contain file images, which *also coincidentally* have the same name of those values in the_dictionary_list .As the df variable has stored the right order in which these images must be merged besides the filenames and foldernames, and also the total amount of permutationsHow could this program take that information from the df and use the functions of:Image.open(r"./") Image.alpha_composite() resize((350, 350), resample=Image.NEAREST from Python Imaging Library (PIL) To produce the new merged images in the order in which the df shows it?Quote:Notes: RE: How can I merge several images via loop using the information of a dataframe? - noahverner1995 - Dec-31-2021 Solved here |