Пример #1
0
from src.utils.snake import init_rect
import numpy as np

x = np.arange(10, 100, 10)
lineh = [[[x[i], x[i]], [x[i+1], x[i+1]]] for i in range( x.shape[0] - 1)]
x = np.arange(10, 50, 5)
linev = [[[x[i], x[i]], [x[i+1], x[i+1]]] for i in range( x.shape[0] - 1)]

x, y = init_rect(200, 100, lineh, linev)
Пример #2
0
from src.utils.hough import hough_horizontal, hough_vertical
from src.utils.canny import my_canny
from src.utils.preprocessing import normalize
box = boxes[2]
window = arr[box[1]+5: box[3]-5, box[0]+5: box[2]-5] # to eliminate the edge scenario
width = window.shape[1]
height = window.shape[0]
window = normalize(window)
ret = my_canny(window, sigma=0.0, save=False, show=DEBUG)
raw = Image.fromarray(np.zeros((height, width)))
lineh, raw = hough_horizontal(ret, hough_line_len=30,line_gap=50, save=False, show=True, raw=raw)
linev, raw = hough_vertical(ret,hough_line_len=30,line_gap=50, save=False, show=True, raw=raw )
raw.show()
f = np.array(raw.convert('L').getdata()).reshape(height, width)/255.

from src.utils.canny import decide_sigma
decide_sigma(f, area=width*height)

from src.utils.GVF import GVF, normalize_GVF_external_force
u, v = GVF(f, 0.2, 80)
px,py = normalize_GVF_external_force(u, v)
from src.utils.io import show_vector
line, plt = show_vector(px, 0-py, skip=6, holdon=True)
from src.utils.snake import snake_disp
from src.utils.snake import init_rect
x, y = init_rect(px.shape[0], px.shape[1])
snake_disp(line, plt, x, y)
from src.utils.snake import snake_deformation
snake_deformation(x, y, px, py, 30, show=True, line=line, plt=plt)
plt.show()