In [1]:
%matplotlib inline

from microscopestitching import ImageCollection, stitch, calc_translations_parallel
from skimage.io import imsave, imshow

def img_tuple(img):
    row = int(img[1])
    col = int(img[4])
    return img, row, col

files = !ls r*png
# list of (path, row, column)
images = [img_tuple(f) for f in files]
ic = ImageCollection(images)
ic


Out[1]:
ImageCollection(
  Image("r0-c0.png", row=0, col=0),
  Image("r0-c1.png", row=0, col=1),
  Image("r0-c2.png", row=0, col=2),
  Image("r1-c0.png", row=1, col=0),
  Image("r1-c1.png", row=1, col=1),
  Image("r1-c2.png", row=1, col=2),
  Image("r2-c0.png", row=2, col=0),
  Image("r2-c1.png", row=2, col=1),
  Image("r2-c2.png", row=2, col=2),
  Image("r3-c0.png", row=3, col=0),
  Image("r3-c1.png", row=3, col=1),
  Image("r3-c2.png", row=3, col=2))

In [2]:
ic[0]


Out[2]:
Image("r0-c0.png", row=0, col=0)

In [3]:
# calc translation single core
%time tr = ic.translations # top left image excluded


CPU times: user 1.83 s, sys: 292 ms, total: 2.13 s
Wall time: 2.14 s

In [4]:
# results are cached
%time tr = ic.translations


CPU times: user 67 µs, sys: 19 µs, total: 86 µs
Wall time: 75.1 µs

In [5]:
# calc translations on all cpu cores
ic = ImageCollection(images) # prevent using cached values
%time translations = calc_translations_parallel(ic)


CPU times: user 47.1 ms, sys: 22 ms, total: 69.1 ms
Wall time: 900 ms

In [6]:
ic.median_translation()


Out[6]:
(-58.0, -58.0)