-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinvert_images.py
More file actions
41 lines (28 loc) · 931 Bytes
/
invert_images.py
File metadata and controls
41 lines (28 loc) · 931 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# -*- coding: utf-8 -*-
"""
Created on Thu Oct 7 02:39:19 2021
@author: Ibrah
"""
import os
from glob import glob
import cv2
# Constants
INPUT_DIR = "your_input_dir"
OUTPUT_DIR = "your_output_dir"
def main():
"""Main : loop through a folder then proceeds to invert all its images"""
# Get the file list
files = glob(INPUT_DIR + "/*")
print(f"Files count: {len(files)}")
# Loop through the files list
for file in files:
# Get the basename (filename)
file_name = os.path.basename(file)
print(f"Image: {file_name}")
# Read the file and invert the image
image = cv2.imread(file)
image_inverted = cv2.bitwise_not(image)
# Save the results
cv2.imwrite(OUTPUT_DIR + file_name + "_inverted.png", image_inverted)
if __name__ == "__main__":
main()