def find_shift(frames, z, N, M, num_frames): max_vel = 5 min_vel = 1 w = Forward(factor=4, hr_size=(N, N), lr_size=(M, M), num_frames=num_frames, frame_rate=4, drift_velocity=min_vel, drift_angle=0) min_cost = np.linalg.norm(frames.flatten() - w.forward / 16.0 @ z.flatten())**2 vels = np.linspace(1, max_vel, 5) for vel in vels: print(vel) w = Forward(factor=4, hr_size=(N, N), lr_size=(M, M), num_frames=num_frames, frame_rate=4, drift_velocity=vel, drift_angle=0) cost = np.linalg.norm(frames.flatten() - w.forward / 16.0 @ z.flatten())**2 print(cost) if cost < min_cost: min_cost = cost min_vel = vel return min_vel
return step # %% N = 500 M = 100 hr_size = (N, N) lr_size = (M, M) num_frames = 40 scene = scene[:500, :500] f = Forward(drift_angle=45, drift_velocity=1, frame_rate=4, num_frames=num_frames, lr_size=(M, M), hr_size=(N, N), factor=4) # crop scene to proper input size scene = scene[:f.hr_size[0], :f.hr_size[1]] # propagate scene through system and reshape frames = (f.forward @ scene.flatten()) / 16.0 frames = frames.reshape(f.num_frames, *f.lr_size) # %% frames_noisy = add_noise(frames, dbsnr=-10) frames = frames_noisy
import numpy as np import matplotlib.pyplot as plt from sr549.forward import Forward, add_noise from sr549.data import scene from sr549.registration import registration, shift_and_sum from sr549.misc import crop, compare_ssim, compare_psnr, upsample from sr549.hmrf import hmrf from skimage.transform import rescale # %% forward f = Forward(drift_angle=45, drift_velocity=1, frame_rate=4, num_frames=40, lr_size=np.array((100, 100)), hr_size=np.array((500, 500)), factor=4) # %% scene = scene[:f.hr_size[0], :f.hr_size[1]] frames = f.forward @ scene.flatten() frames = frames.reshape(f.num_frames, *f.lr_size) # add noise to frames frames_noisy = add_noise(frames, dbsnr=-10) # %% Output is normalized. size:lr_size * factor z = hmrf(frames_noisy, f, dbsnr=-10) scene_norm = scene[:f.lr_size[0] * f.factor, :f.lr_size[1] * f.factor]