|
26 | 26 |
|
27 | 27 | from hexrd.fitgrains import get_instrument_parameters |
28 | 28 |
|
29 | | -logger = logging.getLogger(__name__) |
30 | | - |
31 | | -save_as_ascii = False # FIX LATER... |
| 29 | +from skimage.feature import blob_dog, blob_log |
32 | 30 |
|
33 | 31 | # just require scikit-learn? |
34 | 32 | have_sklearn = False |
|
43 | 41 | pass |
44 | 42 |
|
45 | 43 |
|
| 44 | +method = "blob_dog" # !!! have to get this from the config |
| 45 | +save_as_ascii = False # FIX LATER... |
| 46 | + |
| 47 | +logger = logging.getLogger(__name__) |
| 48 | + |
| 49 | + |
| 50 | +# ============================================================================= |
| 51 | +# FUNCTIONS |
| 52 | +# ============================================================================= |
| 53 | + |
| 54 | + |
46 | 55 | def generate_orientation_fibers( |
47 | 56 | eta_ome, chi, threshold, seed_hkl_ids, fiber_ndiv, |
48 | | - filt_stdev=0.8, ncpus=1): |
| 57 | + method='blob_dog', filt_stdev=0.8, ncpus=1): |
49 | 58 | """ |
50 | 59 | From ome-eta maps and hklid spec, generate list of |
51 | 60 | quaternions from fibers |
@@ -82,21 +91,42 @@ def generate_orientation_fibers( |
82 | 91 | numSpots = [] |
83 | 92 | coms = [] |
84 | 93 | for i in seed_hkl_ids: |
85 | | - # First apply filter |
86 | | - this_map_f = -ndimage.filters.gaussian_laplace( |
87 | | - eta_ome.dataStore[i], filt_stdev) |
88 | | - |
89 | | - labels_t, numSpots_t = ndimage.label( |
90 | | - this_map_f > threshold, |
91 | | - structureNDI_label |
92 | | - ) |
93 | | - coms_t = np.atleast_2d( |
94 | | - ndimage.center_of_mass( |
95 | | - this_map_f, |
96 | | - labels=labels_t, |
97 | | - index=np.arange(1, np.amax(labels_t)+1) |
| 94 | + if method == 'label': |
| 95 | + # First apply filter |
| 96 | + this_map_f = -ndimage.filters.gaussian_laplace( |
| 97 | + eta_ome.dataStore[i], filt_stdev) |
| 98 | + |
| 99 | + labels_t, numSpots_t = ndimage.label( |
| 100 | + this_map_f > threshold, |
| 101 | + structureNDI_label |
98 | 102 | ) |
99 | | - ) |
| 103 | + coms_t = np.atleast_2d( |
| 104 | + ndimage.center_of_mass( |
| 105 | + this_map_f, |
| 106 | + labels=labels_t, |
| 107 | + index=np.arange(1, np.amax(labels_t) + 1) |
| 108 | + ) |
| 109 | + ) |
| 110 | + elif method in ['blob_log', 'blob_dog']: |
| 111 | + # must scale map |
| 112 | + this_map = eta_ome.dataStore[i] |
| 113 | + this_map[np.isnan(this_map)] = 0. |
| 114 | + this_map -= np.min(this_map) |
| 115 | + scl_map = 2*this_map/np.max(this_map) - 1. |
| 116 | + |
| 117 | + # FIXME: need to expose the parameters to config options. |
| 118 | + if method == 'blob_log': |
| 119 | + blobs = np.atleast_2d( |
| 120 | + blob_log(scl_map, min_sigma=0.5, max_sigma=5, |
| 121 | + num_sigma=10, threshold=0.01, overlap=0.1) |
| 122 | + ) |
| 123 | + else: |
| 124 | + blobs = np.atleast_2d( |
| 125 | + blob_dog(scl_map, min_sigma=0.5, max_sigma=5, |
| 126 | + sigma_ratio=1.6, threshold=0.01, overlap=0.1) |
| 127 | + ) |
| 128 | + numSpots_t = len(blobs) |
| 129 | + coms_t = blobs[:, :2] |
100 | 130 | numSpots.append(numSpots_t) |
101 | 131 | coms.append(coms_t) |
102 | 132 | pass |
|
0 commit comments