MCPcopy Create free account
hub / github.com/buaacxf/VIPTR / warp

Function warp

dataload/dataAug.py:317–370  ·  view source on GitHub ↗

warp

(img, use_tia=True, prob=0.4, angz=2)

Source from the content-addressed store, hash-verified

315
316
317def warp(img, use_tia=True, prob=0.4, angz=2):
318 """
319 warp
320 """
321 h, w, _ = img.shape
322 config = Config(use_tia=use_tia)
323 config.make(w, h, angz)
324 new_img = img
325
326 if config.distort:
327 img_height, img_width = img.shape[0:2]
328 if random.random() <= (prob - 0.1) and img_height >= 32 and img_width >= 32:
329 new_img = tia_distort(new_img, 10)
330
331 if config.stretch:
332 img_height, img_width = img.shape[0:2]
333 if random.random() <= prob and img_height >= 32 and img_width >= 32:
334 new_img = tia_stretch(new_img, 10)
335
336 if config.perspective:
337 if random.random() <= prob:
338 new_img = tia_perspective(new_img)
339
340 if config.crop:
341 img_height, img_width = img.shape[0:2]
342 if random.random() <= prob and img_height >= 32 and img_width >= 32:
343 new_img = get_crop(new_img)
344
345 if config.blur:
346 bprob = prob / 3.
347 if random.random() <= bprob:
348 new_img = blur(new_img)
349 elif random.random() > bprob and random.random() <= 2 * bprob:
350 new_img = resizeAug(new_img)
351 elif random.random() > 2 * bprob and random.random() <= 3 * bprob:
352 new_img = motion_blur(new_img)
353
354 if config.random_dilute:
355 if random.random() <= prob:
356 new_img = random_dilute(new_img)
357
358 if config.color:
359 if random.random() <= prob:
360 new_img = cvtColor(new_img)
361 if config.jitter:
362 new_img = jitter(new_img)
363 if config.noise:
364 if random.random() <= prob:
365 new_img = add_gasuss_noise(new_img)
366 if config.reverse:
367 if random.random() <= prob:
368 new_img = 255 - new_img
369
370 return new_img
371

Callers 1

__call__Method · 0.85

Calls 13

makeMethod · 0.95
tia_distortFunction · 0.90
tia_stretchFunction · 0.90
tia_perspectiveFunction · 0.90
ConfigClass · 0.85
get_cropFunction · 0.85
blurFunction · 0.85
resizeAugFunction · 0.85
motion_blurFunction · 0.85
random_diluteFunction · 0.85
cvtColorFunction · 0.85
jitterFunction · 0.85

Tested by

no test coverage detected