<jupyter_start><jupyter_text>Load Data<jupyter_code>from skimage import io
mov = io.imread(filename).transpose([1,2,0])[:60,:60,:]
mov = np.asarray(mov,order='C',dtype=np.float64)
print(mov.shape)

fov_height, fov_width, num_frames = mov.shape<jupyter_output>(60, 60, 2000)<jupyter_text>Set Params<jupyter_code># Maximum of rank 50 blocks (safeguard to terminate early if this is hit)
max_components = 50

# Enable Decimation 
max_iters_main = 10
max_iters_init = 40
d_sub=2
t_sub=2

# Defaults
consec_failures = 3
tol = 0.0005

# Set Blocksize Parameters
block_height = 20
block_width = 20
overlapping = True<jupyter_output><empty_output><jupyter_text>Compress Video  Simulate Critical Region with Noise<jupyter_code>spatial_thresh, temporal_thresh = determine_thresholds((fov_height, fov_width, num_frames),
                                                       (block_height, block_width),
                                                       consec_failures, max_iters_main, 
                                                       max_iters_init, tol, 
                                                       d_sub, t_sub, 5, True)<jupyter_output><empty_output><jupyter_text>Decompose Each Block Into Spatial & Temporal Components<jupyter_code># Blockwise Parallel, Single Tiling
if not overlapping:    
    spatial_components,\
    temporal_components,\
    block_ranks,\
    block_indices = batch_decompose(fov_height, fov_width, num_frames,
                                    mov, block_height, block_width,
                                    max_components, consec_failures,
                                    max_iters_main, max_iters_init, tol,
                                    d_sub=d_sub, t_sub=t_sub)
    
 # Blockwise Parallel, 4x Overlapping Tiling
else:   
    spatial_components,\
    temporal_components,\
    block_ranks,\
    block_indices,\
    block_weights = overlapping_batch_decompose(fov_height, fov_width, num_frames,
                                                mov, block_height, block_width,
                                                spatial_thresh, temporal_thresh,
                                                max_components, consec_failures,
                                                max_iters_main, max_iters_init, tol,
                                                d_sub=d_sub, t_sub=t_sub)<jupyter_output><empty_output><jupyter_text>Reconstruct Denoised Video<jupyter_code># Single Tiling (No need for reqweighting)
if not overlapping: 
    mov_denoised = np.asarray(batch_recompose(spatial_components,
                                              temporal_components,
                                              block_ranks,
                                              block_indices))
# Overlapping Tilings With Reweighting
else:  
    mov_denoised = np.asarray(overlapping_batch_recompose(fov_height, fov_width, num_frames,
                                                          block_height, block_width,
                                                          spatial_components,
                                                          temporal_components,
                                                          block_ranks,
                                                          block_indices,
                                                          block_weights))<jupyter_output><empty_output><jupyter_text>Produce Diagnostics  Single Tiling Pixel-Wise Ranks<jupyter_code>if overlapping:
    pixelwise_ranks(block_ranks['no_skew']['full'], fov_height, fov_width, num_frames, block_height, block_width)
else:
    pixelwise_ranks(block_ranks, fov_height, fov_width, num_frames, block_height, block_width)<jupyter_output><empty_output><jupyter_text>Correlation Images<jupyter_code>from funimag.plots import util_plot
util_plot.comparison_plot([mov, mov_denoised + np.random.randn(np.prod(mov.shape)).reshape(mov.shape)*.01],
                plot_orientation="vertical")<jupyter_output>Local correlation:  range [2.1e-01 9.3e-01]
Local correlation:  range [6.1e-01 1.0e+00]
Local correlation:  range [-2.4e-01 2.3e-01]<jupyter_text>Render Videos & Residual<jupyter_code>play_cv2(np.vstack([mov, mov_denoised, mov-mov_denoised]), magnification=2)<jupyter_output><empty_output><jupyter_text>Save Results<jupyter_code>U, V = overlapping_component_reformat(fov_height, fov_width, num_frames,
                                      block_height, block_width,
                                      spatial_components,
                                      temporal_components,
                                      block_ranks,
                                      block_indices,
                                      block_weights)
np.savez(os.path.join(ext, "demo_results.npz"), U, V,block_ranks,block_height,block_width)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07219693835333058, 'fraction_numerical': 0.013860157219693836, 'mean_word_length': 1.8324545987111893, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 47, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '14415', 'license': 'MIT', 'n_tokens_mistral': 1400, 'n_tokens_neox': 1320, 'n_words': 224, 'path': 'demos/Demo Compression & Denoising.ipynb', 'repo_name': 'apasarkar/funimag', 'size': '4834'}