MCPcopy Create free account
hub / github.com/Topdu/OpenOCR / apply

Method apply

openrec/preprocess/cmer_label_encode.py:102–125  ·  view source on GitHub ↗
(self, img, **params)

Source from the content-addressed store, hash-verified

100 self.mag = mag
101
102 def apply(self, img, **params):
103 img = Image.fromarray(img.astype(np.uint8))
104 w, h = img.size
105 c = [(1.5, 2), (2., 2), (2.5, 1.7)]
106 if self.mag < 0 or self.mag >= len(c):
107 index = self.rng.integers(0, len(c))
108 else:
109 index = self.mag
110 c = c[index]
111 n_channels = len(img.getbands())
112 isgray = n_channels == 1
113 img = np.asarray(img) / 255.
114 max_val = img.max()
115 max_size = 2**math.ceil(math.log2(max(w, h)) + 1)
116 fog = c[0] * plasma_fractal(mapsize=max_size,
117 wibbledecay=c[1],
118 rng=self.rng)[:h, :w][..., np.newaxis]
119 if isgray:
120 fog = np.squeeze(fog)
121 else:
122 fog = np.repeat(fog, 3, axis=2)
123 img += fog
124 img = np.clip(img * max_val / (max_val + c[0]), 0, 1) * 255
125 return img.astype(np.uint8)
126
127 class Frost(A.ImageOnlyTransform):
128

Callers 15

__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45

Calls 1

plasma_fractalFunction · 0.85

Tested by

no test coverage detected