k4d3 commited on
Commit
088eb78
1 Parent(s): 5ce54ff

some changes

Browse files

Signed-off-by: Balazs Horvath <acsipont@gmail.com>

Files changed (4) hide show
  1. .gitmodules +1 -1
  2. dataset-tools +1 -1
  3. utils/crc32.py +18 -0
  4. utils/remove_letterbox.py +42 -0
.gitmodules CHANGED
@@ -1,3 +1,3 @@
1
  [submodule "dataset-tools"]
2
  path = dataset-tools
3
- url = https://github.com/ka-de/dataset-tools
 
1
  [submodule "dataset-tools"]
2
  path = dataset-tools
3
+ url = git@github.com:ka-de/dataset-tools
dataset-tools CHANGED
@@ -1 +1 @@
1
- Subproject commit 0af984140656aa40d830d3317fc6c00ac0fc9ba3
 
1
+ Subproject commit a8c787494826e9ae2d1e386be8ce304eafb3a0e6
utils/crc32.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import zlib
2
+ import sys
3
+
4
+ def calculate_crc32(file_path):
5
+ with open(file_path, 'rb') as file:
6
+ data = file.read()
7
+ crc32_checksum = zlib.crc32(data)
8
+ return crc32_checksum
9
+
10
+ if __name__ == "__main__":
11
+ if len(sys.argv) != 2:
12
+ print("Usage: python script.py <file_path>")
13
+ sys.exit(1)
14
+
15
+ file_path = sys.argv[1]
16
+ checksum = calculate_crc32(file_path)
17
+ print(f"CRC32 checksum of {file_path}: {checksum:#010x}")
18
+
utils/remove_letterbox.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import sys
3
+ from PIL import Image, ImageChops
4
+ import pillow_jxl
5
+
6
+ def remove_letterbox(image_path):
7
+ with Image.open(image_path) as img:
8
+ # Convert image to RGB if it's not already
9
+ img = img.convert("RGB")
10
+ # Create a black image of the same size
11
+ black = Image.new("RGB", img.size, (0, 0, 0))
12
+ # Find the bounding box of the non-black regions
13
+ diff = ImageChops.difference(img, black)
14
+ bbox = diff.getbbox()
15
+ if bbox:
16
+ # Crop the image to the bounding box
17
+ img = img.crop(bbox)
18
+ img.save(image_path)
19
+ print(f"Processed: {image_path}")
20
+ else:
21
+ print(f"No letterboxing found in: {image_path}")
22
+
23
+ def process_directory(directory):
24
+ for root, _, files in os.walk(directory):
25
+ for file in files:
26
+ if file.lower().endswith(('.png', '.jpg', '.jpeg', '.jxl')):
27
+ remove_letterbox(os.path.join(root, file))
28
+
29
+ if __name__ == "__main__":
30
+ if len(sys.argv) < 2:
31
+ print("Usage: python remove_letterbox.py <image_or_directory>")
32
+ sys.exit(1)
33
+
34
+ target_path = sys.argv[1]
35
+ if os.path.isdir(target_path):
36
+ process_directory(target_path)
37
+ elif os.path.isfile(target_path):
38
+ remove_letterbox(target_path)
39
+ else:
40
+ print(f"Invalid path: {target_path}")
41
+ sys.exit(1)
42
+