def connect_sticks_to_polyline_by_inline(masks_orig, class_label: int):
    """
    Iterates on the masks cube which holds the
    contour of the instance and connects the polylines
    """
    masks = masks_orig.copy()

    for slice_index in range(masks_orig.shape[0]):
        if masks_orig[slice_index, :, :].sum() != 0:
            z, y = masks_orig[slice_index, :, :].nonzero()

            # Sort the coordinates depth-wise using
            # Decorate, Sort, Undecorate approach
            z, y = (list(t) for t in zip(*sorted(zip(z, y))))

            # Connect the corresponding coordinates
            for p_index in range(len(z) - 1):
                between_points_bresenham = set(
                    rg.bresenham_lines(
                        ((slice_index, z[p_index], y[p_index]),
                         (slice_index, z[p_index + 1], y[p_index + 1])),
                        closed=True))

                for point in between_points_bresenham:
                    masks[point[0], point[1], point[2]] = class_label

    return masks
示例#2
0
 def generate_triangle(self):
     # coordinates for down left corner
     rand_col_dl = random.randint(OFFSET,
                                  BACKGROUND_SIZE - (IMAGE_SIZE + OFFSET))
     rand_row_dl = random.randint(OFFSET + IMAGE_SIZE,
                                  BACKGROUND_SIZE - OFFSET)
     dl = (rand_row_dl, rand_col_dl)
     # coordinates, down right
     row_dr = rand_row_dl
     col_dr = rand_col_dl + IMAGE_SIZE
     dr = (row_dr, col_dr)
     # coordinates, top point
     rand_col_top = random.randint(OFFSET, BACKGROUND_SIZE - (OFFSET))
     row_top = rand_row_dl - IMAGE_SIZE
     top = (row_top, rand_col_top)
     """ self.image[rand_row_dl, rand_col_dl:col_dr] = 1.0 """
     # vectors
     coords = set(rg.bresenham_lines((dl, dr, top), closed=True))
     for r, w in coords:
         self.image[r, w] = 1.0
def process_fault_instances_by_inline(fault_instance, volume_shape: tuple,
                                      class_label: int):
    """
    Connects the corresponding points between sticks
    to form a raw unfilled 3d-curve. Processes the instance
    by inline direction.
    """

    # Create empty cube for storing fault instance points
    print("Creating empty mask cube...")
    mask = np.zeros(volume_shape, dtype=np.int32)

    # Split fold by sticks
    sticks_split = split_fault_instances_by_sticks(fault_instance)

    for stick_split_index in range(len(sticks_split) - 1):
        curr_split = sticks_split[stick_split_index]
        next_split = sticks_split[stick_split_index + 1]

        # Sort splits by depth in both sticks
        curr_split = curr_split.sort_values('z', ascending=True)
        next_split = next_split.sort_values('z', ascending=True)

        # Connect the upper bounds of the inter-plane
        x_c_min, z_c_min, y_c_min = curr_split.iloc[0][
            'inline'], curr_split.iloc[0]['z'], curr_split.iloc[0]['crossline']
        x_n_min, z_n_min, y_n_min = next_split.iloc[0][
            'inline'], next_split.iloc[0]['z'], next_split.iloc[0]['crossline']
        between_points_bresenham = set(
            rg.bresenham_lines(
                ((x_c_min, z_c_min, y_c_min), (x_n_min, z_n_min, y_n_min)),
                closed=True))
        for point in between_points_bresenham:
            mask[point[0], point[1], point[2]] = class_label

        # Connect the lower bounds of the inter-plane
        x_c_max, z_c_max, y_c_max = curr_split.iloc[-1][
            'inline'], curr_split.iloc[-1]['z'], curr_split.iloc[-1][
                'crossline']
        x_n_max, z_n_max, y_n_max = next_split.iloc[-1][
            'inline'], next_split.iloc[-1]['z'], next_split.iloc[-1][
                'crossline']
        between_points_bresenham = set(
            rg.bresenham_lines(
                ((x_c_max, z_c_max, y_c_max), (x_n_max, z_n_max, y_n_max)),
                closed=True))
        for point in between_points_bresenham:
            mask[point[0], point[1], point[2]] = class_label

        # Connect intermediate nodes with edges (lines) with
        # a minimum weight
        # Since we may have different number of nodes left in
        # two sticks we must select minimum number from the two
        # and iterate over them
        for st_index in range(1, min(len(next_split), len(curr_split)) - 1):
            x_n, z_n, y_n = next_split.iloc[st_index][
                'inline'], next_split.iloc[st_index]['z'], next_split.iloc[
                    st_index]['crossline']
            x_c, z_c, y_c = curr_split.iloc[st_index][
                'inline'], curr_split.iloc[st_index]['z'], curr_split.iloc[
                    st_index]['crossline']

            between_points_bresenham = set(
                rg.bresenham_lines(((x_n, z_n, y_n), (x_c, z_c, y_c)),
                                   closed=True))

            for point in between_points_bresenham:
                mask[point[0], point[1], point[2]] = class_label

    return mask