Important
This application was created with extensive use of agent-based artificial intelligence.
An original data analysis algorithm and graphical interface design were implemented. Approaches to video analysis were implemented using AI under careful human supervision, and elements of the graphical interface were created by agent-based AI in accordance with the original design.
Gait Analysis Tool is specialized software for automated and manual gait analysis of animals (e.g., rodents) based on video recordings (CatWalk-type systems). The program uses computer vision methods for body and paw detection, as well as tracking algorithms (Kalman Filter) to monitor movement trajectories.
- Drag-and-Drop: Support for dragging video files (
.mp4,.avi) directly into the program window. - Zoom & Pan: Ability to zoom (mouse wheel) and pan video (left mouse drag) for detailed examination.
- Navigation: Frame-by-frame viewing (left/right arrows), playback speed control (Play/Pause).
- Range Selection: Time range selection for processing (Start Time / End Time).
- Reset Zoom/Pan: Quick return to initial zoom and position.
- Static Corridor Detection: Automatic detection of red corridor (movement zone) based on static background.
- Body Detection: Body silhouette extraction based on brightness threshold (Dark Threshold) and movement (Movement Threshold).
- Paw Detection: Paw detection by color (Green HSV Threshold) within the corridor.
- Paw Grouping: Automatic merging of individual paw pads into a single paw based on distance (Max Paw Grouping).
- Spatial Filtering: Artifact filtering based on distance from body silhouette (Max Paw-Sil Dist).
- Live Color Preview: Dynamic display of detected color in settings (Color Preview widget).
- Simple Mode: Basic detection without preserving identifiers between frames.
- Global Tracking Mode: Using Kalman Filter and Hungarian Algorithm to build stable paw tracks.
- ID Persistence: Preserving paw identifiers even during temporary disappearance (occlusion).
- Color Coding: Each track has a unique color for visualization.
- Kalman Filter Settings: Flexible adjustment of process/measurement noise for balance between smoothness and reactivity.
- Manual Labeling: Assigning labels to paws:
F_L(Front Left),F_R(Front Right),R_L(Rear Left),R_R(Rear Right). - Smart Propagation: Automatic label propagation to all frames where this paw is present (forward and backward in time), based on bounding box overlap (IoU > 0).
- Area Graph: Visualization of paw contact area over time with color coding for each paw.
- Interactive Cursor: Clicking on the graph moves video to corresponding frame.
- Visual Indication: Labeled paws are displayed with colored bounding boxes and labels.
- Video Export: Saving video with overlaid detection masks, tracks, and labels in MP4 format.
- TIFF Stack Export: Exporting 3D mask stack (Time, Y, X) in TIFF format, where each paw has a unique pixel value (for further analysis in ImageJ/Fiji or Python).
0: Background1: Unlabeled paw2: F_L (Front Left)3: F_R (Front Right)4: R_L (Rear Left)5: R_R (Rear Right)
The program is written in Python 3.7+ and requires the following libraries:
opencv-python(cv2) — video and image processingnumpy— mathematical operations with arraysscipy— Hungarian algorithm for assignment problemqtpy— wrapper for PyQt5/PySide2PyQt5(or PySide2) — graphical interfacetifffile— TIFF stack export
pip install opencv-python numpy scipy qtpy PyQt5 tifffilepython app_run.pyNote: The program has been refactored into a modular architecture:
analysis.py— mathematical apparatus and computer vision algorithmsrun.py— user interfaceThe old file
application.pyis left for compatibility, but it is recommended to useapp_run.py.
The program is composed of two main modules:
Purpose: Mathematical apparatus and computer vision algorithms
Main classes:
ProcessorConfig— configuration of processing parametersGaitVideoProcessor— main video processorTrackerManager— tracker manager (Kalman + Hungarian Algorithm)KalmanTracker— Kalman filter based tracker
Usage:
from analysis import GaitVideoProcessor, ProcessorConfig
import cv2
# Configuration creation
config = ProcessorConfig()
config.green_lower_h = 40
config.paw_grouping_distance = 120
# Processor initialization
processor = GaitVideoProcessor(config)
processor.calculate_static_corridor('video.mp4')
# Frame analysis
frame = cv2.imread('frame.jpg')
results = processor.analyze_frame_data(frame)
print(f"Found {len(results['paws'])} paws")Purpose: Graphical interface on Qt
Main components:
MainWindow— main window of the programAreaGraphWidget— contact area graphZoomableVideoWidget— video display widgetVideoProcessingThread— background video processing
Advantages of modular architecture:
- Testing:
analysis.pycan be tested independently - Reusability: Analytical engine can be used in CLI, Jupyter, web services
- Support: Clear separation of logic and UI
-
Loading Video:
- Drag file into window or click "Load Video" button.
- Program will automatically detect static corridor and background.
- Video will load, but processing will not start automatically.
-
Parameter Settings (Detection/Tracking Tab):
- Body Detection:
- Adjust Dark Threshold (recommended 60-100) for correct body extraction.
- Adjust Movement Threshold (recommended 15-35) for noise filtering.
- Paws Detection:
- Adjust Green Min Hue/Sat/Val, guided by Color Preview window, so color matches paw color in video.
- Adjust Max Paw Grouping (recommended 80-120) for pad merging.
- Adjust Max Paw-Sil Dist (recommended 30-70) for artifact filtering.
- Click "Process Video" to apply settings and see preview result.
- Body Detection:
-
Using Global Tracking (optional):
- Enable checkbox "Use Global Tracking (IDs & Colors)".
- Adjust tracking parameters:
- Max Missing Frames: 20-40 for stable tracks.
- Assignment Distance: 100-200 depending on movement speed.
- Process Noise: 0.02-0.05 (lower = smoother, higher = more reactive).
- Measurement Noise: 0.3-0.7 (higher = smoother).
- Click "Process Video" to recalculate with tracking.
-
Annotation (Annotation Tab):
- Switch to Annotation tab.
- Select radio button with desired label (F_L, F_R, R_L, R_R).
- Click on paw bounding box in video.
- Label will automatically apply to entire step sequence of this paw (forward and backward).
- Use Left/Right arrows to navigate between frames.
- Use Up/Down arrows to change selected label.
- Monitor area graph at bottom for labeling quality control.
-
Export:
- Return to Detection/Tracking tab.
- Click "Export TIFFs" to get masks (for quantitative analysis).
- Click "Export Video" for result visualization.
- Space: Start/Stop video playback (in both tabs).
- Left/Right Arrows: Previous/Next frame.
- Mouse Wheel: Video zoom (in viewing widget).
- Mouse Drag (Left Button): Pan zoomed video.
- Up/Down Arrows: Change selected label (F_L → F_R → R_L → R_R).
- Mouse Click: Assign label to paw (click on bounding box).
- Range: 0-255
- Recommended: 60-100
- Description: Brightness threshold for extracting dark body silhouette on light background. Lower values make detection stricter (only very dark pixels), higher values make it softer.
- When to change: If body is poorly extracted or too much background is captured.
- Range: 0-100
- Recommended: 15-35
- Description: Threshold for movement detection relative to static background. Higher values ignore small movements and noise.
- When to change: If static objects are detected or slow movements are missed.
- Range: 20-300 pixels
- Recommended: 80-120
- Description: Maximum distance between individual contact spots (pads) to consider them one paw. Larger values merge more spots.
- When to change: If individual pads of one paw don't merge or paws standing close together merge.
- Range: 0-200 pixels
- Recommended: 30-70
- Description: Maximum distance a paw can be from body silhouette to be considered valid. Filters artifacts outside body.
- When to change: If artifacts are detected far from body or paws are missed in extended pose.
- Range: 0-180 (OpenCV HSV)
- Recommended: 30-50
- Description: Minimum hue value for green color detection of paws.
- When to change: Guided by Color Preview — color should match paw color in video.
- Range: 0-255
- Recommended: 30-60
- Description: Minimum saturation for green color detection. Lower values allow detecting paler shades.
- When to change: If paws have low color saturation or too much noise is detected.
- Range: 0-255
- Recommended: 30-60
- Description: Minimum brightness (Value/Brightness) for green color detection. Filters dark areas.
- When to change: If paws are in shadow or dark artifacts are detected.
- Range: 5-60 frames
- Recommended: 20-40
- Description: Maximum number of consecutive frames a track can exist without new detections (occlusion). After this, track is deleted.
- When to change: Increase for frequent occlusions, decrease for faster removal of stale tracks.
- Range: 50-300 pixels
- Recommended: 100-200
- Description: Maximum distance between predicted track position (Kalman prediction) and new detection for linking them.
- When to change: Increase for fast movements, decrease to avoid false associations.
- Range: 0.01-0.1
- Recommended: 0.02-0.05
- Description: Kalman filter parameter determining motion model uncertainty. Higher values make filter more reactive to trajectory changes but may add jitter.
- When to change: Increase for sharp direction changes, decrease for smoother tracks.
- Range: 0.1-2.0
- Recommended: 0.3-0.7
- Description: Kalman filter parameter determining trust in measurements. Higher values make filter trust model more (smoother tracks), lower values trust detections more (more accurate but jittery).
- When to change: Increase for noisy detections to smooth, decrease for more precise detection following.
- Static Background: Average frame values computed to extract static elements (corridor, background).
- Corridor Extraction: Red area detection (HSV thresholding) to determine movement zone.
- Body Extraction: Combination of darkness threshold and movement detection (frame differencing).
- Paw Extraction: HSV thresholding for green color within corridor.
- Grouping: Merging nearby contours into single paws based on Euclidean distance between centroids.
- Filtering: Removing paws located too far from body silhouette.
- Initialization: Creating new track for each detection in first frame.
- Prediction: Kalman filter predicts next position of each track.
- Association: Hungarian algorithm finds optimal matching between predictions and detections (minimizing total distance).
- Update: Tracks updated with corresponding detections, new detections create new tracks.
- Deletion: Tracks without detections for
Max Missing Framesare deleted.
- Dimensions: (T, H, W) — Time, Height, Width
- Data type: uint8
- Pixel values: 0 (background), 1 (unlabeled paw), 2-5 (labeled paws)
- Compatibility: ImageJ/Fiji, Python (tifffile, scikit-image), MATLAB
- Check Green Min Hue/Sat/Val settings using Color Preview.
- Decrease Green Min Sat or Green Min Val to detect paler shades.
- Verify paws are within corridor boundaries.
- Increase Green Min Sat to filter unsaturated colors.
- Decrease Max Paw-Sil Dist to filter objects far from body.
- Increase Movement Threshold to ignore static artifacts.
- Increase Max Missing Frames to preserve tracks during occlusions.
- Increase Measurement Noise for smoother tracks.
- Decrease Process Noise for less reactive filter.
- Increase Assignment Distance for larger search radius.
- Increase Max Missing Frames for longer track preservation.
- Ensure video is processed (clicked "Process Video").
- Check if detections are visible in video preview.
- Verify labeling in Annotation mode before export.
