<< Chapter < Page Chapter >> Page >

2.2.4 processing the results of the transform

Often, multiple (r, a, b) within a cluster will be local maximums, and often, we'll also detect false positives. We do some processing to average clusters and remove false positives.

  1. Find clusters of circles, where a cluster is defined as circles with centers a within distance of l away from each other.
  2. Average the center and radius of circles in a cluster to create a new circle. Each circle in a cluster contributes its own center and radius weighted by the number of votes it received squared.
  3. Remove any clusters with less than a threshold number of circles

Code

def reduce_circles(circle_indices, distMin, param_votes): """Helper function for hough_circle Averages clusters of circles:param circle_indices: numpy array of circles detected. Stored as a = [[radii], [rows], [cols]] wherea[0][i]is the radius of the ith circle a[1][i] is the row where the center of the ith circle is locateda[2][i]is the col where the center of the ith circle is located :param distMin: int, minimum distance between circles detected. (The function averages circles clustered withina distMin x distMin square) :param votesMin: int, minimum threshold for accumulator value. The higher this value is,the less false circles detected :return: numpy array of circles""" rad_indices = circle_indices[0]r_indices = circle_indices[1] c_indices = circle_indices[2]print rad_indices print r_indicesprint c_indices total_circles = len(rad_indices)print "total circles ", total_circles new_circle_indices = [[],[],[]]radtemp = 0 # accumulator value for radii rtemp = 0 # accumulator value for rowsctemp = 0 # accumulator value for columns weightcount = 0 # accumulator value for weight of each circle.# A proposed circle with n votes contributes n^2 weight count = 0 # total number of circles detected in a cluster.minThresh = total_circles / 5 # Each cluster has a count that records number of circles in that cluster. # If count is below minThresh, the cluster is disregarded as a false positive.# Remove an (radius, center) once it's been determined part of a cluster. Iterate until no more proposed circles to # iterate through. Iterate backwards so deleting things doesn't mess up indexing.while np.size(rad_indices)!= 0: # get centerr0 = r_indices[0] c0 = c_indices[0]for i in reversed(range(0, total_circles)): # If iterate through all other proposed circles, and find ones with center within a# distMin x distMin square. if abs(r0 - r_indices[i])<distMin and abs(c0 - c_indices[i]<distMin): # (radius, center) values of proposed circle wwe've iterated torad = rad_indices[i] r = r_indices[i]c = c_indices[i] # increase accumulator values, weighted by weightweight = param_votes[rad][r][c]*param_votes[rad][r][c]radtemp += rad * weight rtemp += r * weightctemp += c * weight # delete proposed circle from rad_indicesrad_indices = np.delete(rad_indices, i) r_indices = np.delete(r_indices, i)c_indices = np.delete(c_indices, i) weightcount += weightcount += 1 total_circles = len(rad_indices)# if more circles in cluster than minThresh, average the radii and center values to combine the cluster into # one circleif count>= minThresh: new_circle_indices[0].append(radtemp / weightcount) new_circle_indices[1].append(rtemp / weightcount) new_circle_indices[2].append(ctemp /weightcount) # Optional code. If you know you won't have circles within circles, uncomment this code.# This removes circles with centers inside of other circles. # for i in reversed(range(0, total_circles)):# if abs(rtemp / weightcount - r_indices[i])<radtemp / weightcount and abs(ctemp /weightcount - c_indices[i])<radtemp / weightcount: # rad_indices = np.delete(rad_indices, i)# r_indices = np.delete(r_indices, i) # c_indices = np.delete(c_indices, i)# total_circles = len(rad_indices) # reset accumulators to 0 for the next clusterradtemp = 0 rtemp = 0ctemp = 0 count = 0weightcount = 0 return np.array(new_circle_indices)

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Elec 301 projects fall 2015. OpenStax CNX. Jan 04, 2016 Download for free at https://legacy.cnx.org/content/col11950/1.1
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Elec 301 projects fall 2015' conversation and receive update notifications?

Ask