Exemplo n.º 1
0
def draw_ring(centre, r1, r2, contrast, N): #r1>r2, r_coord: (x,y)
    ring=np.zeros((N,N), dtype=np.int8)
    x1,y1 = draw.disk(centre,r1,shape=ring.shape)
    x2,y2 = draw.disk(centre,r2,shape=ring.shape)
    ring[x1,y1]=contrast
    ring[x2,y2]=0
    return ring
Exemplo n.º 2
0
def test_blob_doh(dtype, threshold_type):
    img = np.ones((512, 512), dtype=dtype)

    xs, ys = disk((400, 130), 20)
    img[xs, ys] = 255

    xs, ys = disk((460, 50), 30)
    img[xs, ys] = 255

    xs, ys = disk((100, 300), 40)
    img[xs, ys] = 255

    xs, ys = disk((200, 350), 50)
    img[xs, ys] = 255

    if threshold_type == 'absolute':
        # Note: have to either scale up threshold or rescale the image to the
        #       range [0, 1] internally.
        threshold = 0.05
        if img.dtype.kind == 'f':
            # account for lack of internal scaling to [0, 1] by img_as_float
            ptp = img.ptp()
            threshold *= ptp**2
        threshold_rel = None
    elif threshold_type == 'relative':
        threshold = None
        threshold_rel = 0.5

    blobs = blob_doh(img,
                     min_sigma=1,
                     max_sigma=60,
                     num_sigma=10,
                     threshold=threshold,
                     threshold_rel=threshold_rel)

    radius = lambda x: x[2]
    s = sorted(blobs, key=radius)
    thresh = 4

    b = s[0]
    assert abs(b[0] - 400) <= thresh
    assert abs(b[1] - 130) <= thresh
    assert abs(radius(b) - 20) <= thresh

    b = s[1]
    assert abs(b[0] - 460) <= thresh
    assert abs(b[1] - 50) <= thresh
    assert abs(radius(b) - 30) <= thresh

    b = s[2]
    assert abs(b[0] - 100) <= thresh
    assert abs(b[1] - 300) <= thresh
    assert abs(radius(b) - 40) <= thresh

    b = s[3]
    assert abs(b[0] - 200) <= thresh
    assert abs(b[1] - 350) <= thresh
    assert abs(radius(b) - 50) <= thresh
Exemplo n.º 3
0
def create_data(deformation=False):
    img = np.zeros((100, 100))

    coords = draw.ellipse(50, 50, 35, 13)
    set_ellipse = set((tuple(i) for i in np.array(coords).T))
    img[coords] = 120

    coords2 = draw.disk((50, 63), 5)
    set_disk = set((tuple(i) for i in np.array(coords2).T))
    set_intersection = set_disk.intersection(set_ellipse)
    inters_xy = tuple(np.array(list(set_intersection)).T)
    img[inters_xy] = 200

    coords_disktop = draw.disk((30, 55), 7)
    set_disk = set((tuple(i) for i in np.array(coords_disktop).T))
    set_intersection = set_disk.intersection(set_ellipse)
    inters_xy = tuple(np.array(list(set_intersection)).T)
    img[inters_xy] = 200

    coords_line = draw.line(82, 46, 60, 40)
    img[coords_line] = 200
    coords_line = draw.line(82, 47, 60, 41)
    img[coords_line] = 200

    if deformation:
        coords = draw.ellipse(50, 37, 7, 3)

        img[coords] = 0

        coords2 = draw.ellipse(50, 63, 7, 3)
        set_coords2 =  set((tuple(i) for i in np.array(coords2).T))
        set_intersection2 = set_coords2.difference(set_ellipse)
        inters2_xy = tuple(np.array(list(set_intersection2)).T)
        img[inters2_xy] = 200

        coords3 = draw.ellipse(76, 61, 7, 6)
        img[coords3] = 0

        coords_line = draw.line(82, 48, 60, 42)
        img[coords_line] = 200
        coords_line = draw.line(82, 49, 60, 43)
        img[coords_line] = 200

        set_intersection = set_disk.intersection(set_ellipse)
        inters_xy = tuple(np.array(list(set_intersection)).T)
        img[inters_xy] = 20

        N = 100
        x = np.linspace(-np.pi,np.pi, N)
        sine1D = 20.0 + (20 * np.sin(x * 5.0))
        sine1D = np.uint8(sine1D)
        sine2D = np.tile(sine1D, (N,1))
        sine2D = sine2D.T
        sine2D = np.where(img == 0, 0, sine2D)

        img += sine2D

    return img
