Commit 4e0db0cda2d9597119f2bb15ab5538130bf4e3be

Authored by David Mayerich
1 parent 6e774c03

added imagestack source code

Showing 1 changed file with 40 additions and 0 deletions   Show diff stats
python/imagestack.py 0 → 100644
  1 +import glob
  2 +import imageio
  3 +import numpy
  4 +import progressbar
  5 +
  6 +def loadstack(fmask, dtype=numpy.float32):
  7 + #read the input files
  8 + F = glob.glob(fmask)
  9 + if(len(F)==0):
  10 + print("No image files found.")
  11 + return
  12 +
  13 + #load the first file
  14 + I = imageio.imread(F[0])
  15 +
  16 + #generate the image stack
  17 + S = numpy.zeros((len(F), I.shape[0], I.shape[1], I.shape[2]), dtype)
  18 +
  19 + bar = progressbar.ProgressBar(max_value=len(F))
  20 +
  21 + for i in range(0, len(F)):
  22 + I = imageio.imread(F[i])
  23 + S[i, :, :, :] = I
  24 + bar.update(i+1)
  25 +
  26 + return S
  27 +
  28 +def rgb2gray(rgb):
  29 + r, g, b = rgb[...,0], rgb[...,1], rgb[...,2]
  30 + gray = 0.2989 * r + 0.5870 * g + 0.1140 * b
  31 +
  32 + return gray
  33 +
  34 +def savestack(I, fname, extension = ".bmp"):
  35 + #output the final images
  36 + bar = progressbar.ProgressBar(max_value=I.shape[0])
  37 + #save the output files
  38 + for i in range(0, I.shape[0]):
  39 + imageio.imwrite(fname + "%03d" % i + extension, I[i, :, :, :])
  40 + bar.update(i+1)
0 41 \ No newline at end of file
... ...