Esempio n. 1
0
def make_difference_image(context: Context, raw_frame: Frame,
                          list_difference: list, list_predictive: list):
    difference_vectors = []
    buffer = 5
    block_size = context.block_size
    bleed = context.bleed

    # first make a 'bleeded' version of input_frame
    # so we can preform numpy calculations w.o having to catch
    bleed_frame = raw_frame.create_bleeded_image(buffer)

    # if there are no items in 'differences' but have list_predictives
    # then the two frames are identical, so no differences image needed.
    if not list_difference and list_predictive:
        out_image = Frame()
        out_image.create_new(1, 1)
        return out_image

    # if there are neither any predictive or inversions
    # then the frame is a brand new frame with no resemblence to previous frame.
    # in this case copy the entire frame over
    if not list_difference and not list_predictive:
        out_image = Frame()
        out_image.create_new(raw_frame.width, raw_frame.height)
        out_image.copy_image(raw_frame)
        return out_image

    # turn the list of differences into a list of vectors
    for x in range(int(len(list_difference) / 4)):
        difference_vectors.append(
            DisplacementVector(int(list_difference[x * 4]),
                               int(list_difference[x * 4 + 1]),
                               int(list_difference[x * 4 + 2]),
                               int(list_difference[x * 4 + 3])))

    # size of output image is determined based off how many differences there are
    image_size = int(math.sqrt(len(list_difference) / 4) + 1) * (block_size +
                                                                 bleed * 2)
    out_image = Frame()
    out_image.create_new(image_size, image_size)

    # move every block from the complete frame to the differences frame using vectors.
    for vector in difference_vectors:
        out_image.copy_block(bleed_frame, block_size + bleed * 2,
                             vector.x_1 + buffer - bleed,
                             vector.y_1 + buffer + -bleed,
                             vector.x_2 * (block_size + bleed * 2),
                             vector.y_2 * (block_size + bleed * 2))

    return out_image
Esempio n. 2
0
    def make_residual_image(context: Context, raw_frame: Frame,
                            list_residual: list, list_predictive: list):
        """
        This section can best be explained through pictures. A visual way of expressing what 'make_residual_image'
        is doing is this section in the wiki.

        https://github.com/aka-katto/dandere2x/wiki/How-Dandere2x-Works#observation_3

        Inputs:
            - frame(x)
            - Residual vectors mapping frame(x)_residual -> frame(x)

        Output:
            - frame(x)_residual
        """

        # Some conditions to check before making a residual image, in both cases, we don't need to do any actual
        # processing in the function call, if these conditions hold true.
        if not list_residual and list_predictive:
            """
            If there are no items in 'list_residuals' but have list_predictives then the two frames are identical,
            so no residual image needed.
            """
            residual_image = Frame()
            residual_image.create_new(1, 1)
            return residual_image

        if not list_residual and not list_predictive:
            """ 
            If there are neither any predictive or inversions, then the frame is a brand new frame with no resemblence
            to previous frame. In this case, copy the entire frame over.
            """
            residual_image = Frame()
            residual_image.create_new(raw_frame.width, raw_frame.height)
            residual_image.copy_image(raw_frame)
            return residual_image

        buffer = 5
        block_size = context.block_size
        bleed = context.bleed
        """
        First make a 'bleeded' version of input_frame, as we need to create a buffer in the event the 'bleed'
        ends up going out of bounds. In other words, crop the image into an even larger image, so that if if we need
        to access out of bounds pixels, and place black pixels where it would be out of bounds. 
        """
        bleed_frame = raw_frame.create_bleeded_image(buffer)

        # size of output image is determined based off how many residuals there are
        image_size = int(math.sqrt(len(list_residual) / 4) + 1) * (block_size +
                                                                   bleed * 2)
        residual_image = Frame()
        residual_image.create_new(image_size, image_size)

        for x in range(int(len(list_residual) / 4)):
            # load every element in the list into a vector
            vector = DisplacementVector(int(list_residual[x * 4 + 0]),
                                        int(list_residual[x * 4 + 1]),
                                        int(list_residual[x * 4 + 2]),
                                        int(list_residual[x * 4 + 3]))

            # apply that vector to the image by copying over their respective blocks.
            residual_image.copy_block(bleed_frame, block_size + bleed * 2,
                                      vector.x_1 + buffer - bleed,
                                      vector.y_1 + buffer + -bleed,
                                      vector.x_2 * (block_size + bleed * 2),
                                      vector.y_2 * (block_size + bleed * 2))

        return residual_image
Esempio n. 3
0
def make_residual_image(context: Context, raw_frame: Frame,
                        list_residual: list, list_predictive: list):
    """
    This section can best be explained through pictures. A visual way of expressing what 'make_residual_image'
    is doing is this section in the wiki.

    https://github.com/aka-katto/dandere2x/wiki/How-Dandere2x-Works#observation_3

    Inputs:
        - frame(x)
        - Residual vectors mapping frame(x)_residual -> frame(x)

    Output:
        - frame(x)_residual
    """

    residual_vectors = []
    buffer = 5
    block_size = context.block_size
    bleed = context.bleed

    # first make a 'bleeded' version of input_frame, as we need to create a buffer in the event the 'bleed'
    # ends up going out of bounds.
    bleed_frame = raw_frame.create_bleeded_image(buffer)

    # if there are no items in 'list_residuals' but have list_predictives
    # then the two frames are identical, so no residual image needed.
    if not list_residual and list_predictive:
        out_image = Frame()
        out_image.create_new(1, 1)
        return out_image

    # if there are neither any predictive or inversions
    # then the frame is a brand new frame with no resemblence to previous frame.
    # in this case copy the entire frame over
    if not list_residual and not list_predictive:
        out_image = Frame()
        out_image.create_new(raw_frame.width, raw_frame.height)
        out_image.copy_image(raw_frame)
        return out_image

    # turn the list of residuals into a list of vectors
    for x in range(int(len(list_residual) / 4)):
        residual_vectors.append(
            DisplacementVector(int(list_residual[x * 4]),
                               int(list_residual[x * 4 + 1]),
                               int(list_residual[x * 4 + 2]),
                               int(list_residual[x * 4 + 3])))

    # size of output image is determined based off how many residuals there are
    image_size = int(math.sqrt(len(list_residual) / 4) + 1) * (block_size +
                                                               bleed * 2)
    out_image = Frame()
    out_image.create_new(image_size, image_size)

    # move every block from the complete frame to the residual frame using vectors.
    for vector in residual_vectors:
        out_image.copy_block(bleed_frame, block_size + bleed * 2,
                             vector.x_1 + buffer - bleed,
                             vector.y_1 + buffer + -bleed,
                             vector.x_2 * (block_size + bleed * 2),
                             vector.y_2 * (block_size + bleed * 2))

    return out_image