Commit 2119be83b31be62fb4ff0d32cbd5c2d019bec689
1 parent
a296b833
updated libraries for imagestack and the muve alignment script
Showing
2 changed files
with
13 additions
and
16 deletions
Show diff stats
python/imagestack.py
1 | 1 | import glob |
2 | -import imageio | |
3 | 2 | import numpy |
4 | 3 | import progressbar |
4 | +import skimage.io | |
5 | 5 | import skimage.transform |
6 | 6 | import os |
7 | 7 | |
... | ... | @@ -13,7 +13,7 @@ def load(fmask, dtype=numpy.float32): |
13 | 13 | return |
14 | 14 | |
15 | 15 | #load the first file |
16 | - I = imageio.imread(F[0]) | |
16 | + I = skimage.io.imread(F[0]) | |
17 | 17 | |
18 | 18 | #generate the image stack |
19 | 19 | if I.ndim == 3: |
... | ... | @@ -24,7 +24,7 @@ def load(fmask, dtype=numpy.float32): |
24 | 24 | bar = progressbar.ProgressBar(max_value=len(F)) |
25 | 25 | |
26 | 26 | for i in range(0, len(F)): |
27 | - I = imageio.imread(F[i]) | |
27 | + I = skimage.io.imread(F[i]) | |
28 | 28 | S[i, ...] = I |
29 | 29 | bar.update(i+1) |
30 | 30 | |
... | ... | @@ -41,7 +41,7 @@ def save(I, fname, extension = "bmp"): |
41 | 41 | bar = progressbar.ProgressBar(max_value=I.shape[0]) |
42 | 42 | #save the output files |
43 | 43 | for i in range(0, I.shape[0]): |
44 | - imageio.imwrite(fname + "%03d" % i + "." + extension, I[i, ...]) | |
44 | + skimage.io.imsave(fname + "%03d" % i + "." + extension, I[i, ...]) | |
45 | 45 | bar.update(i+1) |
46 | 46 | |
47 | 47 | #rescale a stack of images along X and Y by an integer value n and save to directory dest |
... | ... | @@ -59,12 +59,12 @@ def resize(fmask, dest, n, outformat=None): |
59 | 59 | for i in range(0, len(F)): |
60 | 60 | |
61 | 61 | #load the file to memory |
62 | - I = imageio.imread(F[i]) | |
62 | + I = skimage.io.imread(F[i]) | |
63 | 63 | R = skimage.transform.downscale_local_mean(I, (n, n)) |
64 | 64 | if outformat is None: |
65 | - imageio.imwrite(dest+"/"+os.path.basename(F[i]), R) | |
65 | + skimage.io.imwrite(dest+"/"+os.path.basename(F[i]), R) | |
66 | 66 | else: |
67 | - imageio.imwrite(dest+"/"+os.path.basename(F[i]).split('.')[0] + "." + outformat, R) | |
67 | + skimage.io.imwrite(dest+"/"+os.path.basename(F[i]).split('.')[0] + "." + outformat, R) | |
68 | 68 | bar.update(i+1) |
69 | 69 | |
70 | 70 | |
71 | 71 | \ No newline at end of file | ... | ... |
python/muve-align.py
... | ... | @@ -12,6 +12,7 @@ import cv2 |
12 | 12 | import progressbar |
13 | 13 | import scipy.ndimage |
14 | 14 | import sys |
15 | +import os | |
15 | 16 | |
16 | 17 | |
17 | 18 | def press(event): |
... | ... | @@ -95,22 +96,18 @@ def align(A, B, max_power=5): |
95 | 96 | #warp_matrix[0, 2] = 0 |
96 | 97 | # return warp_matrix |
97 | 98 | |
98 | -if len(sys.argv) < 3: | |
99 | - print("usage: muve-align input_mask output_directory") | |
100 | - print("ex: muve-align *.bmp ./aligned") | |
101 | - return | |
102 | - | |
103 | -fmask = sys.argv[1] | |
104 | -out_dir = sys.argv[2] | |
99 | +fmask = "Z:/jack/TinkParaffinLung0.005S/*.png" | |
100 | +out_dir = "Z:/jack/TinkParaffinLung0.005S/aligned" | |
105 | 101 | |
106 | 102 | if not os.path.isdir(out_dir): |
107 | 103 | os.mkdir(out_dir) |
108 | 104 | |
109 | 105 | #read the image stack for alignment |
110 | 106 | print("Loading image stack...") |
111 | -S = imagestack.load(fmask, dtype=numpy.float32) | |
107 | +S = imagestack.load(fmask, dtype=numpy.uint8) | |
108 | + | |
112 | 109 | #convert to grayscale |
113 | -G = imagestack.rgb2gray(S) | |
110 | +G = imagestack.rgb2gray(S.astype(numpy.float32)) | |
114 | 111 | |
115 | 112 | # Define the motion model |
116 | 113 | warp_mode = cv2.MOTION_TRANSLATION | ... | ... |