Exemplo n.º 4
0
def test_blob_log_no_warnings():
    img = np.ones((11, 11))

    xs, ys = disk((5, 5), 2)
    img[xs, ys] = 255

    xs, ys = disk((7, 6), 2)
    img[xs, ys] = 255

    blob_log(img, max_sigma=20, num_sigma=10, threshold=.1)
Exemplo n.º 5
0
def _get_cost_arrays_for_each_route(heatmap,
                                    landmarks,
                                    raise_to_power=4,
                                    block_cost=10):
    heatmap_epi, heatmap_end = heatmap
    lv_x, lv_y = landmarks[2]
    (rv_ant_x, rv_ant_y), (rv_inf_x, rv_inf_y) = landmarks[:2]
    cost_epi = (1 - heatmap_epi)**raise_to_power
    cost_end = (1 - heatmap_end)**raise_to_power

    # outer paths (inner blocked)
    rv_mid_x, rv_mid_y = int(rv_ant_x + rv_inf_x) // 2, int(rv_ant_y +
                                                            rv_inf_y) // 2
    double_rv_mid_x, double_rv_mid_y = lv_x + (rv_mid_x - lv_x) * 2, lv_y + (
        rv_mid_y - lv_y) * 3
    # print("inner")
    _, (inner_circle_y, inner_circle_x) = _get_max_of_image_between_two_points(
        heatmap_epi, double_rv_mid_x, double_rv_mid_y, lv_x, lv_y)

    inner_circle_radius = math.sqrt((rv_ant_x - rv_inf_x)**2 +
                                    (rv_ant_y - rv_inf_y)**2) * 0.3
    rr, cc = disk(inner_circle_y,
                  inner_circle_x,
                  inner_circle_radius,
                  shape=cost_epi.shape)
    cost_outer_epi = cost_epi.copy()
    cost_outer_epi[rr, cc] = block_cost
    cost_outer_end = cost_end.copy()
    cost_outer_end[rr, cc] = block_cost

    # inner paths (outer blocked)
    double_opposite_x, double_opposite_y = lv_x - (
        rv_mid_x - lv_x) * 2, lv_y - (rv_mid_y - lv_y) * 3
    # print("outer")
    _, (outer_circle_y, outer_circle_x) = _get_max_of_image_between_two_points(
        heatmap_epi, double_opposite_x, double_opposite_y, lv_x, lv_y)

    outer_circle_radius = math.sqrt((outer_circle_x - lv_x)**2 +
                                    (outer_circle_y - lv_y)**2)
    rr, cc = disk(outer_circle_y,
                  outer_circle_x,
                  outer_circle_radius,
                  shape=cost_epi.shape)
    cost_inner_epi = cost_epi.copy()
    cost_inner_epi[rr, cc] = block_cost
    cost_inner_end = cost_end.copy()
    cost_inner_end[rr, cc] = block_cost

    # import matplotlib.pyplot as plt
    # plt.imshow(cost_outer_epi)
    # plt.show()
    # plt.imshow(cost_inner_epi)
    # plt.show()

    return cost_outer_epi, cost_inner_epi, cost_outer_end, cost_inner_end
