Skip to content

Latest commit

 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

Temporal Smoothing and Optical Flow Analysis

This repository contains Python scripts for processing image sequences by applying temporal smoothing and computing optical flow using the Lucas-Kanade method.

Features

  1. Temporal Smoothing:
    Smoothens a sequence of image frames using a weighted kernel, enhancing temporal continuity while reducing noise. The smoothed frames are saved as .npy files.

  2. Optical Flow Calculation:
    Computes the optical flow between consecutive smoothed frames using the Lucas-Kanade method. Outputs include velocity fields (vx, vy) and reliability scores, saved as .npy files.

Installation

Ensure you have the following Python libraries installed:

  • numpy
  • scipy
  • matplotlib
  • skimage
  • numba
  • tifffile
  • python-bioformats
  • javabridge

You can install the required dependencies via pip if needed.

Usage

1. Temporal Smoothing

This function smooths a sequence of raw image frames. It uses a weighted kernel to smooth frames temporally and stores the smoothed frames as .npy files.

  • Inputs:
    • data_folder: Path to the folder containing raw image frames (one timeframe per file).
    • single_timelapse_file: Path to a single file containing all timeframes (for example .czi, .lif, .ome.tif, etc.).
    • new_path: Path where smoothed .npy files will be stored.

The smoothing script now supports two modes:

  1. Folder mode: Use data_folder (and optional file_list) when timeframes are separate files.
  2. Single-file mode: Use single_timelapse_file when the full timelapse is in one file.

If input files are not TIFF, the script converts frames to TIFF before smoothing. Common formats (for example PNG/JPG) are loaded directly, and Bio-Formats is used as a fallback for unsupported microscopy formats.

Command-line examples

Folder mode (one timeframe per file):

python smoothing.py --new-path E:/Spandan/TTX/TTX_Experiments_08_22/smooth --data-folder E:/Spandan/TTX/TTX_Experiments_08_22/p2 --jump 1

Single-file mode (whole timelapse in one file):

python smoothing.py --new-path E:/Spandan/TTX/TTX_Experiments_08_22/smooth --single-timelapse-file E:/Spandan/TTX/TTX_Experiments_08_22/timelapse.czi --jump 1

2. Optical Flow Calculation

This function calculates the optical flow between consecutive smoothed frames using the Lucas-Kanade method. It computes the x and y velocity components (vx, vy) and reliability scores for each pixel, saving these as .npy files.

  • Inputs:
    • smooth_address: Path to the folder containing the smoothed .npy files.
    • save_path: Path where the optical flow results will be saved.
    • sigma: The spread of Gaussian weights used in the optical flow calculation.
    • threshold: The reliability score threshold for valid velocity fields.

Outputs

  • Temporal Smoothing: The smoothed frames are saved as .npy files in the new_path directory.
  • Optical Flow: The computed optical flow velocity components (vx, vy) and reliability scores are saved as .npz files in the save_path directory.

Example Workflow

  1. Step 1: Temporal smoothing of raw image frames is done by calling the smoothing function with the appropriate paths.
  2. Step 2: After smoothing, optical flow is computed by calling the optical flow function on the smoothed frames.

Contributing

Feel free to fork the repository and create a pull request for any improvements or bug fixes. Please ensure that any contributions are well-documented and come with the appropriate tests.

About

Implements temporal smoothing for image sequences and computes optical flow using the Lucas-Kanade method, saving results as .npy files for further analysis.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages