forked from adamltyson/Python_tools
-
Notifications
You must be signed in to change notification settings - Fork 1
/
iSPIM_deskew.py
61 lines (43 loc) · 1.49 KB
/
iSPIM_deskew.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# -*- coding: utf-8 -*-
"""
Macro to deskew MLS stage scans.
Adam Tyson | adam.tyson@icr.ac.uk | 2018-05-24
Adapted from ImageJ macro by Min Guo & Hari Shroff (2016)
http://dispim.org/software/imagej_macro
Define deskew parameters, and choose directory containing skewed images (.tif)
All images in the directory will be deskewed, and saved to /deskew
"""
import os
from skimage import io
from datetime import datetime
from fun.deskew import chooseDir, deskew, IJ_save
startTime = datetime.now()
chooseDir()
class var:
save = True
direc = 'Left2Right' # or 'Right2Left'
stepType = 'Z_spacing' # or 'StageDistance'
interval = 0.8
pixelsize = 0.1625
if var.stepType is 'StageDistance':
shiftStep = var.interval/1.414/var.pixelsize
else:
shiftStep = var.interval/var.pixelsize
allFiles = os.listdir('.')
for file in allFiles:
if file.endswith(".tif"):
prefix = file.rsplit('.')[0] # remove .tif
fileout = prefix + '_deskew.tif'
# Only run if not deskewed allready
if not os.path.isfile(fileout):
print('Loading image: ', file)
# 'pil' option prevents attempt to
# load of all original timepoints in ome-tiff
img = io.imread(file, plugin='pil')
deskewed = deskew(img, var.direc, shiftStep)
if var.save:
IJ_save(deskewed, fileout)
else:
print('Image already deskewed')
print('Done!')
print('Total time taken: ', datetime.now() - startTime)