def search_down(edges, folder, n, v, step=math.pi/18, tolerance = math.pi/18, raw=None, debug = False): width = edges.shape[1] height = edges.shape[0] from src.utils.hough import my_hough cur = v ret = [] for i in range(n): if cur.bottomline is not None: # find new vertebra cur_tan = math.fabs((cur.bottomline.line[0][0] - cur.bottomline.line[1][0])/float(cur.bottomline.line[0][1]-cur.bottomline.line[1][1])) cur_ang = -math.atan(cur_tan) # assume it's minus cur_start = cur_ang + step + tolerance cur_end = cur_ang + step - tolerance/10. fn = folder + str(i) cur_len = math.sqrt((cur.bottomline.line[0][0] - cur.bottomline.line[1][0])**2 + (cur.bottomline.line[0][1]-cur.bottomline.line[1][1])**2) if cur_len < 35: ROI, x1, y1= get_ROI(edges, cur.bottomline.line, -70, 40, 0, 50, width, height, debug) else: ROI, x1, y1 = get_ROI(edges, cur.bottomline.line, -50, 20, 0, 50, width, height, debug) fn = folder + str(i) + datetime.datetime.now().strftime("%Y%m%d%H%M") lines = my_hough(fn=fn, edges=ROI,hough_start=cur_end, hough_end=cur_start, hough_line_len=10, save=debug, show=debug, raw=raw, xdiff=x1, ydiff=y1) if len(lines)!= 0: line = lines[0] # only choosing one of the line if cur.bottomline.line != line: v = vertebra() v.topline = line_struct() v.topline.line = line ret.append(v) cur = v else: break else: # find corresponding bottom edge cur_tan = math.fabs((cur.topline.line[0][0] - cur.topline.line[1][0])/float(cur.topline.line[0][1]-cur.topline.line[1][1])) cur_ang = -math.atan(cur_tan) cur_start = cur_ang + tolerance cur_end = cur_ang - tolerance cur_len = math.sqrt((cur.topline.line[0][0] - cur.topline.line[1][0])**2 + (cur.topline.line[0][1]-cur.topline.line[1][1])**2) # if current line is only a small portion of the actual line, # the range is put looser. if cur_len < 34: ROI, x1, y1 = get_ROI(edges, cur.topline.line, -70, 30, 10, 80, width, height, debug) else: ROI, x1, y1 = get_ROI(edges, cur.topline.line, -40, 30, 30, 80, width, height, debug) fn = folder + str(i)+ datetime.datetime.now().strftime("%Y%m%d%H%M") lines =my_hough(edges=ROI, fn=fn, hough_start=cur_end, hough_end=cur_start, hough_line_len=10, save=debug, show=debug, raw=raw, xdiff=x1, ydiff=y1) if len(lines)!= 0: line = lines[0] cur.bottomline = line_struct() cur.bottomline.line = line else: break return ret
def search_up(edges, folder, n, v, step=math.pi/18, tolerance = math.pi/18, raw=None, debug = False): width = edges.shape[1] height = edges.shape[0] from src.utils.hough import my_hough cur = v ret = [] for i in range(n): if cur.topline is not None: cur_tan = math.fabs((cur.topline.line[0][0] - cur.topline.line[1][0])/float(cur.topline.line[0][1]-cur.topline.line[1][1])) cur_ang = math.atan(cur_tan) cur_start = cur_ang - step - 2*tolerance cur_end = cur_ang - step + 2*tolerance cur_len = math.sqrt((cur.topline.line[0][0] - cur.topline.line[1][0])**2 + (cur.topline.line[0][1]-cur.topline.line[1][1])**2) # if current line is only a small portion of the actual line, # the range is put looser. if cur_len < 34: ROI, x1, y1 = get_ROI(edges, cur.topline.line, -40, 30, -70, 20, width, height, debug) else: ROI, x1, y1 = get_ROI(edges, cur.topline.line, -40, 30, -70, 20, width, height, debug) fn = folder + str(i) + datetime.datetime.now().strftime("%Y%m%d%H%M") lines =my_hough(edges=ROI, fn=fn, hough_start=cur_start, hough_end=cur_end, hough_line_len=10, save=debug, show=debug, raw=raw, xdiff=x1, ydiff=y1) if len(lines)!= 0: line = lines[0] v_new = vertebra() v_new.bottomline = line_struct() v_new.bottomline.line = line ret.insert(0, v_new) #add new vertebra to the top of the list cur = v_new else: break else: cur_tan = math.fabs((cur.bottomline.line[0][0] - cur.bottomline.line[1][0])/float(cur.bottomline.line[0][1]-cur.bottomline.line[1][1])) cur_ang = math.atan(cur_tan) cur_start = cur_ang - tolerance cur_end = cur_ang + tolerance fn = folder + str(i) + datetime.datetime.now().strftime("%Y%m%d%H%M") cur_len = math.sqrt((cur.bottomline.line[0][0] - cur.bottomline.line[1][0])**2 + (cur.bottomline.line[0][1]-cur.bottomline.line[1][1])**2) if cur_len < 35: ROI, x1, y1 = get_ROI(edges, cur.bottomline.line, -70, 40, -120, -10, width, height, debug) else: ROI, x1, y1 = get_ROI(edges, cur.bottomline.line, -50, 20, -100, -20, width, height, debug) fn = folder + str(i) + datetime.datetime.now().strftime("%Y%m%d%H%M") lines = my_hough(fn=fn, edges=ROI,hough_start=cur_start, hough_end=cur_end, hough_line_len=10, save=debug, show=debug, raw=raw, xdiff=x1, ydiff=y1) if len(lines)!= 0: line = lines[0] # only choosing one of the line if cur.bottomline.line != line: cur.topline = line_struct() cur.topline.line = line else: break return ret