Fly Tracker
1. Labkit for Pixel Classification
2. Python for Fly Detection
3. Kalman Filter for Fly Tracking
Labkit for Pixel Classification
1. Image > Hyperstack > Stack to Hyperstack
2. Label Foreground (Fly) and Background by choosing Draw (D) button and painting on a few pixels
Labkit for Pixel Classification
3. Segmentation > Train Classifier
4. Label a few more pixels if you are not satisfied with the result
Labkit for Pixel Classification
5. Save Segmentation Result
This takes some time !
Clone Repository
git clone https://github.com/MLbyML/fly-tracker.git
cd fly-tracker
git checkout 01_DetectFlies
conda env create -f flytrackerEnv.yml
conda activate flytrackerEnv2
python3 -m ipykernel install --user --name flytrackerEnv2 --display-name "flytrackerEnv2"
jupyter notebook
Now you can run the notebook !!
Python Script for Fly Detection
### Use Erosion to hide small incorrect
#foreground pixels
from skimage.morphology import erosion
from skimage.morphology import square, cube
erodedIm=erosion(im, cube(3))
print("Shape", erodedIm.shape)
plt.figure(figsize=(16, 8))
plt.subplot(1,2,1)
plt.imshow(im[50])
plt.title('Original')
plt.subplot(1,2,2)
plt.imshow(erodedIm[50, ...])
plt.title('Eroded')
Erosion
Some technical details. Not so important!
Python Script for Fly Detection
Connected Components
fly_labels = np.empty_like(erodedIm)
for i in range(fly_labels.shape[0]):
fly_labels[i, ...]=
measure.label(erodedIm[i, ...], background=0)
Python Script for Fly Detection
Hungarian Asssignment
row_col_dict_list=[]
for t in range(0, fly_labels.shape[0]-1): # time axis
cost=np.zeros((len(np.unique(fly_labels[t]))-1, len(np.unique(fly_labels[t+1]))-1))
for j in range(cost.shape[0]):
for k in range(cost.shape[1]):
cost[j, k]=(comyt[t][j]-comyt[t+1][k])**2 + (comxt[t][j]-comxt[t+1][k])**2
row_ind, col_ind = linear_sum_assignment(cost)
objects=dict(zip(row_ind, col_ind))
row_col_dict_list.append(objects)
FlyTracker
By Manan Lalit
FlyTracker
Flytracker
- 140