-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstandardization.py
72 lines (59 loc) · 2.08 KB
/
standardization.py
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# -*-coding:Latin-1 -*
# Extern packages
import numpy
import cv2
import os
from settings import segmentationSettings, classificationSettings
def load_image(path, type):
return cv2.imread(path, type)
def write_image(img, path):
if cv2.imwrite(path, img):
print("File '%s' has been created" % (path))
return True
else:
print("Error during creation of file '%s'" % (path))
return False
def resize_image(img, width, height, interpolation_type):
return cv2.resize(img, (width, height), interpolation=interpolation_type)
def segmentation_standardization(input_path):
# Create writting path
basename = os.path.basename(input_path)
[filename, extension] = os.path.splitext(basename)
writting_path = (
segmentationSettings["path"] + filename + segmentationSettings["format"]
)
# Check if file already exists or should be created
# if os.path.isfile(writting_path):
# print("File '%s' already exists" % (writting_path))
# else:
img = load_image(input_path, segmentationSettings["color"])
img = resize_image(
img,
segmentationSettings["width"],
segmentationSettings["height"],
segmentationSettings["interpolation"],
)
if write_image(img, writting_path):
return writting_path
return False
def classification_standardization(input_path):
# Create writting path
basename = os.path.basename(input_path)
[filename, extension] = os.path.splitext(basename)
writting_path = (
classificationSettings["path"] + filename + classificationSettings["format"]
)
# Check if file already exists or should be created
# if os.path.isfile(writting_path):
# print("File '%s' already exists" % (writting_path))
# else:
img = load_image(input_path, classificationSettings["color"])
img = resize_image(
img,
classificationSettings["width"],
classificationSettings["height"],
classificationSettings["interpolation"],
)
if write_image(img, writting_path):
return writting_path
return False