Harzis commited on
Commit
ce2c6e6
·
verified ·
1 Parent(s): ec2f2e2

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. remove_background.py +14 -11
remove_background.py CHANGED
@@ -7,16 +7,19 @@ output_folder = 'Output_images' # Folder where images without background will b
7
 
8
  os.makedirs(output_folder, exist_ok=True)
9
 
10
- for filename in os.listdir(input_folder):
11
- if filename.lower().endswith(('.png', '.jpg', '.jpeg')):
12
- input_path = os.path.join(input_folder, filename)
13
- output_path = os.path.join(output_folder, filename)
14
-
15
- with open(input_path, 'rb') as i:
16
- input_data = i.read()
17
- output_data = remove(input_data)
18
 
19
- with open(output_path, 'wb') as o:
20
- o.write(output_data)
 
 
 
 
 
 
21
 
22
- print(f'Processed images saved to {output_folder}')
 
 
 
 
7
 
8
  os.makedirs(output_folder, exist_ok=True)
9
 
10
+ image_files = [f for f in os.listdir(input_folder) if f.lower().endswith(('.png', '.jpg', '.jpeg'))]
11
+ total_images = len(image_files)
 
 
 
 
 
 
12
 
13
+ for index, filename in enumerate(image_files):
14
+ print(f"Processing image {index + 1}/{total_images}: {filename}")
15
+ input_path = os.path.join(input_folder, filename)
16
+ output_path = os.path.join(output_folder, filename)
17
+
18
+ with open(input_path, 'rb') as i:
19
+ input_data = i.read()
20
+ output_data = remove(input_data)
21
 
22
+ with open(output_path, 'wb') as o:
23
+ o.write(output_data)
24
+
25
+ print(f'\nAll {total_images} images processed and saved to {output_folder}')