def draw_row_view(image, coordinate, click_settings, should_copy=False):
    """

    :param image:           the image data to work on
    :param coordinate:      the coordinate where to draw around as tuple (x,y)
    :param click_settings:  the clickSettings
    :param should_copy:     Indicates if the image should be copied b4
    :return:                the manipulated image data
    """

    im = None
    if should_copy:
        im = image.copy()
    else:
        im = image

    x = coordinate[0]

    minimal_x_half = click_settings.minimal_width + click_settings.grad_radius

    im = drw.draw_line(im, (max(0, x - minimal_x_half), 0),
                       (max(0, x - minimal_x_half), image.shape[0] - 1),
                       (0, 0, 0, 1))
    im = drw.draw_line(
        im, (min(image.shape[1] - 1, x + minimal_x_half), 0),
        (min(image.shape[1] - 1, x + minimal_x_half), image.shape[0] - 1),
        (0, 0, 0, 1))

    return im
Esempio n. 2
0
def draw_line_view(image, coordinate, click_settings, should_copy=False):
    """

    :param image:           the image data to work on
    :param coordinate:      the coordinate where to draw around as tuple (x,y)
    :param click_settings:  the clickSettings
    :param should_copy:     Indicates if the image should be copied b4
    :return:                the manipulated image data
    """

    im = utils.shallow_or_deep(image, should_copy)

    y = coordinate[1]

    minimal_y_half = click_settings.minimal_height + click_settings.grad_radius

    im = drw.draw_line(im, (0, max(0, y - minimal_y_half)),
                       (image.shape[1] - 1, max(0, y - minimal_y_half)),
                       (0, 0, 0, 1))

    im = drw.draw_line(
        im, (0, min(image.shape[0] - 1, y + minimal_y_half)),
        (image.shape[1] - 1, min(image.shape[0] - 1, y + minimal_y_half)),
        (0, 0, 0, 1))

    return im
def draw_horizontal_needleman_wunsch_line_diagram(image,
                                                  rounding,
                                                  coordinate_buffer_a,
                                                  coordinate_buffer_b,
                                                  should_copy=False):
    """

    :param image:                   image data to draw on
    :param rounding:                rounding value
    :param coordinate_buffer_a:     coordinates of the first buffer [(x,y)]
    :param coordinate_buffer_b:     coordinates of the second buffer [(x,y)]
    :param should_copy:             Indicates if the image should be copied b4
    :return:                        the updated image, the buffer with needleman wunsch data (dictionary with "kind", "data")
    """

    im = None
    if should_copy:
        im = image.copy()
    else:
        im = image

    buffer_nw_a = []
    buffer_nw_b = []

    rounding_half = rounding / 2

    for i in range(0, len(coordinate_buffer_a)):
        buffer_nw_a.append(
            nw.round_with_offset(rounding_half, rounding,
                                 coordinate_buffer_a[i][0]))

    for i in range(0, len(coordinate_buffer_b)):
        buffer_nw_b.append(
            nw.round_with_offset(rounding_half, rounding,
                                 coordinate_buffer_b[i][0]))

    solution = nw.needleman_wunsch(buffer_nw_a, buffer_nw_b)

    color = (0, 0, 0, 1)

    current_x = solution[0]["data"]
    current_y = 3

    for i in range(0, len(solution)):
        if solution[i]["kind"] == "delete" or solution[i][
                "kind"] == "missmatch":
            continue
        x = solution[i]["data"]
        im = drw.draw_line(im, (current_x, current_y), (x, current_y), color)
        current_x = x
        im = drw.draw_line(im, (current_x, current_y),
                           (current_x, current_y + 3), color)
        current_y += 3

    return im, solution
