Ejemplo n.º 1
0
def particles(image_id,
              npart,
              coord,
              center_arr,
              img,
              sigma,
              Nx,
              Ny,
              rad=0.3,
              edgy=0):
    all_part_mask = np.zeros((Ny, Nx))
    #global sub_mask_details
    #global annotation_id
    for j in range(npart):
        center = center_arr[j]
        a = get_random_points(n=4, scale=30) + center
        s, c = get_bezier_curve(a, rad=rad, edgy=edgy)
        Density = rtnorm(0, 1, 0.92, 0.3)

        p = path.Path(c)
        particle_pixl = p.contains_points(coord)
        particle_pixl = np.reshape(particle_pixl, (Ny, Nx)) - 0.0
        particle = particle_pixl * Density

        img = np.maximum(img, particle)
        all_part_mask = np.maximum(all_part_mask, particle_pixl)
        """
        sub_mask_details['image_id'].append(image_id+1)
        sub_mask_details['category_id'].append(2)
        sub_mask_details['pixl_arr'].append(particle_pixl)
        sub_mask_details['id'].append(annotation_id)
        annotation_id += 1
        """
    return img, all_part_mask
Ejemplo n.º 2
0
    def fiber(self, nfiber, center_arr):
        alpha = np.zeros((nfiber, 1))
        L = np.zeros((nfiber, 1))
        W = np.zeros((nfiber, 1))
        Density = np.zeros((nfiber, 1))

        all_fiber_mask = np.zeros((self.Ny, self.Nx))

        for i in range(nfiber):
            alpha[i] = np.random.uniform(-math.pi / 2, math.pi / 2)
            L[i] = np.random.normal(40, 5)  # fiber length mu=40, sd = 5
            W[i] = 4  # constant fiber width 4
            Density[i] = rtnorm(0, 1, 0.92, 0.3)

        for i in range(nfiber):
            #four vertices of a single fiber
            p1 = np.vstack((-W[i] / 2, -L[i] / 2))
            p2 = np.vstack((W[i] / 2, -L[i] / 2))
            p3 = np.vstack((W[i] / 2, L[i] / 2))
            p4 = np.vstack((-W[i] / 2, L[i] / 2))

            theta = alpha[i]

            R = np.array([[math.cos(theta), -math.sin(theta)],
                          [math.sin(theta), math.cos(theta)]])
            center = np.expand_dims(center_arr[i], axis=1)

            # rotation of vertices and move to center
            q1 = np.dot(R, p1) + center
            q2 = np.dot(R, p2) + center
            q3 = np.dot(R, p3) + center
            q4 = np.dot(R, p4) + center

            V_xy = np.hstack((q1, q2, q3, q4))
            p = path.Path(np.transpose(V_xy))
            fiber_pixl = p.contains_points(self.coord)
            fiber_pixl = np.reshape(fiber_pixl, (self.Ny, self.Nx)) - 0.0
            fiber = fiber_pixl * Density[i]

            self.img = np.maximum(self.img, fiber)
            all_fiber_mask = np.maximum(
                all_fiber_mask,
                fiber_pixl)  # mask of all fibers in a single image

            self.sub_mask_details['category_id'].append(
                1)  # 1 is for fiber category
            self.sub_mask_details['pixl_arr'].append(fiber_pixl)

        return self.img, all_fiber_mask  # at this point self.img contains all the fibers per image
Ejemplo n.º 3
0
def fiber(image_id, nfiber, coord, center_arr, img, sigma, Nx,
          Ny):  # tag changed to image_id
    #global sub_mask_details
    #global annotation_id
    alpha = np.zeros((nfiber, 1))
    L = np.zeros((nfiber, 1))
    W = np.zeros((nfiber, 1))
    Density = np.zeros((nfiber, 1))

    for i in range(nfiber):
        alpha[i] = np.random.uniform(-math.pi / 2, math.pi / 2)
        L[i] = np.random.normal(40, 5)
        W[i] = 2 * 2
        Density[i] = rtnorm(0, 1, 0.92, 0.3)

    all_fiber_mask = np.zeros((Ny, Nx))

    for i in range(nfiber):
        p1 = np.vstack((-W[i] / 2, -L[i] / 2))
        p2 = np.vstack((W[i] / 2, -L[i] / 2))
        p3 = np.vstack((W[i] / 2, L[i] / 2))
        p4 = np.vstack((-W[i] / 2, L[i] / 2))

        theta = alpha[i]
        R = np.array([[math.cos(theta), -math.sin(theta)],
                      [math.sin(theta), math.cos(theta)]])
        center = np.expand_dims(center_arr[i], axis=1)
        q1 = np.dot(R, p1) + center
        q2 = np.dot(R, p2) + center
        q3 = np.dot(R, p3) + center
        q4 = np.dot(R, p4) + center

        V_xy = np.hstack((q1, q2, q3, q4))
        p = path.Path(np.transpose(V_xy))
        fiber_pixl = p.contains_points(coord)
        fiber_pixl = np.reshape(fiber_pixl, (Ny, Nx)) - 0.0
        fiber = fiber_pixl * Density[i]

        img = np.maximum(img, fiber)
        all_fiber_mask = np.maximum(all_fiber_mask, fiber_pixl)
        """
        sub_mask_details['image_id'].append(image_id+1)
        sub_mask_details['category_id'].append(1)
        sub_mask_details['pixl_arr'].append(fiber_pixl)
        sub_mask_details['id'].append(annotation_id)
        annotation_id += 1
        """
    return img, all_fiber_mask
Ejemplo n.º 4
0
    def particles(self, npart, center_arr, rad=0.3, edgy=0):
        all_part_mask = np.zeros((self.Ny, self.Nx))
        for j in range(npart):
            center = center_arr[j]
            a = get_random_points(n=4, scale=30) + center
            s, c = get_bezier_curve(a, rad=rad, edgy=edgy)
            Density = rtnorm(0, 1, 0.92, 0.3)

            p = path.Path(c)
            particle_pixl = p.contains_points(self.coord)
            particle_pixl = np.reshape(particle_pixl, (self.Ny, self.Nx)) - 0.0
            particle = particle_pixl * Density

            self.img = np.maximum(self.img, particle)
            all_part_mask = np.maximum(all_part_mask, particle_pixl)

            self.sub_mask_details['category_id'].append(
                2)  # 2 is for particle category
            self.sub_mask_details['pixl_arr'].append(particle_pixl)

        return self.img, all_part_mask, self.sub_mask_details  # at this point self.img contains all fibers & particles per image