forked from Moo64c/GaborFilter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutility.py
More file actions
38 lines (35 loc) · 1.13 KB
/
utility.py
File metadata and controls
38 lines (35 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import json
import Image
import matlab.engine
import numpy as np
# This function runs on all the paths we created in the web application.
# Basically every path becomes a rectangle which we"ll pass to the grab cut
# function.
# We later add up each grab cut to a final picture.
# @return array of rectangles in the format: x, y, width, height
def extractFromPaths(data, img):
# Results stored in an array.
shape = img.shape
height = shape[0]
width = shape[1]
tmp = [[],[]]
fore = np.array([])
back = np.array([])
for path in data["fore"]:
for i in range(0, len(path)):
X = path[i]["cor"]["x"];
Y = path[i]["cor"]["y"];
# Minimum values, otherwise we crash!
tmp[0].append(int(X*height+Y))
for path in data["back"]:
for i in range(0, len(path)):
X = path[i]["cor"]["x"];
Y = path[i]["cor"]["y"];
# Minimum values, otherwise we crash!
tmp[1].append(int(X*height+Y))
fore = matlab.int32(tmp[0])
fore = fore[0]
back = matlab.int32(tmp[1])
back = back[0]
ans = [fore, back]
return ans;