Skip to content

Commit 1f7d4ce

Browse files
joelvbernierJun-Sang Park
authored andcommitted
more nf mods
1 parent c7cab72 commit 1f7d4ce

File tree

2 files changed

+107
-59
lines changed

2 files changed

+107
-59
lines changed

scripts/nf_munge.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env python2
2+
# -*- coding: utf-8 -*-
3+
"""
4+
Created on Tue Jun 19 18:43:52 2018
5+
6+
@author: s1iduser
7+
"""
8+
from skimage import io
9+
10+
# %%
11+
img_stem = 'MapZBeam_5mmTo9mm_%s__%06d.tif'
12+
13+
im_or = ['m90deg', '0deg', '90deg']
14+
im_idx = 31
15+
16+
img_list = [io.imread(img_stem % (i, im_idx)) for i in im_or]
17+
18+
# %%
19+
for i, img in enumerate(img_list):
20+
fig, ax = plt.subplots()
21+
22+
ax.imshow(img, cmap=plt.cm.inferno, vmin=np.percentile(img, 50))
23+
fig.suptitle("%s" % im_or[i])
24+
ax.axis('normal')
25+
26+
# %%
27+
x_range = [0, 2047] # eyeballed
28+
y_range = [1990, 2040] # eyeballed
29+
30+
beam_img_list = [img[np.ix_(range(*y_range), range(*x_range))] for img in img_list]
31+
32+
sinogram = np.vstack([np.sum(bimg, axis=0) for bimg in beam_img_list])
33+
34+
35+
# %%
36+
pix_size = 0.00148
37+
38+
left = pix_size*np.r_[361, 2015]
39+
right = pix_size*np.r_[1669, 2029]
40+
41+
diff = right - left
42+
incl = np.degrees(np.arctan2(diff[1], diff[0]))

scripts/process_nf_grain_map.py

Lines changed: 65 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -73,94 +73,100 @@
7373
# name of the material for the reconstruction
7474
mat_name = 'MAT_NAME'
7575

76-
#reconstruction with misorientation included, for many grains, this will quickly
77-
#make the reconstruction size unmanagable
78-
misorientation_bnd=0.0 #degrees
79-
misorientation_spacing=0.25 #degress
76+
# reconstruction with misorientation included, for many grains,
77+
# this will quickly make the reconstruction size unmanagable
78+
misorientation_bnd = 0.0 # degrees
79+
misorientation_spacing = 0.25 # degrees
8080

81-
beam_stop_width=0.55#mm, assumed to be in the center of the detector
81+
beam_stop_width = 0.55 # mm, assumed to be in the center of the detector
8282

83+
ome_range_deg = [(0., 360.), ] # degrees
8384

84-
ome_range_deg=[(0.,360.)] #degrees
85+
# maximu bragg angle 2theta in degrees
86+
# if -1, all peaks that will hit the detector are calculated
87+
max_tth = -1.
8588

89+
# image processing
90+
num_for_dark = 250 # num images to use for median data
91+
threshold = 3.
8692

87-
max_tth=-1. #degrees, if a negative number is input, all peaks that will hit the detector are calculated
93+
# !!! DO NOT CHANGE ANY OF THESE UNLESS YOU KNOW WHAT YOU ARE DOING
94+
num_erosions = 3 # num iterations of images erosion
95+
num_dilations = 2 # num iterations of images erosion
96+
ome_dilation_iter = 1 # num iterations of 3d image stack dilations
97+
chunk_size = 500 # chunksize for multiprocessing
8898

89-
#image processing
90-
num_for_dark=250#num images to use for median data
91-
threshold=3.
92-
num_erosions=3 #num iterations of images erosion, don't mess with unless you know what you're doing
93-
num_dilations=2 #num iterations of images erosion, don't mess with unless you know what you're doing
94-
ome_dilation_iter=1 #num iterations of 3d image stack dilations, don't mess with unless you know what you're doing
99+
# thresholds for accepting FF grains in NF reconstruction
100+
min_completeness = 0.5
101+
max_chisq = 0.05
95102

96-
chunk_size=500#chunksize for multiprocessing, don't mess with unless you know what you're doing
103+
# tomography options
104+
layer_row = 1024 # row of layer to use to find the specimen cross section
97105

98-
#thresholds for grains in reconstructions
99-
comp_thresh=0.5 #only use orientations from grains with completnesses ABOVE this threshold
100-
chi2_thresh=0.05 #only use orientations from grains BELOW this chi^2
106+
# TOMO OPTIONS
107+
# !!! Don't change these unless you know what you are doing
108+
# this will close small holes and remove noise
109+
recon_thresh = 0.00006 # usually varies between 0.0001 and 0.0005
110+
noise_obj_size = 5000
111+
min_hole_size = 5000
101112

113+
# cross sectional to reconstruct (should be at least 20%-30% over sample width)
114+
cross_sectional_dim = 1.00
102115

