This repository has been archived by the owner on Aug 31, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
chessfftomo_process_changes.py
133 lines (99 loc) · 4.94 KB
/
chessfftomo_process_changes.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import tifffile
import matplotlib.pyplot as plt
import os
import numpy as np
from scipy.ndimage.interpolation import shift
import tomopy
import scipy.ndimage
import skimage.measure
import cv2
def chess_fileio_proj(datapath, prefix, fnumstart, fnumend, imgsize = [2048, 2048],
print_infile = False, print_fcounter = False):
'''
load frames from datapath with prefix in order
'''
numframes = fnumend - fnumstart + 1
frames = np.zeros([numframes, imgsize[0], imgsize[1]])
for fnum in range(fnumstart, fnumend+1):
infile = os.path.join(datapath,prefix+'{0:05d}'.format(fnum)+'.tif')
if print_infile is True:
print(infile)
frames[fnum-fnumstart, :, :] = tifffile.imread(infile)
frames = np.array(frames)
print(' loaded all projects.')
return frames
def chess_proj(chess_datapath, fname, imgsize = [664, 590]):
'''
Load image stacking
'''
image_files = chess_datapath # Your list of files
image_height = imgsize[0]
image_width = imgsize[1]
image_stack = np.empty((image_height, image_width, 1441)) # Create empty HxWxN array/matrix
for i, fname in enumerate(image_files):
#img = cv2.imread(fname, cv2.CV_LOAD_IMAGE_GRAYSCALE)
img = cv2.imread(fname, cv2.IMREAD_GRAYSCALE)
image_stack[:,:,i] = img # Set the i:th slice to this image
proj = image_stack
return proj
def srxfftomo_findcenter(corrected_proj_tiff = None, proj = None,
save_find_center = True, autocheck = False,
check_cen_range_step = [390, 410, 1],
auto_selecslice = True, cen_slice = 400,
outpath = None, samplename = None):
'''
input needs to be either
1) corrected_proj_tiff, provided as a file path and name,
e.g. '/home/xf05id1/localdata/TomoCommissioning/testsample_01/testsample_01_corrected.tiff'
it is a stack of tiff generated by srxfftomo_correction, where background and stage round out have been corrected
2) projection numpy array, returned from srxfftomo_correction
The 'proj' array assignment has priority. If it is None, proj was be read from corrected_proj_tiff
input example:
check_cen_range_step = [390, 410, 1]
cen_slice = 400
return:
proj (numpy array, float), with negative natural log has been taken
'''
if proj is None:
print('proj is not asigned, load corrected projection from:', corrected_proj_tiff)
proj = tifffile.imread(chess_proj)
else:
print('proj array is not None, use it as is')
if save_find_center is True:
center_check_path = outpath +'/' + samplename + '/center_check/'
print('saving find center value into ' + center_check_path)
theta = tomopy.angles(proj.shape[0])
if autocheck is True:
check_cen_range_step = [int(proj.shape[2]/2)-50, int(proj.shape[2])/2+50, 5]
if auto_selecslice is True:
cen_slice = int(proj.shape[1]/2)
tomopy.write_center(proj, theta,
center_check_path, cen_range = check_cen_range_step, ind = cen_slice, mask = True)
return proj
#
def srxfftomo_recon(corrected_proj_tiff = None, proj = None,
rot_center = None, recon_algorithm = 'art', recon_section = None,
outpath = None, recon_outpath = 'recon', samplename = None):
'''
input needs to be either
1) corrected_proj_tiff, provided as a file path and name,
e.g. '/home/xf05id1/localdata/TomoCommissioning/testsample_01/testsample_01_corrected.tiff'
it is a stack of tiff generated by srxfftomo_correction, where background and stage round out have been corrected
2) projection numpy array, returned from srxfftomo_correction
The 'proj' array assignment has priority. If it is None, proj was be read from corrected_proj_tiff
recon_section is a list of upper and lower bounds for y range, e.g. [380, 420]
'''
if proj is None:
print('proj is not asigned, load corrected projection from:', chess_proj)
proj = tifffile.imread(chess_proj)
else:
print('proj array is not None, use it as is')
print('running reconstruction')
if recon_section is not None:
proj = proj [:, recon_section[0]:recon_section[1], :]
theta = tomopy.angles(proj.shape[0])
rec = tomopy.recon(proj, theta, center=rot_center, algorithm= recon_algorithm)
print('saving reconstruction into')
recon_outfile = outpath +'/' + samplename + '/' + recon_outpath +'/' + samplename + '_recon'
tomopy.write_tiff_stack(rec, fname=recon_outfile)
return rec