def _generate_ellipse_mask(point, image, size, p, random, OorA, lean, angle=0): if size == 1: raise ValueError('size must be > 1 for ellipses') left = point[1] right = image[1] - point[1] top = point[0] bottom = image[0] - point[0] available_radius = min(left, right, top, bottom) r_radius = int(math.sqrt((size / p) / math.pi)) c_radius = int(math.sqrt((size * p) / math.pi)) if r_radius > available_radius: raise ArithmeticError('cannot fit shape to image') ellipse = draw_ellipse(point[0], point[1], r_radius, c_radius, rotation=angle) #不是很懂为啥有+1 label = ('ellipse', ((point[0] - r_radius + 1, point[0] + r_radius), (point[1] - r_radius + 1, point[1] + r_radius))) # return ellipse, label
def _generate_ellipse_mask(point, image, size,p, random, angle=0): if size == 1 : raise ValueError('size must be > 1 for circles') left = point[1] right = image[1] - point[1] top = point[0] bottom = image[0] - point[0] available_radius=min(left,right,top,bottom) #仅仅为了让lable中有变量 radius = math.sqrt(size / math.pi) # r_radius = math.sqrt(size / p / math.pi) c_radius = math.sqrt(size * p / math.pi) if r_radius > available_radius or c_radius > available_radius : raise ArithmeticError('cannot fit shape to image') ellipse = draw_ellipse(point[0], point[1], r_radius, c_radius, rotation=angle) #这里label需要修改!!!!!! label = ('ellipse', ((point[0] - radius + 1, point[0] + radius), (point[1] - radius + 1, point[1] + radius))) # return ellipse, label
def _generate_ellipse_mask(point, image, shape, random, angle=0): if shape[0] == 1 or shape[1] == 1: raise ValueError('size must be > 1 for circles') min_radius = shape[0] / 2.0 max_radius = shape[1] / 2.0 left = point[1] right = image[1] - point[1] top = point[0] bottom = image[0] - point[0] available_radius = min(left, right, top, bottom, max_radius) if available_radius < min_radius: raise ArithmeticError('cannot fit shape to image') radius = random.randint(min_radius, available_radius + 1) import random as rd radius1 = radius * (rd.random() / 2 + 0.5) radius2 = radius * (rd.random() / 2 + 0.5) if radius1 > radius2: r_radius = radius1 c_radius = radius2 else: r_radius = radius2 c_radius = radius1 ellipse = draw_ellipse(point[0], point[1], r_radius, c_radius, rotation=angle) label = ('ellipse', ((point[0] - radius + 1, point[0] + radius), (point[1] - radius + 1, point[1] + radius))) return ellipse, label
def _drawEllipse(self, centro, axs, image): ''' args: centro = coordinates of the center axs = major and minor axis coming from the fit of the ellipse image = masked array returns: ellipse = ellipse of one to display ''' ellipse = np.zeros((image.shape[0], image.shape[1])) rr, cc = draw_ellipse(centro[1], centro[0], axs[1], axs[0]) ellipse[rr, cc] = 1 return ellipse