Skip to content

Commit ab3a322

Browse files
committed
Writing initial draft of extract_curves.py
1 parent d3435d2 commit ab3a322

5 files changed

+219
-435
lines changed

Image_based/bezier_cyl_2d.py

+22-2
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,20 @@ def edge_pts(self, t):
103103
right_pt = [pt[0] + vec_step[1], pt[1] - vec_step[0]]
104104
return left_pt, right_pt
105105

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+
106120
@staticmethod
107121
def _rect_in_image(im, r, pad=2):
108122
""" See if the rectangle is within the image boundaries
@@ -157,19 +171,25 @@ def _rect_corners_interior(self, t1, t2, perc_width=0.3):
157171
[pt1[0] - vec_step[1], pt1[1] + vec_step[0]]], dtype="float32")
158172
return rect
159173

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):
161175
""" Get a set of rectangles covering the left/right expected edges of the cylinder/tube
162176
March along the edges at the given image step size and produce rectangles in pairs
163177
@param step_size how many pixels to move along the boundary
164178
@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
165180
@returns a list of pairs of left,right rectangles - evens are left, odds right"""
166181

167182
t_step = self._time_step_from_im_step(step_size)
168183
n_boxes = int(max(1.0, 1.0 / t_step))
169184
t_step_exact = 1.0 / n_boxes
170185
rects = []
171186
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):
173193
rect_left, rect_right = self._rect_corners(t, t + t_step_exact, perc_width=perc_width)
174194
rects.append(rect_left)
175195
rects.append(rect_right)

0 commit comments

Comments
 (0)