Exemplo n.º 6
0
def test_blob_dog(dtype, threshold_type):
    r2 = math.sqrt(2)
    img = np.ones((512, 512), dtype=dtype)

    xs, ys = disk((400, 130), 5)
    img[xs, ys] = 255

    xs, ys = disk((100, 300), 25)
    img[xs, ys] = 255

    xs, ys = disk((200, 350), 45)
    img[xs, ys] = 255

    if threshold_type == 'absolute':
        threshold = 2.0
        if img.dtype.kind != 'f':
            # account for internal scaling to [0, 1] by img_as_float
            threshold /= img.ptp()
        threshold_rel = None
    elif threshold_type == 'relative':
        threshold = None
        threshold_rel = 0.5

    blobs = blob_dog(
        img,
        min_sigma=4,
        max_sigma=50,
        threshold=threshold,
        threshold_rel=threshold_rel,
    )
    radius = lambda x: r2 * x[2]
    s = sorted(blobs, key=radius)
    thresh = 5
    ratio_thresh = 0.25

    b = s[0]
    assert abs(b[0] - 400) <= thresh
    assert abs(b[1] - 130) <= thresh
    assert abs(radius(b) - 5) <= ratio_thresh * 5

    b = s[1]
    assert abs(b[0] - 100) <= thresh
    assert abs(b[1] - 300) <= thresh
    assert abs(radius(b) - 25) <= ratio_thresh * 25

    b = s[2]
    assert abs(b[0] - 200) <= thresh
    assert abs(b[1] - 350) <= thresh
    assert abs(radius(b) - 45) <= ratio_thresh * 45

    # Testing no peaks
    img_empty = np.zeros((100, 100), dtype=dtype)
    assert blob_dog(img_empty).size == 0
Exemplo n.º 7
0
def test_blob_log_no_warnings():
    img = np.ones((11, 11))

    xs, ys = disk((5, 5), 2)
    img[xs, ys] = 255

    xs, ys = disk((7, 6), 2)
    img[xs, ys] = 255

    with pytest.warns(None) as records:
        blob_log(img, max_sigma=20, num_sigma=10, threshold=.1)
    assert len(records) == 0
Exemplo n.º 8
0
def draw_nodes(img, nodes, r=2, labels=None):
    img_copy = np.copy(img)
    # source node
    if labels == None:
        for i, (x, y) in enumerate(nodes):
            rr, cc = draw.disk((x, y), r)
            img_copy[rr % img.shape[0], cc % img.shape[1]] = int(i + 1)
    else:
        for i, (x, y) in enumerate(nodes):
            rr, cc = draw.disk((x, y), r)
            img_copy[rr % img.shape[0], cc % img.shape[1]] = int(labels[i])
    return img_copy
def create_test_image(image_size=256,
                      spot_count=30,
                      spot_radius=5,
                      cloud_noise_size=4):
    """
    Generate a test image with random noise, uneven illumination and spots.
    """
    state = np.random.get_state()
    np.random.seed(314159265)  # some digits of pi

    image = np.random.normal(loc=0.25,
                             scale=0.25,
                             size=(image_size, image_size))

    for _ in range(spot_count):
        rr, cc = disk((np.random.randint(
            image.shape[0]), np.random.randint(image.shape[1])),
                      spot_radius,
                      shape=image.shape)
        image[rr, cc] = 1

    image *= np.random.normal(loc=1.0, scale=0.1, size=image.shape)

    image *= ndi.zoom(
        np.random.normal(loc=1.0,
                         scale=0.5,
                         size=(cloud_noise_size, cloud_noise_size)),
        image_size / cloud_noise_size)

    np.random.set_state(state)

    return ndi.gaussian_filter(image, sigma=2.0)
