|
31 | 31 | # `from kubi.kubi import kubi`, |
32 | 32 | # when using this Python module as a library. |
33 | 33 |
|
34 | | - |
35 | 34 | def kubi(args): |
36 | 35 |
|
37 | 36 | if IsWin: |
@@ -70,32 +69,33 @@ def kubi(args): |
70 | 69 | elif args.transform == "otc": # M.Zucker & Y.Higashi (2018): Cube-to-sphere Projections for Procedural Texturing and Beyond |
71 | 70 | ls = np.tan(ls * 0.8687) / np.tan(0.8687) |
72 | 71 |
|
73 | | - xv,yv = np.meshgrid(ls, ls) |
74 | | - |
75 | | - xv2 = xv ** 2 |
76 | | - yv2 = yv ** 2 |
77 | | - |
78 | | - idx = np.stack([ |
79 | | - np.arctan(xv), #tha0 |
80 | | - np.arctan2(yv, np.sqrt(1 + xv2)), #phi0 |
81 | | - np.arctan2(xv, yv), #tha1 |
82 | | - np.arctan2(1, np.sqrt(yv2 + xv2)) #phi1 |
83 | | - ], axis=-1) |
84 | | - |
85 | | - ### end of numpy |
| 72 | + xv,yv = np.meshgrid(ls, ls, copy=False) |
86 | 73 |
|
87 | | - ls = xv = yv = xv2 = yv2 = None |
88 | | - |
89 | | - idx = pyvips.Image.new_from_memory(idx.reshape(size**2 * 4), size, size, 4, 'float') / (pi/2) |
| 74 | + x0 = np.arctan(xv) |
| 75 | + y0 = np.arctan2(yv, np.hypot(1,xv)) |
| 76 | + x1 = np.arctan2(xv, yv) |
| 77 | + y1 = np.arctan(np.hypot(yv,xv)) |
| 78 | + |
| 79 | + ls = xv = yv = None |
| 80 | + |
| 81 | + piot = pi/2 |
| 82 | + |
| 83 | + x0 = pyvips.Image.new_from_memory(x0.ravel(), size, size, 1, 'float') / piot |
| 84 | + y0 = pyvips.Image.new_from_memory(y0.ravel(), size, size, 1, 'float') / piot |
| 85 | + x1 = pyvips.Image.new_from_memory(x1.ravel(), size, size, 1, 'float') / piot |
| 86 | + y1 = pyvips.Image.new_from_memory(y1.ravel(), size, size, 1, 'float') / piot |
| 87 | + |
| 88 | + ### end of numpy |
90 | 89 |
|
91 | 90 | idx = [ |
92 | | - pyvips.Image.bandjoin(idx[0]+3,idx[1]+1), |
93 | | - pyvips.Image.bandjoin(idx[0]+1,idx[1]+1), |
94 | | - pyvips.Image.bandjoin((idx[2]-2)%4,1-idx[3]), |
95 | | - pyvips.Image.bandjoin((4-idx[2])%4,1+idx[3]), |
96 | | - pyvips.Image.bandjoin(idx[0]+2,idx[1]+1), |
97 | | - pyvips.Image.bandjoin(idx[0]%4,idx[1]+1), |
| 91 | + pyvips.Image.bandjoin(x0+3,y0+1), |
| 92 | + pyvips.Image.bandjoin(x0+1,y0+1), |
| 93 | + pyvips.Image.bandjoin((x1-2)%4,y1), |
| 94 | + pyvips.Image.bandjoin((4-x1)%4,2-y1), |
| 95 | + pyvips.Image.bandjoin(x0+2,y0+1), |
| 96 | + pyvips.Image.bandjoin(x0%4,y0+1), |
98 | 97 | ] |
| 98 | + |
99 | 99 |
|
100 | 100 | if args.layout is None or args.layout in ("column","row"): |
101 | 101 | if args.inverse is not None: |
|
0 commit comments