nguyenp99 commited on
Commit
66655aa
1 Parent(s): d3b88f5

Create preprocesses.py

Browse files
Files changed (1) hide show
  1. preprocesses.py +37 -0
preprocesses.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cv2
2
+ import numpy as np
3
+ import plasma.functional as f
4
+ import albumentations as alb
5
+
6
+
7
+ class Preprocessor(f.SequentialPipe):
8
+
9
+ def __init__(self, width, interpolation):
10
+ super().__init__()
11
+
12
+ self.resize = WidthReisze(width, interpolation)
13
+ # self.to_gray = ToGray()
14
+
15
+
16
+ class WidthReisze(f.Pipe):
17
+
18
+ def __init__(self, width, interpolation):
19
+ super().__init__(width=width, interpolation=interpolation)
20
+
21
+ def run(self, img):
22
+ w = self.width
23
+ resized_img = cv2.resize(img, (w, int(w / img.shape[1] * img.shape[0])), interpolation=self.interpolation)
24
+ return resized_img
25
+
26
+
27
+ class ToGray(f.Pipe):
28
+
29
+ def __init__(self):
30
+ super().__init__()
31
+
32
+ def run(self, img):
33
+ if len(img.shape) == 3:
34
+ img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
35
+
36
+ img = cv2.cvtColor(img, cv2.COLOR_GRAY2RGB)
37
+ return img