Skip to content

Commit

Permalink
idx creation improved
Browse files Browse the repository at this point in the history
  • Loading branch information
Keim, Stefan committed Jun 18, 2021
1 parent 74b5688 commit 564fd50
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 28 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,5 @@ MANIFEST
docs
htmlcov
tests/in
tests/out
tests/out
src/kubi/kubi_.py
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
Changelog
=========

Version 0.1.2
===========

- performance of idx creation improved
- Basic tests passed (97% coverage | 194run | 0 missing | 4 excluded | 8 partial)

Version 0.1.1
===========

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ Marzipano.ImageUrlSource.fromString("<some_path>/dstfile_{f}/{z}/{y}/{x}.jpg");

| face size | 1024px | 2048px | 4096px |
| ---| --- | --- | --- |
| kubi | 0.9s | 1.7s | 4.9s |
| [py360convert](https://pypi.org/project/py360convert/) | 2.5s | 8.7s | 33.0s |
| kubi | 0.9s | 1.6s | 4.7s |
| [py360convert](https://pypi.org/project/py360convert/) | 2.6s | 8.6s | 32.2s |
| *any others ?* | - | - | - |

### single input file - tiled output
Expand All @@ -77,8 +77,8 @@ Marzipano.ImageUrlSource.fromString("<some_path>/dstfile_{f}/{z}/{y}/{x}.jpg");

| face size | 1024px | 2048px | 4096px |
| ---| --- | --- | --- |
| kubi | 0.9s | 1.4s | 3.5s |
| [panorama_windows.exe](https://github.com/blackironj/panorama) | 1.4s | 4.4s | 16.8s |
| kubi | 0.9s | 1.3s | 3.1s |
| [panorama_windows.exe](https://github.com/blackironj/panorama) | 1.5s | 4.7s | 16.9s |
| *any others ?* | - | - | - |

### multiple input files
Expand Down
46 changes: 23 additions & 23 deletions src/kubi/kubi.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
# `from kubi.kubi import kubi`,
# when using this Python module as a library.


def kubi(args):

if IsWin:
Expand Down Expand Up @@ -70,32 +69,33 @@ def kubi(args):
elif args.transform == "otc": # M.Zucker & Y.Higashi (2018): Cube-to-sphere Projections for Procedural Texturing and Beyond
ls = np.tan(ls * 0.8687) / np.tan(0.8687)

xv,yv = np.meshgrid(ls, ls)

xv2 = xv ** 2
yv2 = yv ** 2

idx = np.stack([
np.arctan(xv), #tha0
np.arctan2(yv, np.sqrt(1 + xv2)), #phi0
np.arctan2(xv, yv), #tha1
np.arctan2(1, np.sqrt(yv2 + xv2)) #phi1
], axis=-1)

### end of numpy
xv,yv = np.meshgrid(ls, ls, copy=False)

ls = xv = yv = xv2 = yv2 = None

idx = pyvips.Image.new_from_memory(idx.reshape(size**2 * 4), size, size, 4, 'float') / (pi/2)
x0 = np.arctan(xv)
y0 = np.arctan2(yv, np.hypot(1,xv))
x1 = np.arctan2(xv, yv)
y1 = np.arctan(np.hypot(yv,xv))

ls = xv = yv = None

piot = pi/2

x0 = pyvips.Image.new_from_memory(x0.ravel(), size, size, 1, 'float') / piot
y0 = pyvips.Image.new_from_memory(y0.ravel(), size, size, 1, 'float') / piot
x1 = pyvips.Image.new_from_memory(x1.ravel(), size, size, 1, 'float') / piot
y1 = pyvips.Image.new_from_memory(y1.ravel(), size, size, 1, 'float') / piot

### end of numpy

idx = [
pyvips.Image.bandjoin(idx[0]+3,idx[1]+1),
pyvips.Image.bandjoin(idx[0]+1,idx[1]+1),
pyvips.Image.bandjoin((idx[2]-2)%4,1-idx[3]),
pyvips.Image.bandjoin((4-idx[2])%4,1+idx[3]),
pyvips.Image.bandjoin(idx[0]+2,idx[1]+1),
pyvips.Image.bandjoin(idx[0]%4,idx[1]+1),
pyvips.Image.bandjoin(x0+3,y0+1),
pyvips.Image.bandjoin(x0+1,y0+1),
pyvips.Image.bandjoin((x1-2)%4,y1),
pyvips.Image.bandjoin((4-x1)%4,2-y1),
pyvips.Image.bandjoin(x0+2,y0+1),
pyvips.Image.bandjoin(x0%4,y0+1),
]


if args.layout is None or args.layout in ("column","row"):
if args.inverse is not None:
Expand Down

0 comments on commit 564fd50

Please sign in to comment.