rotate_image.py
Go to the documentation of this file.
1 import matplotlib.pyplot as plt
2 import os
3 import glob
4 import time
5 
6 from PIL import Image
7 
8 
9 def create_image(i, j):
10  image = Image.new("RGB", (i, j), (205, 205, 205))
11  return image
12 
13 
14 def convert_imm(in_file, out_folder, file_name, angle=45):
15  # receive as parameter the image to rotate, the location where to save, the name and the angle
16 
17  src_im = Image.open(in_file)
18  # compute size
19  real_size = src_im.size
20  proportion = float(real_size[0]) / real_size[1]
21  first_dimension = real_size[0]
22  second_dimension = float(first_dimension) / proportion
23  size = int(first_dimension), int(second_dimension)
24 
25  width, height = size
26  new = create_image(width + 50, height + 50)
27  im = src_im.convert('RGBA')
28  rot = im.rotate(angle).resize(size)
29  new.paste(rot, (25, 25), rot)
30  new.save(out_folder + "/" + file_name.split(".")[0] + ".png")
31 
32  plt.clf()
33  plt.cla()
34  plt.close()
35 
36 
37 def main():
38  # -------------------PARAMETERS-------------------------------------------------------
39  start = time.time()
40  INFOLDER = './../data/INPUT/Carmen_Input/'
41  OUTFOLDER = './../data/INPUT/IMGs/'
42 
43  for typedataset in glob.glob(INFOLDER + '*'):
44  print("starting to parse folder: ", typedataset)
45  split_path = typedataset.split('/')
46  name_type_dataset = split_path[len(split_path) - 1]
47  print(name_type_dataset)
48 
49  for dataset in glob.iglob(INFOLDER + name_type_dataset + '/*'):
50  print("starting to parse dataset: ", dataset)
51  split_path = dataset.split('/')
52  dataset_name = split_path[len(split_path) - 1]
53  if not os.path.exists(OUTFOLDER + dataset_name):
54  os.mkdir(OUTFOLDER + dataset_name)
55  print(dataset_name)
56 
57  for png in glob.iglob(INFOLDER + name_type_dataset + "/" + dataset_name + "/*.png"):
58  split_path = png.split('/')
59  file_name = split_path[len(split_path) - 1]
60  print("il nome del file che parso :", file_name)
61  if dataset_name == 'Freiburg_Building_079':
62  # convert_imm(png, OUTFOLDER + dataset_name, file_name, angle=4)
63  pass
64  elif dataset_name == 'Intel_Reserach_Lab':
65  # convert_imm(png, OUTFOLDER + dataset_name, file_name, angle=-2)
66  pass
67  elif dataset_name == 'ubremen-cartesium':
68  pass
69  # convert_imm(png, OUTFOLDER + dataset_name, file_name, angle=-20)
70  else:
71  convert_imm(png, OUTFOLDER + dataset_name, file_name, angle=0)
72  end = time.time()
73  print("total time: ", end - start)
74 
75 
76 if __name__ == '__main__':
77  main()
rotate_image.main
def main()
Definition: rotate_image.py:37
rotate_image.convert_imm
def convert_imm(in_file, out_folder, file_name, angle=45)
Definition: rotate_image.py:14
rotate_image.create_image
def create_image(i, j)
Definition: rotate_image.py:9


rose2
Author(s): Gabriele Somaschini, Matteo Luperto
autogenerated on Wed Jun 28 2023 02:21:53