Exemplo n.º 10
0
    def createScenarioThree(self, vertiports, radius):
        '''
        Map of Scenario Three:
            - Use a image to create a nrow x ncol matrix with values of populational density of Belo Horizonte.
            - Create points for safe landing and determine a radius from those points where the aircraft could operate.  

        '''
        from skimage import io
        from skimage.util import invert
        from skimage.transform import rotate, resize
        from skimage.draw import disk
        from skimage.draw import circle_perimeter

        nrows = self.nrows
        ncols = self.ncols
        delta_d = 1 / nrows
        x = np.arange(ncols + 1) * delta_d
        y = np.arange(nrows + 1) * delta_d

        original = io.imread(
            '/home/josuehfa/System/CoreSystem/ImageLib/popCalculated.png')
        image_resized = resize(original, (nrows + 1, ncols + 1),
                               anti_aliasing=True)
        image_rotate = rotate(image_resized, 180)
        final_image = image_rotate[:, ::-1]
        final_image = np.multiply(final_image,
                                  np.where(final_image >= 0.1, 110, 1))

        self.vertiports = vertiports
        vertiports_map = np.zeros((nrows + 1, ncols + 1), dtype=np.uint8)
        for vertiport in vertiports:
            #Obtem os dados de perimetros para cada vertice
            xp, yp = circle_perimeter(int(vertiport[1] * nrows),
                                      int(vertiport[0] * nrows),
                                      int(radius * nrows))
            x_del = np.argwhere((xp <= 0) | (xp >= nrows))
            y_del = np.argwhere((yp <= 0) | (yp >= ncols))
            xp = np.delete(xp, np.concatenate((x_del, y_del), axis=0)) / nrows
            yp = np.delete(yp, np.concatenate((x_del, y_del), axis=0)) / nrows
            self.verti_perimeters.append([xp, yp])
            #Obtem a região dentro do circulo de perimetro
            xx, yy = disk((vertiport[1] * nrows, vertiport[0] * nrows),
                          radius * nrows)
            x_del = np.argwhere((xx <= 0) | (xx >= nrows))
            y_del = np.argwhere((yy <= 0) | (yy >= ncols))
            xx = np.delete(xx, np.concatenate((x_del, y_del), axis=0))
            yy = np.delete(yy, np.concatenate((x_del, y_del), axis=0))
            vertiports_map[xx, yy] = 1

        mask = vertiports_map < 1
        mapimage = final_image * vertiports_map + mask * 100
        mapimage = mapimage + 0.1

        for t in range(self.time):
            self.z_time.append(mapimage)

        self.obs_time = []
        self.z = self.z_time[0]
        self.y = y
        self.x = x
Exemplo n.º 11
0
    def get_circle_colour(self, cr, cc, r):
        rows, cols = draw.disk((cr, cc), r)

        # colour = np.mean(self.data[rows, cols], axis=(0, 1))
        colour = np.mean(self.data[rows, cols], axis=0)

        return colour
Exemplo n.º 12
0
def draw_joint(colors, pose_joints, joint_line_list, radius=2):
    im_size = (colors.shape[0], colors.shape[1])
    for f, t in joint_line_list:
        from_missing = pose_joints[0, f] == MISSING_VALUE or pose_joints[
            1, f] == MISSING_VALUE
        to_missing = pose_joints[0, t] == MISSING_VALUE or pose_joints[
            1, t] == MISSING_VALUE
        if from_missing or to_missing:
            continue
        yy, xx, val = line_aa(pose_joints[0, f], pose_joints[1, f],
                              pose_joints[0, t], pose_joints[1, t])
        yy, xx = np.clip(yy, 0, im_size[0] - 1), np.clip(xx, 0, im_size[1] - 1)
        colors[yy, xx] = np.expand_dims(val, 1) * 255
        # mask[yy, xx] = True

    colormap = labelcolormap(pose_joints.shape[1])
    for i in range(pose_joints.shape[1]):
        if pose_joints[0,
                       i] == MISSING_VALUE or pose_joints[1,
                                                          i] == MISSING_VALUE:
            continue
        yy, xx = disk((pose_joints[0, i], pose_joints[1, i]),
                      radius=radius,
                      shape=im_size)
        colors[yy, xx] = colormap[i]
    return colors
Exemplo n.º 13
0
    def get_circle_stats(self, cr, cc, r) -> PickStats:

        # import pdb; pdb.set_trace()
        rows, cols = draw.disk((cr, cc), r)

        mu = np.mean(self.fullData[rows, cols], axis=0)
        sigma = np.std(self.fullData[rows, cols], axis=0)

        ps = PickStats()
        ps.mu_r = mu[0]
        ps.mu_g = mu[1]
        ps.mu_b = mu[2]
        ps.sigma_r = sigma[0]
        ps.sigma_g = sigma[1]
        ps.sigma_b = sigma[2]

        totSum = np.sum(self.fullData[rows, cols])

        ps.perc_r = np.sum(self.fullData[rows, cols][:, 0]) / totSum
        ps.perc_g = np.sum(self.fullData[rows, cols][:, 1]) / totSum
        ps.perc_b = np.sum(self.fullData[rows, cols][:, 2]) / totSum

        ps.num_pixels = len(rows)

        return ps
