def make_merge_image(workspace, block_size, scale_factor, bleed, frame_inversion, frame_base, list_predictive, list_differences, list_corrections, output_location): logger = logging.getLogger(__name__) predictive_vectors = [] difference_vectors = [] out_image = Frame() out_image.create_new(frame_base.width, frame_base.height) scale_factor = int(scale_factor) if not list_predictive and not list_differences: logger.info("list_predictive and not list_differences: true") logger.info("Saving inversion image..") out_image.copy_image(frame_inversion) out_image.save_image(output_location) return if list_predictive and not list_differences: logger.info("list_predictive and not list_differences") logger.info("saving last image..") out_image.copy_image(frame_base) out_image.save_image(output_location) return # load list into vector displacements for x in range(int(len(list_differences) / 4)): difference_vectors.append(DisplacementVector(int(list_differences[x * 4]), int(list_differences[x * 4 + 1]), int(list_differences[x * 4 + 2]), int(list_differences[x * 4 + 3]))) for x in range(int(len(list_predictive) / 4)): predictive_vectors.append(DisplacementVector(int(list_predictive[x * 4]), int(list_predictive[x * 4 + 1]), int(list_predictive[x * 4 + 2]), int(list_predictive[x * 4 + 3]))) # copy over predictive vectors into new image for vector in predictive_vectors: out_image.copy_block(frame_base, block_size * scale_factor, vector.x_2 * scale_factor, vector.y_2 * scale_factor, vector.x_1 * scale_factor, vector.y_1 * scale_factor) # copy over inversion vectors (the difference images) into new image for vector in difference_vectors: out_image.copy_block(frame_inversion, block_size * scale_factor, (vector.x_2 * (block_size + bleed * 2)) * scale_factor + (bleed * scale_factor), (vector.y_2 * (block_size + bleed * 2)) * scale_factor + (bleed * scale_factor), vector.x_1 * scale_factor, vector.y_1 * scale_factor) # Correct the image before saving. out_image = correct_image(4, scale_factor, out_image, list_corrections) out_image.save_image(output_location)
def debug_image(block_size, frame_base, list_predictive, list_differences, output_location): logger = logging.getLogger(__name__) predictive_vectors = [] out_image = Frame() out_image.create_new(frame_base.width, frame_base.height) if not list_predictive and not list_differences: logger.info("list_predictive and not list_differences: true") logger.info("Saving inversion image..") out_image.save_image(output_location) return if list_predictive and not list_differences: logger.info("list_predictive and not list_differences") logger.info("saving last image..") out_image.copy_image(frame_base) out_image.save_image(output_location) return # load list into vector displacements for x in range(int(len(list_predictive) / 4)): predictive_vectors.append(DisplacementVector(int(list_predictive[x * 4]), int(list_predictive[x * 4 + 1]), int(list_predictive[x * 4 + 2]), int(list_predictive[x * 4 + 3]))) # copy over predictive vectors into new image for vector in predictive_vectors: out_image.copy_block(frame_base, block_size, vector.x_2, vector.y_2, vector.x_1, vector.y_1) out_image.save_image_quality(output_location, 25)
def make_difference_image(context: Context, raw_frame, list_difference, list_predictive, out_location): 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) out_image.save_image(out_location) return # 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) out_image.save_image(out_location) return # 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 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)) out_image.save_image(out_location)
from wrappers.frame import Frame # f1 = Frame() # f1.load_from_string("C:\\Users\\windwoz\\Desktop\\workspace\\violetfade\\100\\frame20.png") # # f2 = Frame() # f2.load_from_string("C:\\Users\\windwoz\\Desktop\\workspace\\violetfade\\100\\frame21.png") # f1 = Frame() f1.load_from_string( "C:\\Users\\windwoz\\Desktop\\workspace\\violetfade\\inputs\\frame30.jpg") f1.fade_block(0, 0, 100, -100) f1.save_image("C:\\Users\\windwoz\\Desktop\\workspace\\violetfade\\lmfao.jpg")