Detecting black blob (mouse) in .tif frames
6 views (last 30 days)
Show older comments
Hi everyone, I am having trouble to understand how to detect the mouse from these frames. My goal is to find its position and the distance it travels from frame to frame of the TIFF movie. I have tried using Otsu thresholding and bwboundaries, following other posted questions and tutorials but I cannot seem to reach a solution. I will attach an image of the first frame as I cannot attach the TIFF file.
Thanks in advance,
Kind regards.
0 Comments
Accepted Answer
Image Analyst
on 28 Jul 2021
You can basically put it into a loop over video frames where you get a frame and then do (untested, but see attached demo):
% Convert to gray scal if needed.
if size(thisFrame) == 3
grayImage = rgb2gray(thisFrame);
else
grayImage = thisFrame;
end
mask = ~imbinarize(grayImage);
% Get largeste blob only.
mask = bwareafilt(mask);
% Fill any holes.
mask = imfill(mask, 'holes');
% Find centroid
props = regionprops(mask, 'Centroid')
% Store the centroid for this frame index
xCenter(frameIndex) = props.Centroid(1);
yCenter(frameIndex) = props.Centroid(2);
Then to find distance tracked
deltaX = diff(xCenter);
deltaY = diff(yCenter);
distanceTraveled = sqrt(deltaX .^ 2 + deltaY .^ 2); % As a function of frame number.
% Sum up all the distances traveled frame-to-frame to get the total distance.
totalDistance = sum(distanceTraveled)
===================================================================
That said, there are already many animal tracking packages out there that have this all worked out already. We use Noldus Ethovision in my company. It's very sophisticated, and does way more than simple tracking of centroid. For example, you can tell if the animal is still moving/alive even if it's centroid has not changed. And it can track several animals at once.
Here are some links on animal tracking software. If I were to pick one, I’d start with one of the noldus packages because they’re made by a company whose main business is animal tracking and it seems very professional. Most of the others seem like research projects – some seem to be just source code that you have to compile. Since noldus offers so many tracking programs, we should contact the company to make sure we try the most appropriate one.
=========================================================================
Variety of powerful packages
Perhaps the most comprehensive solution. Professional global company dedicated to animal and human behavior and motion analysis. Founded by an animal behavior scientist 33 years ago. Has over 10,000 clients. Can do much more than just position tracking – like behavior, etc. Has a free trial software download. Packages start at $5850 : https://www.noldus.com/ethovision-xt
Looks like it can do the most of any of the other software I ran across.
=========================================================================
idtracker,
idTracker is a videotracking software that keeps the correct identity of each individual during the whole video.
It works for many animal species including mice, insects (Drosophila, ants) and fish (zebrafish, medaka, stickleback). Claims to handle animal occlusion/overlapping better than other software.
Written in MATLAB but is compiled so you don’t need MATLAB.
=========================================================================
Ctrax is an MATLAB-BASED open-source, freely available, machine vision program for estimating the positions and orientations of many walking flies, maintaining their individual identities over long periods of time. It was designed to allow high-throughput, quantitative analysis of behavior in freely moving flies. Our primary goal in this project is to provide quantitative behavior analysis tools to the neuroethology community; thus, we've endeavored to make the system adaptable to other labs' setups.
=========================================================================
Microsoft zootracer
Microsoft Research has released free software that scientists or students can use to analyze animal behavior captured on video, potentially offering insights that could, among other things, aid threatened species.
The Redmond, Wash., software giant’s research division will formally announce ZooTracer on Wednesday. It’s the result of a partnership between MSR’s Computational Ecology and Environmental Sciences division and the Computer Vision group, both based in Cambridge, England.
The mission of the first group is to create computer models to help answer scientific questions about the planet and environment
The big idea here is that the process can be automated. ZooTracer’s algorithms can extract meaning from video by tracking and analyzing the movements of animals, be they bees, frogs or elephants.
For example, MSR is using it to analyze what flower color patterns lure bees and under what conditions, information that can advance our understanding of evolutionary selection pressures.
But it’s possible the tool could also be used to track bee movements in an effort to help unravel the mystery of colony collapse disorder.
=========================================================================
Bemovi,
Developed by a Univ. Zurich professor. Bemovi is an R package that allows to extract abundance, behaviour and morphology of individual organisms from video sequences. The package relies on R - the statistical computing environment and ImageJ, as well as the ParticleTracker plug-in developed for ImageJ. I believe the software is free.
=========================================================================
wrMTrck,
wrMTrck plugin is based on Mtrack2 by Nico Stuurman, which is based on MultiTracker by Jeffrey Kuhn, which is based on Object_trackerby Wayne Rasband. wrMTrck will identify the objects in each frame, and then determine which objects in successive frames are closest together. If theses are within a user-defined distance (the maximum velocity of the objects) and have similar area (maxAreaChange) they are assembled into tracks. When multiple objects are within the distance determined by the maximum velocity, the closest object is selected and the object is flagged in the output. wrMTrck adds the following functionality to MTrack2
=========================================================================
cowLog,
CowLog is a software for recording behaviors from digital video developed in the Research Center for Animal Welfare and Department of Agricultural Sciences in the University of Helsinki. It is currently maintained and developed in the Natural Resources Institute Finland (Luke) .
We created CowLog, because we wanted a free easy to use program for coding digital video. CowLog is open source software and it is therefore free to use and modify.
CowLog is lightweight software, which tracks the time code from video files, and records the time with the coded behavior to a data file. The program reads common digital video formats and works in all major operating systems: Linux, Windows and Mac OS X.
=========================================================================
ToxTrack
ToxTrac is a free Windows program optimized for tracking animals. It uses an advanced tracking algorithm that is robust; very fast; and that can handle one or several animals in one or several environments. The program provides useful statistics as output. ToxTrac can be used for fish, insects, rodents, etc.
=========================================================================
TrackTor
Tracktor is an OpenCV based object tracking software. The software is able to perform single-object tracking in noisy environments or multi-object tracking in uniform environments while maintaining individual identities.
Tracktor is command based (i.e. there is no graphical user interface (GUI)) but anyone with basic coding/scripting skills such as R users can readily use it.
=========================================================================
DeepLabCut
DeepLabCut is a toolbox for markerless pose estimation of animals performing various tasks. Read a short development and application summary below. As long as you can see (label) what you want to track, you can use this toolbox, as it is animal and object agnostic. “open source Deep Learning software that works really good once you get used to it."
3 Comments
Image Analyst
on 29 Jul 2021
Sorry, you need
mask = bwareafilt(mask, 1);
In the future when something like that happens, check the help documentation for the function.
More Answers (1)
darova
on 28 Jul 2021
Here is the siple script that does the job
A0 = imread('img1.png');
A1 = im2bw(A0,0.2);
montage({A0 A1})
See Also
Categories
Find more on Animation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!