|
31 | 31 |
|
32 | 32 |
|
33 | 33 | import numpy as np |
34 | | -#import numba as nb |
35 | 34 | from skimage.feature import peak_local_max |
36 | 35 | from skimage.morphology.grey import erosion, dilation |
37 | 36 |
|
| 37 | +from .rasterizer import polys |
38 | 38 |
|
39 | 39 | def _linear_transform(src, dst): |
40 | 40 | """ Parameters of a linear transform from range specifications """ |
@@ -112,7 +112,7 @@ def transform(self, x): |
112 | 112 | """ |
113 | 113 | _check_points(x) |
114 | 114 | x0,x1 = np.split(x,2,axis=1) |
115 | | - return np.concatenate([self.norm_u(x1), self.norm_v(x0), self.norm_w(x1)], axis=1) |
| 115 | + return np.concatenate([self.norm_u(x1), self.norm_v(x0), self.norm_w(x1)], axis=1).astype("f") |
116 | 116 |
|
117 | 117 | def inverse(self, l): |
118 | 118 | """ |
@@ -145,25 +145,23 @@ def insert(self, x, weight=None): |
145 | 145 | if weight is None: |
146 | 146 | weight = np.ones(n, np.float32) |
147 | 147 |
|
| 148 | + if weight.dtype != np.float32: |
| 149 | + weight = weight.astype(np.float32) |
| 150 | + |
148 | 151 | valid = self.valid_points(p) |
149 | 152 | p = p[valid] |
150 | 153 | weight = weight[valid.flat] |
151 | 154 |
|
152 | | - d = self.d |
153 | | - c = np.arange(2*d-1,dtype="i") |
154 | | - for (u,v,w),wt in zip(p, weight): # remove space wraping |
155 | | - t_part = np.linspace(u,v,d) |
156 | | - s_part = np.linspace(v,w,d) |
157 | | - r = np.concatenate([t_part, s_part[1:]]).astype("i") |
158 | | - self.A[r,c] += wt # TODO add weight |
| 155 | + polys(p, weight, self.A) |
| 156 | + |
159 | 157 |
|
160 | 158 | def find_peaks(self, t=0.8, prominence=2, min_dist=1): |
161 | 159 | """ |
162 | 160 | Retrieve locations with prominent local maxima in the accumulator |
163 | 161 | """ |
164 | 162 | p = dilation(self.A+1)/erosion(self.A+1) |
165 | | - peaks = peak_local_max(self.A, threshold_rel=t, min_distance=min_dist) |
| 163 | + peaks = peak_local_max(self.A, threshold_rel=t, min_distance=min_dist, exclude_border=False) |
166 | 164 | r,c = peaks[:,0], peaks[:,1] |
167 | | - value = A[r,c] |
| 165 | + value = self.A[r,c] |
168 | 166 | valid = p[r,c] > prominence |
169 | 167 | return peaks[valid], value[valid] |
0 commit comments