def draw_vertical_combined_needleman_wunsch_line_diagram(
        image, rounding, buffers, should_copy=False):
    """

    :param image:                   image data to draw on
    :param rounding:                rounding value
    :param buffers:                 a buffer of coordinate lists
    :param should_copy:             Indicates if the image should be copied b4
    :return:                        the updated image data and the solution of the needleman wunsch
    """

    im = None
    if should_copy:
        im = image.copy()
    else:
        im = image

    buffers_needle = []

    rounding_half = rounding / 2

    for i in range(0, len(buffers)):
        tmp_buffer = []
        for j in range(0, len(buffers[i])):
            tmp_buffer.append(
                nw.round_with_offset(rounding_half, rounding,
                                     buffers[i][j][1]))
        buffers_needle.append(tmp_buffer)

    current_solution = buffers_needle[0]
    for i in range(1, len(buffers_needle)):
        sol_buffer = nw.needleman_wunsch(buffers_needle[i], current_solution)
        current_solution = nw.to_usable_buffer(sol_buffer)

    color = (0, 0, 0, 1)

    current_x = 3
    current_y = current_solution[0]

    for i in range(0, len(current_solution)):
        y = current_solution[i]
        im = drw.draw_line(im, (current_x, current_y), (current_x, y), color)
        current_y = y
        im = drw.draw_line(im, (current_x, current_y),
                           (current_x + 3, current_y), color)
        current_x += 3

    return im, current_solution
def draw_semantic_classifier(image, semantic_classifier, should_copy=False):
    """
    :param image:                   image data to draw on
    :param semantic_classifier:     the semantic classifer object to draw
    :param should_copy:             Indicates if the image should be copied b4
    :return:                        the updated image data and the solution of the needleman wunsch

    """
    im = None
    if should_copy:
        im = image.copy()
    else:
        im = image

    semantic_fields = semantic_classifier.get_semantic_fields()

    for field in semantic_fields:
        if field[1] < im.shape[0]:
            im = drw.draw_line(im, (0, field[1]),
                               (image.shape[1] - 1, field[1]), (0, 0, 0, 1))
        x = image.shape[1] - 12
        y = field[0] + 3

        drw.draw_letter(im, (x, y), field[2][0])

    return im
def draw_horizontal_line_diagram(image,
                                 min_idx,
                                 max_idx,
                                 coordinates,
                                 should_copy=False):
    """
    :param image:           the image data to work with
    :param min_idx:         the index where to start drawing the heatmap
    :param max_idx:         the index where to stop drawing the heatmap exclusive
    :param coordinates:     an array of coordinates (x,y)
    :param should_copy:     Indicates if the image should be copied b4
    :return:                the modified image data
    """

    im = None
    if should_copy:
        im = image.copy()
    else:
        im = image

    min_idx = max(0, min_idx)

    if max_idx < min_idx:
        max_idx = min_idx + 1
    max_idx = min(len(coordinates), max_idx)

    # a number to start, 3 otherwise would overlap with the start
    current_y = 3
    current_x = coordinates[min_idx][0]

    for i in range(min_idx, max_idx):
        x = coordinates[i][0]
        im = drw.draw_line(im, (current_x, current_y), (x, current_y),
                           (0, 0, 0, 1))
        current_x = x
        im = drw.draw_line(im, (current_x, current_y),
                           (current_x, current_y + 3), (0, 0, 0, 1))
        current_y += 3

    return im
Esempio n. 7
0
def draw_horizontal_line_diagram(image,
                                 coordinates,
                                 min_idx=None,
                                 max_idx=None,
                                 should_copy=False):
    """
    :param image:           the image data to work with
    :param min_idx:         the index where to start drawing the heatmap
    :param max_idx:         the index where to stop drawing the heatmap exclusive
    :param coordinates:     an array of coordinates (x,y)
    :param should_copy:     Indicates if the image should be copied b4
    :return:                the modified image data
    """

    im = utils.shallow_or_deep(image, should_copy)

    min_idx = utils.get_normal_on_none(min_idx, 0)
    min_idx = utils.clamp(min_idx, 0, len(coordinates) - 1)

    max_idx = utils.get_normal_on_none(max_idx, len(coordinates))
    max_idx = utils.clamp(max_idx, 1, len(coordinates))

    # a number to start, 3 otherwise would overlap with the start
    current_y = 3
    current_x = coordinates[min_idx][0]

    for i in range(min_idx, max_idx):
        x = coordinates[i][0]
        im = drw.draw_line(im, (current_x, current_y), (x, current_y),
                           (0, 0, 0, 1))
        current_x = x
        im = drw.draw_line(im, (current_x, current_y),
                           (current_x, current_y + 3), (0, 0, 0, 1))
        current_y += 3

    return im