# Initialize the frame alignment object. my_timer.create('Select optimal alignment patch') align_frames = AlignFrames(frames, rank_frames, configuration) if configuration.align_frames_mode == "Surface": # Select the local rectangular patch in the image where the L gradient is highest in both x # and y direction. The scale factor specifies how much smaller the patch is compared to the # whole image frame. (y_low_opt, y_high_opt, x_low_opt, x_high_opt) = align_frames.compute_alignment_rect( configuration.align_frames_rectangle_scale_factor) my_timer.stop('Select optimal alignment patch') print("optimal alignment rectangle, x_low: " + str(x_low_opt) + ", x_high: " + str(x_high_opt) + ", y_low: " + str(y_low_opt) + ", y_high: " + str(y_high_opt)) reference_frame_with_alignment_points = frames.frames_mono( align_frames.frame_ranks_max_index).copy() reference_frame_with_alignment_points[ y_low_opt, x_low_opt:x_high_opt] = reference_frame_with_alignment_points[ y_high_opt - 1, x_low_opt:x_high_opt] = 255 reference_frame_with_alignment_points[ y_low_opt:y_high_opt, x_low_opt] = reference_frame_with_alignment_points[ y_low_opt:y_high_opt, x_high_opt - 1] = 255 # plt.imshow(reference_frame_with_alignment_points, cmap='Greys_r') # plt.show() # Align all frames globally relative to the frame with the highest score. my_timer.create('Global frame alignment') try: align_frames.align_frames()
try: # In creating the Frames object the images are read from the specified file(s). frames = Frames(configuration, names, type=type) print("Number of images read: " + str(frames.number)) print("Image shape: " + str(frames.shape)) except Error as e: print("Error: " + str(e)) exit() # Rank the frames by their overall local contrast. rank_frames = RankFrames(frames, configuration) rank_frames.frame_score() print("Best frame index: " + str(rank_frames.frame_ranks_max_index)) output_file = 'Images/' + file + '.jpg' imwrite(output_file, frames.frames_mono(rank_frames.frame_ranks_max_index)) # Initialize the frame alignment object. align_frames = AlignFrames(frames, rank_frames, configuration) if configuration.align_frames_mode == "Surface": # Select the local rectangular patch in the image where the L gradient is highest in both x # and y direction. The scale factor specifies how much smaller the patch is compared to the # whole image frame. (y_low_opt, y_high_opt, x_low_opt, x_high_opt) = align_frames.compute_alignment_rect( configuration.align_frames_rectangle_scale_factor) # Alternative: Set the alignment rectangle by hand. # (align_frames.x_low_opt, align_frames.x_high_opt, align_frames.y_low_opt, # align_frames.y_high_opt) = (x_low_opt, x_high_opt, y_low_opt, y_high_opt) = (