@@ -103,6 +103,20 @@ def edge_pts(self, t):
103
103
right_pt = [pt [0 ] + vec_step [1 ], pt [1 ] - vec_step [0 ]]
104
104
return left_pt , right_pt
105
105
106
+ def edge_offset_pt (self , t , perc_in_out , dir ):
107
+ """ Go in/out of the edge point a given percentage
108
+ @param t - t value along the curve (in range 0, 1)
109
+ @param perc_in_out - if 1, get point on edge. If 0.5, get halfway to centerline. If 2.0 get 2 width
110
+ @param dir - 'Left' is the left direction, 'Right' is the right direction
111
+ @return numpy array x,y """
112
+ pt_edge = self .pt_axis (t )
113
+ vec_tang = self .tangent_axis (t )
114
+ vec_step = perc_in_out * self .radius (t ) * vec_tang / np .sqrt (vec_tang [0 ] * vec_tang [0 ] + vec_tang [1 ] * vec_tang [1 ])
115
+
116
+ if dir == "Left" :
117
+ return np .array ([pt_edge [0 ] + vec_step [1 ], pt_edge [1 ] - vec_step [0 ]])
118
+ return np .array ([pt_edge [0 ] - vec_step [1 ], pt_edge [1 ] + vec_step [0 ]])
119
+
106
120
@staticmethod
107
121
def _rect_in_image (im , r , pad = 2 ):
108
122
""" See if the rectangle is within the image boundaries
@@ -157,19 +171,25 @@ def _rect_corners_interior(self, t1, t2, perc_width=0.3):
157
171
[pt1 [0 ] - vec_step [1 ], pt1 [1 ] + vec_step [0 ]]], dtype = "float32" )
158
172
return rect
159
173
160
- def boundary_rects (self , step_size = 40 , perc_width = 0.3 ):
174
+ def boundary_rects (self , step_size = 40 , perc_width = 0.3 , offset = False ):
161
175
""" Get a set of rectangles covering the left/right expected edges of the cylinder/tube
162
176
March along the edges at the given image step size and produce rectangles in pairs
163
177
@param step_size how many pixels to move along the boundary
164
178
@param perc_width How much of the radius to move in/out of the edge
179
+ @param offset - if True, start at 0.5 of step_size and end at 1-0.5
165
180
@returns a list of pairs of left,right rectangles - evens are left, odds right"""
166
181
167
182
t_step = self ._time_step_from_im_step (step_size )
168
183
n_boxes = int (max (1.0 , 1.0 / t_step ))
169
184
t_step_exact = 1.0 / n_boxes
170
185
rects = []
171
186
ts = []
172
- for t in np .arange (0 , 1.0 , step = t_step_exact ):
187
+ t_start = 0
188
+ t_end = 1
189
+ if offset :
190
+ t_start = 0.5 * t_step_exact
191
+ t_end = 1.0 - 0.5 * t_step_exact
192
+ for t in np .arange (t_start , t_end , step = t_step_exact ):
173
193
rect_left , rect_right = self ._rect_corners (t , t + t_step_exact , perc_width = perc_width )
174
194
rects .append (rect_left )
175
195
rects .append (rect_right )
0 commit comments