Exemplo n.º 14
0
def test_blob_doh_overlap():
    img = np.ones((256, 256), dtype=np.uint8)

    xs, ys = disk((100, 100), 20)
    img[xs, ys] = 255

    xs, ys = disk((120, 100), 30)
    img[xs, ys] = 255

    blobs = blob_doh(img,
                     min_sigma=1,
                     max_sigma=60,
                     num_sigma=10,
                     threshold=.05)

    assert len(blobs) == 1
Exemplo n.º 15
0
def test_disk():
    img = np.zeros((15, 15), 'uint8')

    rr, cc = disk((7, 7), 6)
    img[rr, cc] = 1

    img_ = np.array(
        [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0],
         [0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0],
         [0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0],
         [0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0],
         [0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0],
         [0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0],
         [0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0],
         [0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0],
         [0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0],
         [0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0],
         [0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
    )

    assert_array_equal(img, img_)
Exemplo n.º 16
0
def test_blob_dog_excl_border():
    # Testing exclude border

    # image where blob is 5 px from borders, radius 5
    img = np.ones((512, 512))
    xs, ys = disk((5, 5), 5)
    img[xs, ys] = 255
    blobs = blob_dog(
        img,
        min_sigma=1.5,
        max_sigma=5,
        sigma_ratio=1.2,
    )
    assert blobs.shape[0] == 1
    b = blobs[0]
    assert b[0] == b[1] == 5, "blob should be 5 px from x and y borders"

    blobs = blob_dog(
        img,
        min_sigma=1.5,
        max_sigma=5,
        sigma_ratio=1.2,
        exclude_border=6,
    )
    msg = "zero blobs should be detected, as only blob is 5 px from border"
    assert blobs.shape[0] == 0, msg
Exemplo n.º 17
0
def create_test_image(image_size=256,
                      spot_count=30,
                      spot_radius=5,
                      cloud_noise_size=4):
    """
    Generate a test image with random noise, uneven illumination and spots.
    """
    rng = np.random.default_rng()
    image = rng.normal(loc=0.25, scale=0.25, size=(image_size, image_size))

    for _ in range(spot_count):
        rr, cc = disk(
            (rng.integers(image.shape[0]), rng.integers(image.shape[1])),
            spot_radius,
            shape=image.shape)
        image[rr, cc] = 1

    image *= rng.normal(loc=1.0, scale=0.1, size=image.shape)

    image *= ndi.zoom(
        rng.normal(loc=1.0,
                   scale=0.5,
                   size=(cloud_noise_size, cloud_noise_size)),
        image_size / cloud_noise_size)

    return ndi.gaussian_filter(image, sigma=2.0)
Exemplo n.º 18
0
def get_simulated_disc(square_size, disc_radius):
    """Create a uniform disc for correlating with the experimental square.

    Parameters
    ----------
    square size : int
        (even) - size of the bounding box
    disc_radius : int
        radius of the disc

    Returns
    -------
    arr: np.array()
        Upsampled copy of the simulated disc as a numpy array

    """

    if square_size % 2 != 0:
        raise ValueError("'square_size' must be an even number")

    ss = int(square_size)
    arr = np.zeros((ss, ss))
    rr, cc = draw.disk((int(ss / 2), int(ss / 2)),
                       radius=disc_radius,
                       shape=arr.shape)  # is the thin disc a good idea
    arr[rr, cc] = 1
    return arr
    def _draw_passengers(self, location, color):
        passenger_radius = Passenger_SIZE * self.grid_size

        pos_x, pos_y = self._get_screen_pos(location[0], location[1])
        pos_x += int(self.grid_size / 2)
        pos_y += int(self.grid_size / 2)
        rr, cc = disk((pos_x, pos_y), passenger_radius)
        self.rgb_observation[rr, cc, :] = list(color)
Exemplo n.º 20
0
        def _cost_annular_disk(params):
            x0, y0, r, inr = params
            coords = draw.disk((x0, y0), r, shape=img.shape)
            template = np.zeros_like(img)
            template[coords] = 1

            coords2 = draw.disk((x0, y0), inr, shape=img.shape)
            template2 = np.zeros_like(img)
            template2[coords2] = 1
            template -= template2

            if display:
                self._dispnobl(template + img, fign)

            merit_fcn = np.sum((template - img)**2)

            return np.sqrt(merit_fcn)
Exemplo n.º 21
0
 def _cost_disk(params):
     x0, y0, r = params
     coords = draw.disk((x0, y0), r, shape=img.shape)
     template = np.zeros_like(img)
     template[coords] = 1
     if display:
         self._dispnobl(template + img, fign)
     return -np.sum((template > 0) & (img > 0))
Exemplo n.º 22
0
    def get_colour_display(self, cr, cc, r):
        # colour = self.get_circle_colour(cr, cc, r)
        ps = self.get_circle_stats(cr, cc, r)
        colour = np.array([ps.mu_r, ps.mu_g, ps.mu_b])
        ImgLogger.log("Got mean colour for display: ", colour)

        rows, cols = draw.disk((cr, cc), r)

        im = np.full((2 * r, 2 * r, 3), 255, dtype=self.fullData.dtype)

        irows, icols = draw.disk((r, r), r)

        im[irows, icols] = self.fullData[rows, cols]

        im[:, :r] = colour

        return DataImage(im)
Exemplo n.º 23
0
def test_blob_doh_log_scale():
    img = np.ones((512, 512), dtype=np.uint8)

    xs, ys = disk((400, 130), 20)
    img[xs, ys] = 255

    xs, ys = disk((460, 50), 30)
    img[xs, ys] = 255

    xs, ys = disk((100, 300), 40)
    img[xs, ys] = 255

    xs, ys = disk((200, 350), 50)
    img[xs, ys] = 255

    blobs = blob_doh(
        img,
        min_sigma=1,
        max_sigma=60,
        num_sigma=10,
        log_scale=True,
        threshold=.05)

    radius = lambda x: x[2]
    s = sorted(blobs, key=radius)
    thresh = 10

    b = s[0]
    assert abs(b[0] - 400) <= thresh
    assert abs(b[1] - 130) <= thresh
    assert abs(radius(b) - 20) <= thresh

    b = s[2]
    assert abs(b[0] - 460) <= thresh
    assert abs(b[1] - 50) <= thresh
    assert abs(radius(b) - 30) <= thresh

    b = s[1]
    assert abs(b[0] - 100) <= thresh
    assert abs(b[1] - 300) <= thresh
    assert abs(radius(b) - 40) <= thresh

    b = s[3]
    assert abs(b[0] - 200) <= thresh
    assert abs(b[1] - 350) <= thresh
    assert abs(radius(b) - 50) <= thresh
Exemplo n.º 24
0
    def get_snr(frame, y, x, fwhm, fmerit):
        """
        """
        if fmerit == 'max':
            yy, xx = disk((y, x), fwhm / 2.)
            res = [
                snr(frame, (x_, y_),
                    fwhm,
                    plot=False,
                    verbose=False,
                    exclude_negative_lobes=exclude_negative_lobes,
                    full_output=True) for y_, x_ in zip(yy, xx)
            ]
            snr_pixels = np.array(res, dtype=object)[:, -1]
            fluxes = np.array(res, dtype=object)[:, 2]
            argm = np.argmax(snr_pixels)
            # integrated fluxes for the max snr
            return np.max(snr_pixels), fluxes[argm]

        elif fmerit == 'px':
            res = snr(frame, (x, y),
                      fwhm,
                      plot=False,
                      verbose=False,
                      exclude_negative_lobes=exclude_negative_lobes,
                      full_output=True)
            snrpx = res[-1]
            fluxpx = np.array(res, dtype=object)[2]
            # integrated fluxes for the given px
            return snrpx, fluxpx

        elif fmerit == 'mean':
            yy, xx = disk((y, x), fwhm / 2.)
            res = [
                snr(frame, (x_, y_),
                    fwhm,
                    plot=False,
                    verbose=False,
                    exclude_negative_lobes=exclude_negative_lobes,
                    full_output=True) for y_, x_ in zip(yy, xx)
            ]
            snr_pixels = np.array(res, dtype=object)[:, -1]
            fluxes = np.array(res, dtype=object)[:, 2]
            # mean of the integrated fluxes (shifting the aperture)
            return np.mean(snr_pixels), np.mean(fluxes)
Exemplo n.º 25
0
 def move(self, img, x, y):
     """Moving brush through canvas"""
     old_x, old_y = self.press_pos
     for c_x, c_y in zip(*disk((old_x, old_y), self.size, shape=img.shape)):
         end_x = min(x + (c_x - old_x), img.shape[0] - 1)
         end_y = min(y + (c_y - old_y), img.shape[1] - 1)
         row_map, column_map = line(c_x, c_y, end_x, end_y)
         img[row_map, column_map] = self.color
     self.press_pos = (x, y)
    def _draw_agent(self, location, color):
        agent_radius = AGENT_SIZE * self.grid_size
        pos_x, pos_y = self._get_screen_pos(location[0], location[1])
        # move to grid center
        pos_x += int(self.grid_size / 2)
        pos_y += int(self.grid_size / 2)

        rr, cc = disk((pos_x, pos_y), agent_radius)
        self.rgb_observation[rr, cc, :] = list(color)
Exemplo n.º 27
0
def get_circles(img, diameter, thresh): 
	selem = np.ones((diameter+1, diameter+1), dtype=np.uint8)
	rr, cc = disk((diameter//2, diameter//2), diameter//2)
	selem[rr,cc] = 1
	img_cpy = img.copy()
	selem = np.array([
		[1,1,1],
		[1,1,1],
		[1,1,1]
	])
	img_cpy = binary_erosion(img_cpy, selem=selem)
	img_cpy = binary_erosion(img_cpy, selem=selem)
	img_cpy = binary_erosion(img_cpy, selem=selem)
	img_cpy = binary_erosion(img_cpy, selem=selem)




	result = convolve2d(np.uint8(img_cpy), selem, mode='same')  + convolve2d(np.uint8(1-img_cpy), 1-selem, mode='same')
	# print(np.max(result), (selem.shape[0] * selem.shape[1]), diameter)
	# result = result / (selem.shape[0] * selem.shape[1])
	
	if(np.max(result) > 0):
		result = result / np.max(result)

	ij = np.where(result >= thresh)
	x, y = ij[::-1]
	# circlesArrX = x
	# circlesArrY = y

	# Combine very close circles to one circle
	circlesArrX = []
	circlesArrY = []
	used = np.zeros(len(x), dtype=np.uint8)
	for i in range(len(x)):
		if(used[i] == 1):
			continue
		used[i] = 1
		accumulator = []
		accumulator.append(i)
		for j in range(len(x)):
			if(used[j] == 1):
				continue
			if abs(x[i] - x[j]) <= diameter and abs(y[i] - y[j]) <= diameter:
				used[j] = 1
				accumulator.append(j)
		centerX = 0
		centerY = 0
		for k in accumulator:
			centerX += x[k]
			centerY += y[k]
		centerX /= len(accumulator)
		centerY /= len(accumulator)
		circlesArrX.append(centerX)
		circlesArrY.append(centerY)

	return np.array(circlesArrX), np.array(circlesArrY)
Exemplo n.º 28
0
def test_multiotsu_output():
    image = np.zeros((100, 100), dtype='int')
    coords = [(25, 25), (50, 50), (75, 75)]
    values = [64, 128, 192]
    for coor, val in zip(coords, values):
        rr, cc = disk(coor, 20)
        image[rr, cc] = val
    thresholds = [0, 64, 128]
    assert np.array_equal(thresholds, threshold_multiotsu(image, classes=4))
Exemplo n.º 29
0
 def binary_draw(self, grid):
     # print(self.x, self.y, self.radius, grid.shape)
     # rr, cc = draw.circle(self.x, self.y, radius=self.radius, shape=grid.shape)
     # x and y are reversed as numpy array first index correspond to y
     rr, cc = draw.disk((self.y, self.x),
                        radius=self.radius,
                        shape=grid.shape)
     grid[rr, cc] = 1
     return grid
Exemplo n.º 30
0
def exp_disc():
    ss, disc_radius, upsample_factor = int(60), 6, 10

    arr = np.zeros((ss, ss))
    rr, cc = draw.disk((int(ss / 2) + 20, int(ss / 2) - 10),
                       radius=disc_radius,
                       shape=arr.shape)
    arr[rr, cc] = 1
    return arr