This commit is contained in:
Colombo 2020-03-20 11:37:42 +04:00
parent 4c24f9d41c
commit 3fa93da5e7
3 changed files with 23 additions and 2 deletions

View file

@ -30,7 +30,7 @@ def apply_random_hsv_shift(img, mask=None, rnd_state=None):
h, s, v = cv2.split(cv2.cvtColor(img, cv2.COLOR_BGR2HSV))
h = ( h + rnd_state.randint(360) ) % 360
s = np.clip ( s + rnd_state.random()-0.5, 0, 1 )
v = np.clip ( v + rnd_state.random()/2-0.25, 0, 1 )
v = np.clip ( v + rnd_state.random()-0.5, 0, 1 )
result = np.clip( cv2.cvtColor(cv2.merge([h, s, v]), cv2.COLOR_HSV2BGR) , 0, 1 )
if mask is not None:

View file

@ -1 +1,2 @@
from .draw import *
from .calc import *

20
core/imagelib/sd/calc.py Normal file
View file

@ -0,0 +1,20 @@
import numpy as np
import numpy.linalg as npla
def dist_to_edges(pts, p):
a = pts[:-1,:]
b = pts[1:,:]
edges = np.concatenate( ( pts[:-1,None,:], pts[1:,None,:] ), axis=-2)
pa = p-a
ba = b-a
h = np.clip( np.einsum('ij,ij->i', pa, ba) / np.einsum('ij,ij->i', ba, ba), 0, 1 )
return npla.norm ( pa - ba*h[...,None], axis=1 )
def nearest_edge_id_and_dist(pts, p):
x = dist_to_edges(pts, p)
if len(x) != 0:
return np.argmin(x), np.min(x)
return None, None