-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathresize.circom
79 lines (24 loc) · 1.03 KB
/
resize.circom
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
pragma circom 2.0.0;
template Resize(hOrig, wOrig, hNew, wNew) {
signal input orig[hOrig][wOrig];
signal input new[hNew][wNew];
signal output n_check;
for (var i = 0; i < hNew; i++) {
for (var j = 0; j < wNew; j++) {
var x_l = (wOrig - 1) * j / (wNew - 1);
var y_l = (hOrig - 1) * i / (hNew - 1);
var x_h = x_l * (wNew - 1) == (wOrig - 1) * j ? x_l : x_l + 1;
var y_h = y_l * (hNew - 1) == (hOrig - 1) * i ? y_l : y_l + 1;
var xRatioWeighted = ((wOrig - 1) * j) - (wNew - 1)*x_l;
var yRatioWeighted = ((hOrig - 1) * i) - (hNew - 1)*y_l;
var denom = (wNew - 1) * (hNew - 1);
var sum = orig[y_l][x_l] * (wNew - 1 - xRatioWeighted) * (hNew - 1 - yRatioWeighted)
+ orig[y_l][x_h] * xRatioWeighted * (hNew - 1 - yRatioWeighted)
+ orig[y_h][x_l] * yRatioWeighted * (wNew - 1 - xRatioWeighted)
+ orig[y_h][x_h] * xRatioWeighted * yRatioWeighted;
new[i][j] * denom === sum;
}
}
n_check <== 1;
}
component main = Resize(3, 6, 3, 2);