This repository contains Python scripts for processing image sequences by applying temporal smoothing and computing optical flow using the Lucas-Kanade method.
-
Temporal Smoothing:
Smoothens a sequence of image frames using a weighted kernel, enhancing temporal continuity while reducing noise. The smoothed frames are saved as.npyfiles. -
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.npyfiles.
Ensure you have the following Python libraries installed:
numpyscipymatplotlibskimagenumbatifffilepython-bioformatsjavabridge
You can install the required dependencies via pip if needed.
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.npyfiles will be stored.
The smoothing script now supports two modes:
- Folder mode: Use
data_folder(and optionalfile_list) when timeframes are separate files. - Single-file mode: Use
single_timelapse_filewhen 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.
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 1Single-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 1This 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.npyfiles.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.
- Temporal Smoothing: The smoothed frames are saved as
.npyfiles in thenew_pathdirectory. - Optical Flow: The computed optical flow velocity components (
vx,vy) and reliability scores are saved as.npzfiles in thesave_pathdirectory.
- Step 1: Temporal smoothing of raw image frames is done by calling the smoothing function with the appropriate paths.
- Step 2: After smoothing, optical flow is computed by calling the optical flow function on the smoothed frames.
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.