mirror of
https://github.com/iperov/DeepFaceLab.git
synced 2025-08-19 21:13:20 -07:00
imagelib : apply_random_sharpen
This commit is contained in:
parent
7a08c0c1d3
commit
dcf146cc16
2 changed files with 47 additions and 28 deletions
|
@ -22,6 +22,7 @@ from .blursharpen import LinearMotionBlur, blursharpen
|
|||
|
||||
from .filters import apply_random_rgb_levels, \
|
||||
apply_random_hsv_shift, \
|
||||
apply_random_sharpen, \
|
||||
apply_random_motion_blur, \
|
||||
apply_random_gaussian_blur, \
|
||||
apply_random_nearest_resize, \
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import numpy as np
|
||||
from .blursharpen import LinearMotionBlur
|
||||
from .blursharpen import LinearMotionBlur, blursharpen
|
||||
import cv2
|
||||
|
||||
def apply_random_rgb_levels(img, mask=None, rnd_state=None):
|
||||
|
@ -38,6 +38,24 @@ def apply_random_hsv_shift(img, mask=None, rnd_state=None):
|
|||
|
||||
return result
|
||||
|
||||
def apply_random_sharpen( img, chance, kernel_max_size, mask=None, rnd_state=None ):
|
||||
if rnd_state is None:
|
||||
rnd_state = np.random
|
||||
|
||||
sharp_rnd_kernel = rnd_state.randint(kernel_max_size)+1
|
||||
|
||||
result = img
|
||||
if rnd_state.randint(100) < np.clip(chance, 0, 100):
|
||||
if rnd_state.randint(2) == 0:
|
||||
result = blursharpen(result, 1, sharp_rnd_kernel, rnd_state.randint(10) )
|
||||
else:
|
||||
result = blursharpen(result, 2, sharp_rnd_kernel, rnd_state.randint(50) )
|
||||
|
||||
if mask is not None:
|
||||
result = img*(1-mask) + result*mask
|
||||
|
||||
return result
|
||||
|
||||
def apply_random_motion_blur( img, chance, mb_max_size, mask=None, rnd_state=None ):
|
||||
if rnd_state is None:
|
||||
rnd_state = np.random
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue