diff --git a/WMS/Util.py b/WMS/Util.py index 8705c09..dd0a1c7 100644 --- a/WMS/Util.py +++ b/WMS/Util.py @@ -1,5 +1,7 @@ #Import Pillow library for working with images from PIL import Image +import os +import shutil def split_image(image_path, output_folder, tile_size): @@ -19,7 +21,7 @@ def split_image(image_path, output_folder, tile_size): print("done"); #Checks if the file is of the correct type, otherwise raises an error - if(image_path.split(".")[2] not in acceptedFileTypes): + if(image_path.split(".")[1] not in acceptedFileTypes): return "Filetype not supported" @@ -46,8 +48,65 @@ def split_image(image_path, output_folder, tile_size): tile = image.crop((left_top, left_bottom, right_top, right_bottom)) #Save the tile to the output folder - tile.save(f"{output_folder}/tile_{i}_{j}.jpeg") + tile.save(f"{output_folder}/tile_{i}_{i}.png") - #Return the amount of tiles created to be used for testing purposes + #Return the amount of tiles created return horizontal_tiles + vertical_tiles + +def split_files(image_path, output_folder, tiles, training_fraction, validation_fraction): + ''' + Splits a set of tiles and sorts them according to machine learning specifications + + Args: + image_path (str): The path to where the images are stored + output_folder (str): The path to the output folder + tiles (int): The amount of tiles that need to be handled + training_fraction (int): The amount of tiles that will be used for training + validation (int): The amount of tiles that will be used for validation + + ''' + + + + try: + #Generate output folder + os.mkdir("WMS/" + output_folder + "/") + + #Generate subfolders based on the standard + folders = ["train", "val", "/train/images", "/train/masks", "/val/images", "/val/masks"] + for folder in folders: + path = os.path.join("WMS/" + output_folder + "/" + folder) + os.mkdir(path) + except: + print("Something went wrong with generating the folders...") + + + #Calculate the amount of files for each fraction + training_files = int(training_fraction)/100 * int(tiles) + validation_files = int(validation_fraction)/100 * int(tiles) + + #Copy the files into the right places + for i in range(0, tiles - 1): + if(i > 0 and i < training_files): + try: + shutil.copy2(image_path + f"/orto/tile_{i}_{i}.png", "WMS/" + output_folder + "/train/images") + shutil.copy2(image_path + f"/fasit/tile_{i}_{i}.png", "WMS/" + output_folder + "/train/masks") + except: + print("Something went wrong with copying...") + else: + try: + shutil.copy2(image_path + f"/orto/tile_{i}_{i}.png", "WMS/" + output_folder + "/val/images") + shutil.copy2(image_path + f"/fasit/tile_{i}_{i}.png", "WMS/" + output_folder + "/val/masks") + except: + print("Something went wrong with copying...") + + #Delete the files, we dont need them anymore + for i in range(0, tiles): + try: + os.remove(image_path + f"/orto/tile_{i}_{i}.png") + os.remove(image_path + f"/fasit/tile_{i}_{i}.png") + except: + print("Couldn't delete") + + diff --git a/WMS/__pycache__/__init__.cpython-311.pyc b/WMS/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000..3190edb Binary files /dev/null and b/WMS/__pycache__/__init__.cpython-311.pyc differ diff --git a/WMS/email/train/images/tile_1_1.png b/WMS/email/train/images/tile_1_1.png new file mode 100644 index 0000000..51a6b3e Binary files /dev/null and b/WMS/email/train/images/tile_1_1.png differ diff --git a/WMS/email/train/images/tile_2_2.png b/WMS/email/train/images/tile_2_2.png new file mode 100644 index 0000000..894ba60 Binary files /dev/null and b/WMS/email/train/images/tile_2_2.png differ diff --git a/WMS/email/train/images/tile_3_3.png b/WMS/email/train/images/tile_3_3.png new file mode 100644 index 0000000..2eae7b0 Binary files /dev/null and b/WMS/email/train/images/tile_3_3.png differ diff --git a/WMS/email/train/images/tile_4_4.png b/WMS/email/train/images/tile_4_4.png new file mode 100644 index 0000000..2e9cef8 Binary files /dev/null and b/WMS/email/train/images/tile_4_4.png differ diff --git a/WMS/email/train/images/tile_5_5.png b/WMS/email/train/images/tile_5_5.png new file mode 100644 index 0000000..53c0855 Binary files /dev/null and b/WMS/email/train/images/tile_5_5.png differ diff --git a/WMS/email/train/images/tile_6_6.png b/WMS/email/train/images/tile_6_6.png new file mode 100644 index 0000000..72b5014 Binary files /dev/null and b/WMS/email/train/images/tile_6_6.png differ diff --git a/WMS/email/train/images/tile_7_7.png b/WMS/email/train/images/tile_7_7.png new file mode 100644 index 0000000..ad6338f Binary files /dev/null and b/WMS/email/train/images/tile_7_7.png differ diff --git a/WMS/email/train/images/tile_8_8.png b/WMS/email/train/images/tile_8_8.png new file mode 100644 index 0000000..9293b8d Binary files /dev/null and b/WMS/email/train/images/tile_8_8.png differ diff --git a/WMS/email/train/masks/tile_1_1.png b/WMS/email/train/masks/tile_1_1.png new file mode 100644 index 0000000..3f60232 Binary files /dev/null and b/WMS/email/train/masks/tile_1_1.png differ diff --git a/WMS/email/train/masks/tile_2_2.png b/WMS/email/train/masks/tile_2_2.png new file mode 100644 index 0000000..5f85b1d Binary files /dev/null and b/WMS/email/train/masks/tile_2_2.png differ diff --git a/WMS/email/train/masks/tile_3_3.png b/WMS/email/train/masks/tile_3_3.png new file mode 100644 index 0000000..db4731b Binary files /dev/null and b/WMS/email/train/masks/tile_3_3.png differ diff --git a/WMS/email/train/masks/tile_4_4.png b/WMS/email/train/masks/tile_4_4.png new file mode 100644 index 0000000..89a9435 Binary files /dev/null and b/WMS/email/train/masks/tile_4_4.png differ diff --git a/WMS/email/train/masks/tile_5_5.png b/WMS/email/train/masks/tile_5_5.png new file mode 100644 index 0000000..94caf44 Binary files /dev/null and b/WMS/email/train/masks/tile_5_5.png differ diff --git a/WMS/email/train/masks/tile_6_6.png b/WMS/email/train/masks/tile_6_6.png new file mode 100644 index 0000000..439ff78 Binary files /dev/null and b/WMS/email/train/masks/tile_6_6.png differ diff --git a/WMS/email/train/masks/tile_7_7.png b/WMS/email/train/masks/tile_7_7.png new file mode 100644 index 0000000..7657e70 Binary files /dev/null and b/WMS/email/train/masks/tile_7_7.png differ diff --git a/WMS/email/train/masks/tile_8_8.png b/WMS/email/train/masks/tile_8_8.png new file mode 100644 index 0000000..b99c2e3 Binary files /dev/null and b/WMS/email/train/masks/tile_8_8.png differ diff --git a/WMS/email/val/images/tile_0_0.png b/WMS/email/val/images/tile_0_0.png new file mode 100644 index 0000000..51a6b3e Binary files /dev/null and b/WMS/email/val/images/tile_0_0.png differ diff --git a/WMS/email/val/masks/tile_0_0.png b/WMS/email/val/masks/tile_0_0.png new file mode 100644 index 0000000..3f60232 Binary files /dev/null and b/WMS/email/val/masks/tile_0_0.png differ diff --git a/WMS/ortofoto_images/output_20240217013013.png b/WMS/ortofoto_images/output_20240217013013.png new file mode 100644 index 0000000..526d9cc Binary files /dev/null and b/WMS/ortofoto_images/output_20240217013013.png differ diff --git a/WMS/rawphotos/eksempel.png b/WMS/rawphotos/eksempel.png deleted file mode 100644 index ddc8e77..0000000 Binary files a/WMS/rawphotos/eksempel.png and /dev/null differ diff --git a/WMS/rawphotos/fasit.png b/WMS/rawphotos/fasit.png new file mode 100644 index 0000000..37e7981 Binary files /dev/null and b/WMS/rawphotos/fasit.png differ diff --git a/WMS/rawphotos/orto.png b/WMS/rawphotos/orto.png new file mode 100644 index 0000000..95bb9c7 Binary files /dev/null and b/WMS/rawphotos/orto.png differ diff --git a/WMS/readyforemail/tile_0_0.jpeg b/WMS/readyforemail/tile_0_0.jpeg deleted file mode 100644 index 52c1048..0000000 Binary files a/WMS/readyforemail/tile_0_0.jpeg and /dev/null differ diff --git a/WMS/readyforemail/tile_0_1.jpeg b/WMS/readyforemail/tile_0_1.jpeg deleted file mode 100644 index 238b02e..0000000 Binary files a/WMS/readyforemail/tile_0_1.jpeg and /dev/null differ diff --git a/WMS/readyforemail/tile_0_2.jpeg b/WMS/readyforemail/tile_0_2.jpeg deleted file mode 100644 index bd23abf..0000000 Binary files a/WMS/readyforemail/tile_0_2.jpeg and /dev/null differ diff --git a/WMS/readyforemail/tile_1_0.jpeg b/WMS/readyforemail/tile_1_0.jpeg deleted file mode 100644 index 8ed6583..0000000 Binary files a/WMS/readyforemail/tile_1_0.jpeg and /dev/null differ diff --git a/WMS/readyforemail/tile_1_1.jpeg b/WMS/readyforemail/tile_1_1.jpeg deleted file mode 100644 index 14ec2e1..0000000 Binary files a/WMS/readyforemail/tile_1_1.jpeg and /dev/null differ diff --git a/WMS/readyforemail/tile_1_2.jpeg b/WMS/readyforemail/tile_1_2.jpeg deleted file mode 100644 index 44dfad1..0000000 Binary files a/WMS/readyforemail/tile_1_2.jpeg and /dev/null differ diff --git a/WMS/readyforemail/tile_2_0.jpeg b/WMS/readyforemail/tile_2_0.jpeg deleted file mode 100644 index 29346bf..0000000 Binary files a/WMS/readyforemail/tile_2_0.jpeg and /dev/null differ diff --git a/WMS/readyforemail/tile_2_1.jpeg b/WMS/readyforemail/tile_2_1.jpeg deleted file mode 100644 index 15c10d8..0000000 Binary files a/WMS/readyforemail/tile_2_1.jpeg and /dev/null differ diff --git a/WMS/readyforemail/tile_2_2.jpeg b/WMS/readyforemail/tile_2_2.jpeg deleted file mode 100644 index 42a7bf7..0000000 Binary files a/WMS/readyforemail/tile_2_2.jpeg and /dev/null differ diff --git a/WMS/readyforemail/tile_3_0.jpeg b/WMS/readyforemail/tile_3_0.jpeg deleted file mode 100644 index 46ff02e..0000000 Binary files a/WMS/readyforemail/tile_3_0.jpeg and /dev/null differ diff --git a/WMS/readyforemail/tile_3_1.jpeg b/WMS/readyforemail/tile_3_1.jpeg deleted file mode 100644 index bc8d2bf..0000000 Binary files a/WMS/readyforemail/tile_3_1.jpeg and /dev/null differ diff --git a/WMS/readyforemail/tile_3_2.jpeg b/WMS/readyforemail/tile_3_2.jpeg deleted file mode 100644 index 855e19d..0000000 Binary files a/WMS/readyforemail/tile_3_2.jpeg and /dev/null differ diff --git a/WMS/resources/config.json b/WMS/resources/config.json index 5329e30..8b1d465 100644 --- a/WMS/resources/config.json +++ b/WMS/resources/config.json @@ -1 +1 @@ -{"Config": {"data_parameters": ["60", "40", "5"], "layers": ["Bygning", "Veg", "Bru"], "colors": ["#000000", "#ffff00", "#00ff00"]}} \ No newline at end of file +{"Config": {"data_parameters": ["90", "10", "10"], "layers": ["Bygning", "Veg", "Bru"], "colors": ["#000000", "#ffff00", "#00ff00"]}} \ No newline at end of file diff --git a/WMS/resources/coordinates.json b/WMS/resources/coordinates.json index 7e42e62..eff35b1 100644 --- a/WMS/resources/coordinates.json +++ b/WMS/resources/coordinates.json @@ -1 +1 @@ -{"Coordinates": [[588751.5420105711, 6642899.275265058], [588749.8344259012, 6642970.498298281], [589238.8910459754, 6642982.255880976], [589240.6080427505, 6642911.032997987], [588751.5420105711, 6642899.275265058]]} \ No newline at end of file +{"Coordinates": [[586077.6407936335, 6646104.917552568], [586025.9038943398, 6648327.088944961], [588710.10992247, 6648390.564976909], [588763.4615420719, 6646168.418973851], [586077.6407936335, 6646104.917552568]]} \ No newline at end of file diff --git a/__pycache__/deleteFolder.cpython-311.pyc b/__pycache__/deleteFolder.cpython-311.pyc index 24091c5..222bd6e 100644 Binary files a/__pycache__/deleteFolder.cpython-311.pyc and b/__pycache__/deleteFolder.cpython-311.pyc differ diff --git a/__pycache__/main.cpython-311.pyc b/__pycache__/main.cpython-311.pyc index 9c96478..4ef9196 100644 Binary files a/__pycache__/main.cpython-311.pyc and b/__pycache__/main.cpython-311.pyc differ diff --git a/frontend/pages/setConstraints.html b/frontend/pages/setConstraints.html index f76b1c8..b01efb5 100644 --- a/frontend/pages/setConstraints.html +++ b/frontend/pages/setConstraints.html @@ -92,9 +92,13 @@