예제 #1
0
 def make_labels(self, s=10, side=1000, ct=20):
     mini_side = side / s
     labels = np.zeros((side, side), int)
     pts = np.zeros((s * s * ct, 2), int)
     index = np.arange(pts.shape[0], dtype=float) / float(ct)
     index = index.astype(int)
     idx = 0
     for i in range(0, side, mini_side):
         for j in range(0, side, mini_side):
             idx = idx + 1
             # get ct+1 unique points
             p = np.random.uniform(low=0,
                                   high=mini_side,
                                   size=(ct + 1, 2)).astype(int)
             while True:
                 pu = np.unique(p[:, 0] + p[:, 1] * mini_side)
                 if pu.shape[0] == ct + 1:
                     break
                 p[:pu.shape[0], 0] = np.mod(pu, mini_side).astype(int)
                 p[:pu.shape[0], 1] = (pu / mini_side).astype(int)
                 p_size = (ct + 1 - pu.shape[0], 2)
                 p[pu.shape[0], :] = np.random.uniform(low=0,
                                                       high=mini_side,
                                                       size=p_size)
             # Use the last point as the "center" and order
             # all of the other points according to their angles
             # to this "center"
             center = p[ct, :]
             v = p[:ct, :] - center
             angle = np.arctan2(v[:, 0], v[:, 1])
             order = np.lexsort((angle, ))
             p = p[:ct][order]
             p[:, 0] = p[:, 0] + i
             p[:, 1] = p[:, 1] + j
             pts[(idx - 1) * ct:idx * ct, :] = p
             #
             # draw lines on the labels
             #
             for k in range(ct):
                 draw_line(labels, p[k, :], p[(k + 1) % ct, :], idx)
     labels = fill_labeled_holes(labels)
     return labels
예제 #2
0
 def make_labels(self,s=10,side=1000,ct=20):
     mini_side = side / s
     labels = np.zeros((side,side),int)
     pts = np.zeros((s*s*ct,2),int)
     index = np.arange(pts.shape[0],dtype=float)/float(ct)
     index = index.astype(int)
     idx = 0
     for i in range(0,side,mini_side):
         for j in range(0,side,mini_side):
             idx = idx+1
             # get ct+1 unique points
             p = np.random.uniform(low=0,high=mini_side,
                                   size=(ct+1,2)).astype(int)
             while True:
                 pu = np.unique(p[:,0]+p[:,1]*mini_side)
                 if pu.shape[0] == ct+1:
                     break
                 p[:pu.shape[0],0] = np.mod(pu,mini_side).astype(int)
                 p[:pu.shape[0],1] = (pu / mini_side).astype(int)
                 p_size = (ct+1-pu.shape[0],2)
                 p[pu.shape[0],:] = np.random.uniform(low=0,
                                                      high=mini_side,
                                                      size=p_size)
             # Use the last point as the "center" and order
             # all of the other points according to their angles
             # to this "center"
             center = p[ct,:]
             v = p[:ct,:]-center
             angle = np.arctan2(v[:,0],v[:,1])
             order = np.lexsort((angle,))
             p = p[:ct][order]
             p[:,0] = p[:,0]+i
             p[:,1] = p[:,1]+j
             pts[(idx-1)*ct:idx*ct,:]=p
             #
             # draw lines on the labels
             #
             for k in range(ct):
                 draw_line(labels, p[k,:], p[(k+1)%ct,:], idx)
     labels = fill_labeled_holes(labels)
     return labels