MCPcopy Create free account
hub / github.com/IceClear/StableSR / data_aug_np

Function data_aug_np

scripts/util_image.py:390–435  ·  view source on GitHub ↗

Performs data augmentation of the input image Input: image: a cv2 (OpenCV) image mode: int. Choice of transformation to apply to the image 0 - no transformation 1 - flip up and down 2 - rotate counterwise 90 degree

(image, mode)

Source from the content-addressed store, hash-verified

388
389# ------------------------Augmentation-----------------------------
390def data_aug_np(image, mode):
391 '''
392 Performs data augmentation of the input image
393 Input:
394 image: a cv2 (OpenCV) image
395 mode: int. Choice of transformation to apply to the image
396 0 - no transformation
397 1 - flip up and down
398 2 - rotate counterwise 90 degree
399 3 - rotate 90 degree and flip up and down
400 4 - rotate 180 degree
401 5 - rotate 180 degree and flip
402 6 - rotate 270 degree
403 7 - rotate 270 degree and flip
404 '''
405 if mode == 0:
406 # original
407 out = image
408 elif mode == 1:
409 # flip up and down
410 out = np.flipud(image)
411 elif mode == 2:
412 # rotate counterwise 90 degree
413 out = np.rot90(image)
414 elif mode == 3:
415 # rotate 90 degree and flip up and down
416 out = np.rot90(image)
417 out = np.flipud(out)
418 elif mode == 4:
419 # rotate 180 degree
420 out = np.rot90(image, k=2)
421 elif mode == 5:
422 # rotate 180 degree and flip
423 out = np.rot90(image, k=2)
424 out = np.flipud(out)
425 elif mode == 6:
426 # rotate 270 degree
427 out = np.rot90(image, k=3)
428 elif mode == 7:
429 # rotate 270 degree and flip
430 out = np.rot90(image, k=3)
431 out = np.flipud(out)
432 else:
433 raise Exception('Invalid choice of image transformation')
434
435 return out.copy()
436
437def inverse_data_aug_np(image, mode):
438 '''

Callers 1

__call__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected