def verify_user_settings(context): from wrappers.frame import Frame input_frames_dir = context.input_frames_dir extension_type = context.extension_type block_size = context.block_size f1 = Frame() f1.load_from_string(input_frames_dir + "frame1" + extension_type) valid = True if f1.width % block_size != 0 and f1.height % block_size != 0: print("----------------------ERROR---------------------------------------") print("Your block size is incompatible with the resolution you provided. ") print("Valid Block sizes are:") print("------------------------------------------------------------------") valid_sizes = [] larger_val = [f1.width, f1.height][f1.height > f1.width] for x in range(1, larger_val): if f1.width % x == 0 and f1.height % x == 0: valid_sizes.append(x) print(valid_sizes) print("------------------------------------------------------------------") new_block_size = int(input("Enter your value (recommended 25 or greater): ")) while new_block_size not in valid_sizes: new_block_size = int(input("Invalid Choice! Re-Enter a correct value: ")) context.block_size = new_block_size
def main(): block_size = 4 scale_factor = 2 frame_base = Frame() frame_base.load_from_string( "C:\\Users\\windwoz\\Desktop\\image_research\\shelter\\merged2x.jpg") list_predictive = wait_on_text( "C:\\Users\\windwoz\\Desktop\\image_research\\shelter\\correction.txt") out_location = ( "C:\\Users\\windwoz\\Desktop\\image_research\\shelter\\new_correction.jpg" ) correct_image(block_size, scale_factor, frame_base, list_predictive, out_location)
def compress_frames(context: Context): inputs_dir = context.input_frames_dir frame_count = context.frame_count compressed_dir = context.compressed_dir quality_low = context.quality_low extension_type = context.extension_type for x in range(1, frame_count + 1): if os.path.exists(compressed_dir + "compressed_" + str(x) + ".jpg"): continue frame = Frame() frame.load_from_string(inputs_dir + "frame" + str(x) + extension_type) frame.save_image_quality( compressed_dir + "compressed_" + str(x) + ".jpg", quality_low)
def determine_sens(workspace, frame, lower_val, higher_val): from wrappers.frame import Frame frame.save_image_quality(workspace + "lower.jpg", lower_val) frame.save_image_quality(workspace + "higher.jpg", higher_val) lower_image = Frame() lower_image.load_from_string(workspace + "lower.jpg") higher_image = Frame() higher_image.load_from_string(workspace + "higher.jpg") lower_mse = frame.mean(lower_image) higher_mse = frame.mean(higher_image) os.remove(workspace + "lower.jpg") os.remove(workspace + "higher.jpg") return lower_mse, higher_mse
def set_mse(self): print("calculating mse") list = [] for x in range(1, int(math.sqrt(self.frame_count))): print(str(x) + " out of " + str(int(math.sqrt(self.frame_count)))) num = random.randint(1, self.frame_count) f1 = Frame() f1.load_from_string(self.input_frames_dir + "frame" + str(num) + ".jpg") list.append( determine_sens(self.workspace, f1, self.quality_low, self.quality_high)) output = [sum(y) / len(y) for y in zip(*list)] self.mse_max = output[0] self.mse_min = output[1] print("mse is ") print(output)
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")