-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchannelsplit.py
More file actions
25 lines (20 loc) · 880 Bytes
/
channelsplit.py
File metadata and controls
25 lines (20 loc) · 880 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
import cv2
#import numpy as np
import os
def splitchannel(image, count):
img = cv2.imread(image)
b, g, r = cv2.split(img)
# Specify filename for each channel e.g. blue: b_00001.jpg
b_file = "b_" + str(count) + ".jpg"
g_file = "g_" + str(count) + ".jpg"
r_file = "r_" + str(count) + ".jpg"
# Folder Directory
exportspath = os.path.join(os.path.dirname(__file__), "exports")
b_export_dir = os.path.join(exportspath, "blue_channel")
g_export_dir = os.path.join(exportspath, "green_channel")
r_export_dir = os.path.join(exportspath, "red_channel")
# Write processed images
# Todo use os.makedirs(path, exist_ok=true) to premade folder in case there is no folder
cv2.imwrite(os.path.join(b_export_dir, b_file), b)
cv2.imwrite(os.path.join(g_export_dir, g_file), g)
cv2.imwrite(os.path.join(r_export_dir, r_file), r)