def make_ring(inner_radius: int, outer_radius: int, dtype: str = 'uint8') -> np.ndarray: """ Make a circle with a given radius. Args: inner_radius: the inner radius of the circle to draw outer_radius: the outer radius of the circle to draw Returns: a NumPy matrix of size 2 * radius + 1 with a circle in it. """ # if the radius is even, make it odd length = 2 * outer_radius + 1 # create an RGBA box to house the circle in box = np.zeros((length, length), dtype=dtype) # get the coordinates for the outer circle x_pixels, y_pixels = draw_circle(outer_radius, outer_radius, outer_radius) # set the coordinates of the circle in the box box[x_pixels, y_pixels] = 1 # get the coordinates for the inner circle x_pixels, y_pixels = draw_circle(outer_radius, outer_radius, inner_radius) # set the coordinates of the circle in the box box[x_pixels, y_pixels] = 0 return box
def get_label_map(self, parameters, height, width): label_map = np.zeros((height, width, 1)) dia = np.sqrt(height**2 + width**2) rr, cc = draw_circle(int(parameters[0] * height), int(parameters[1] * width), int(parameters[2] * dia), shape=(height, width)) label_map[rr, cc, 0] = 1 return label_map
def _drawCircle(self, centro, raggio, image): ''' args: centro = coordinates of the center raggio = radius of the parabola circumference image = masked array returns: circle = circle of one to display ''' circle = np.zeros((image.shape[0], image.shape[1])) rr, cc = draw_circle(centro[1], centro[0], raggio / self._rFiducialPoint) circle[rr, cc] = 1 return circle
def _generate_circle_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) circle = draw_circle(point[0], point[1], radius) label = ('circle', ((point[0] - radius + 1, point[0] + radius), (point[1] - radius + 1, point[1] + radius))) return circle, label
def _generate_circle_mask_new(point, image, shape, random): """Generate a mask for a filled circle shape. The radius of the circle is generated randomly. Parameters ---------- point : tuple The row and column of the top left corner of the rectangle. image : tuple The height, width and depth of the image into which the shape is placed. shape : tuple The minimum and maximum size and color of the shape to fit. random : np.random.RandomState The random state to use for random sampling. Raises ------ ArithmeticError When a shape cannot be fit into the image with the given starting coordinates. This usually means the image dimensions are too small or shape dimensions too large. Returns ------- label : tuple A (category, ((r0, r1), (c0, c1))) tuple specifying the category and bounding box coordinates of the shape. indices : 2-D array A mask of indices that the shape fills. """ 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) circle = draw_circle(point[0], point[1], radius) label = ('circle', (point[0], point[1], radius)) return circle, label
def _circleImage(image, x, y, raggio_px): ''' Function to create circular cuts of the image. The function excludes cuts that come out of the edges of the image and check the threshold for valid point NOTE: if image is out of conditions return None type Parameters ---------- image: masked array image for the analysis x: int coordinate x y: int coordinate y radius_px: int radius of circular patch in pixels Returns ------- ima: numpy masked array cut image ''' th_validPoint = np.pi * raggio_px**2 * 30 / 100 if image is not None: circle = np.ones((image.shape[0], image.shape[1])).astype(int) rr, cc = draw_circle(x, y, raggio_px) test_r = (len(list(filter(lambda x: x >= image.shape[0], rr))) > 0) test_r2 = (len(list(filter(lambda x: x <= 0, rr))) > 0) test_c = (len(list(filter(lambda x: x >= image.shape[0], cc))) > 0) if test_r == True: pass elif test_r2 == True: pass elif test_c == True: pass else: circle[rr, cc] = 0 mask_prod = np.ma.mask_or(circle.astype(bool), image.mask) ima = np.ma.masked_array(image, mask=mask_prod) valid_point = ima.compressed().shape[0] if valid_point >= th_validPoint: return ima
def _generate_circle_mask(point, image, size, p, random, OorA, lean, angle): 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) radius = int(math.sqrt(size / math.pi)) if radius > available_radius: raise ArithmeticError('cannot fit shape to image') circle = draw_circle(point[0], point[1], radius) label = ('circle', ((point[0] - radius + 1, point[0] + radius), (point[1] - radius + 1, point[1] + radius))) return circle, label