Home

Awesome

Mice Tracking and Detection of Head Direction Using Principal Component Analysis (PCA)

projPca

This project was developed and tested for Ubuntu and Windows

To use the provided tools, the first step is to clone this repository, which can be can be accomplished by:

user@computer:~$ git clone https://github.com/vanluwin/proj-pca.git

Requirements

Python enviroment

This section is a guide to the installations of a python environment with the requirements of this repository.

First, install Anaconda or Miniconda, both of them give you similar results, but the latter requires less disk space.

Now, create a python virtual environment and install the required packages following the commands. Substitute <environment_name> with a name for your environment

On Linux Distributions

Open your terminal and execute the following commands:

user@computer:~$ conda create -n <enviroment_name> anaconda python=3
user@computer:~$ conda activate <enviroment_name> || source activate <enviroment_name>
(<enviroment_name>) user@computer:~$ conda install -c loopbio -c conda-forge -c pkgw-forge ffmpeg gtk2 numpy==1.16.3 opencv==3.4.3 matplotlib scipy pyserial

On Windows

Open your anaconda command prompt and execute the following commands:

C:\Users\your-user> conda create -n <enviroment_name> anaconda python=3
C:\Users\your-user> conda activate <enviroment_name> || source activate <enviroment_name>
(<enviroment_name>) C:\Users\your-user> conda install -c loopbio -c conda-forge -c pkgw-forge ffmpeg numpy==1.16.3 opencv==3.4.3 matplotlib scipy pyserial

Graphical User Interface

This GUI implements a more user-friendly way to interact with the tracking algorithm. Usage:

(<enviroment_name>) user@computer:~/proj-pca/gui$ python main.py

guiGif

The scripts

To use the provided scripts, first make sure to activate your python environment:

On Linux Distributions

On your terminal, execute the following command:

user@computer:~$ conda activate <enviroment_name>

On Windows

On your anaconda command prompt, execute the following command:

C:\Users\your-user> conda activate <enviroment_name>

PCA Analyser

pcaGif

This script aims to track the mice and detect the head direction during behavioral neuroscience experiments. For testing, use the following suggested commands:

(<enviroment_name>) user@computer:~/proj-pca$ python pcaAnalyser.py [-h] [--color-mask] [--both-axis] [--show-mask] [--save-video] video

Required arguments:

Optional arguments:

Tracker

tracker_GIF

This script aims to track mice throughout a neuroscience experiment detecting when the mice are present in a previously selected region, with that the program is able to keep track of how many frames the animal stayed inside each zone. Usage:

(<enviroment_name>) user@computer:~/proj-pca$ python tracker.py video frame_rate [--draw-axis] [--save-video] [--color-mask] [--log-position] [--log-speed]

Required arguments:

Optional arguments:

A statistics file containing the following information will be created.

Counters for the regions considering 30fps video

Traveled distance: 16971.568 pixels
Region 0: 3995 frames, 133.167s
Region 1: 4105 frames, 136.833s
Region 2: 852 frames, 28.400s
Region 3: 727 frames, 24.233s
Region 4: 1378 frames, 45.933s

Tracker with Arduino integration

trackerArduino

This script is an integration of the tracking system with Arduino-based development boards, enabling experiments with real-time decisions like the control of a laser simulated by the blue led in the gif above.

To utilize the script first, upload the Arduino file to your microcontroller and make sure that the serial communication is working. Then, in your terminal, run the following command:

(<enviroment_name>) user@computer:~/proj-pca$ python trackerArduino.py [-h] [--draw-axis] [--save-video] [--color-mask] [--log-position] video

Required arguments:

Optional arguments:

Detections Analyser

detectionsAnalyser

This script is intended to manually correct errors in detections that have already been made and can be edited, a window containing the instructions will be displayed. Pause and press d to edit the detections of the current frame. Usage:

(<enviroment_name>) user@computer:~/proj-pca$ python detectionsAnalyser.py video log_file

Avalible commands:

Heatmap Plot

heatmapPlot

This scripts takes as input a detection log file produced by the tracker.py script used with the --log-position option, and produces a heatmap plot, a window containg the plot will be displayed. Usage:

(<enviroment_name>) user@computer:~/proj-pca$ python heatmapPlot.py log_file frameWidth frameHeight

Required arguments:

Speed Plot

speedPlot

This scripts takes as input a speed log file produced by the tracker.py script used with the --log-speed option, and produces a speed plot, a window containg the plot will be displayed. Usage:

(<enviroment_name>) user@computer:~/proj-pca$ python speedPlot.py log_file

Required arguments:

<!-- ## Any questions? Feel free to contact me at richardsonsantiago@ufrn.edu.br -->