103-
#tomography options
104-
layer_row=1024 # row of layer to use to find the cross sectional specimen shape
116+
voxel_spacing = 0.005 # voxel spacing for the near field reconstruction in mm
117+
v_bnds = [-0.005, 0.005] # vertical (y) reconstruction voxel bounds in mm
105118

106-
#Don't change these unless you know what you are doing, this will close small holes
107-
#and remove noise
108-
recon_thresh=0.00006#usually varies between 0.0001 and 0.0005
109-
noise_obj_size=5000
110-
min_hole_size=5000
111-
112-
113-
cross_sectional_dim=1.35 #cross sectional to reconstruct (should be at least 20%-30% over sample width)
114-
#voxel spacing for the near field reconstruction
115-
voxel_spacing=0.005#in mm
116-
##vertical (y) reconstruction voxel bounds in mm
117-
v_bnds=[-0.005,0.005]
118-
119-
120-
121-
122-
#==============================================================================
119+
# =============================================================================
123120
# %% LOAD GRAIN DATA
124-
#==============================================================================
121+
# =============================================================================
125122

126-
experiment, nf_to_ff_id_map = nfutil.gen_trial_exp_data(grain_out_file,det_file,mat_file, x_ray_energy, mat_name, max_tth, comp_thresh, chi2_thresh, misorientation_bnd, \
127-
misorientation_spacing,ome_range_deg, num_imgs, beam_stop_width)
123+
experiment, nf_to_ff_id_map = nfutil.gen_trial_exp_data(
124+
grain_out_file, det_file, mat_file, x_ray_energy, mat_name,
125+
max_tth, min_completeness, max_chisq, misorientation_bnd,
126+
misorientation_spacing, ome_range_deg, num_imgs, beam_stop_width
127+
)
128128

129-
#==============================================================================
129+
# =============================================================================
130130
# %% TOMO PROCESSING - GENERATE BRIGHT FIELD
131-
#==============================================================================
131+
# =============================================================================
132132

133-
tbf=tomoutil.gen_bright_field(tbf_data_folder,tbf_img_start,tbf_num_imgs,experiment.nrows,experiment.ncols)
133+
tbf = tomoutil.gen_bright_field(
134+
tbf_data_folder, tbf_img_start, tbf_num_imgs,
135+
experiment.nrows, experiment.ncols
136+
)
134137

135-
#==============================================================================
138+
# =============================================================================
136139
# %% TOMO PROCESSING - BUILD RADIOGRAPHS
137-
#==============================================================================
138-
139-
140-
rad_stack=tomoutil.gen_attenuation_rads(tomo_data_folder,tbf,tomo_img_start,tomo_num_imgs,experiment.nrows,experiment.ncols)
140+
# =============================================================================
141141

142+
rad_stack = tomoutil.gen_attenuation_rads(
143+
tomo_data_folder, tbf, tomo_img_start, tomo_num_imgs,
144+
experiment.nrows, experiment.ncols
145+
)
142146

143-
#==============================================================================
147+
# =============================================================================
144148
# %% TOMO PROCESSING - INVERT SINOGRAM
145-
#==============================================================================
149+
# =============================================================================
146150

147-
reconstruction_fbp=tomoutil.tomo_reconstruct_layer(rad_stack,cross_sectional_dim,layer_row=layer_row,\
148-
start_tomo_ang=ome_range_deg[0][0],end_tomo_ang=ome_range_deg[0][1],\
149-
tomo_num_imgs=tomo_num_imgs, center=experiment.detector_params[3])
151+
reconstruction_fbp = tomoutil.tomo_reconstruct_layer(
152+
rad_stack, cross_sectional_dim, layer_row=layer_row,
153+
start_tomo_ang=ome_range_deg[0][0], end_tomo_ang=ome_range_deg[0][1],
154+
tomo_num_imgs=tomo_num_imgs, center=experiment.detector_params[3]
155+
)
150156

151-
#==============================================================================
157+
# =============================================================================
152158
# %% TOMO PROCESSING - VIEW RAW FILTERED BACK PROJECTION
153-
#==============================================================================
159+
# =============================================================================
154160

155161
plt.close('all')
156-
plt.imshow(reconstruction_fbp,vmin=0.75e-4,vmax=2e-4)
157-
#Use this image to view the raw reconstruction, estimate threshold levels. and
158-
#figure out if the rotation axis position needs to be corrected
162+
plt.imshow(reconstruction_fbp, vmin=0.75e-4, vmax=2e-4)
163+
# Use this image to view the raw reconstruction, estimate threshold levels. and
164+
# figure out if the rotation axis position needs to be corrected
159165

160166

161-
#==============================================================================
167+
# =============================================================================
162168
# %% TOMO PROCESSING - CLEAN TOMO RECONSTRUCTION
163-
#==============================================================================
169+
# =============================================================================
164170

165171
binary_recon = tomoutil.threshold_and_clean_tomo_layer(
166172
reconstruction_fbp,

0 commit comments

Comments
 (0)