File Exchange

image thumbnail

Muscle fascicle tracking - Ultrasound

version 1.2 (5.54 MB) by

Implementation of an optical flow algorithm to track muscle length changes imaged with ultrasound.



View License

This Matlab GUI demonstrates how muscle fascicles from the medial gastrocnemius (MG) muscle in humans that are imaged using B-mode ultrasound can be automatically tracked using optical flow algorithms utilising an affine transformation to track end points of muscle fascicles as determined in an initial frame.

Please cite the following manuscripts in any academic work which uses this algorithm -

1. Cronin, NJ, Carty, CP, Barrett, RS & Lichtwark G. (2011) Automatic tracking of medial gastrocnemius fascicle length during human locomotion. Journal of Applied Physiology. In Press. doi:10.1152/japplphysiol.00530.2011

2. Gillett, J, Barrett, R & Lichtwark, G. (2011) Reliability and accuracy of an automatic tracking algorithm to measure passive and active muscle fascicle length changes from B-mode ultrasound. Computer Methods in Biomechanics and Biomedical Engineering. In Press.

This toolbox requires the Image Processing toolbox.

This toolbox utilises Dr David Young's (Susses University) excellent algorithms for calculating the optical flow using the affine transformation
extension -

It also uses Sandra Martinka's Rubberband Line function -

The GUI comes with an example video file and represents a passive rotation of the ankle which in turn changes the length of the MG muscle. This may require DivX codecs to be installed. Please read README.txt file for full information.

Comments and Ratings (8)


I also get errors when I advance forward by a frame, and the red line from tracking the fascicle goes away. There are errors in both the affine_flowdisplay function and the guimainfcn function, as well as in the muscle_track function, itself. Any help would be greatly appreciated!


Ethan (view profile)

Dear all,

I get error messages while I execute step 8 in the readme file, "Advance forward by a frame by clicking the right arrow on the frame slider bar. The new frame and the new tracked fascicle should be shown"
Could anyone help to solve this problem, Thanks in advance.


Robert (view profile)

I was wrong - installing DivX as suggested solved the problem…


Robert (view profile)

Hi, the script runs flawlessly on Matlab R2009 under Windows. On R2012a (Mac) VideoReader seems to be unable to read the video file, though.

Error using VideoReader/init (line 447)
Failed to initialize internal resources.

Error in VideoReader (line 132)

The videos display nicely using VLC, so I don't suppose this is a codec issue.

Any suggestions?


Martin (view profile)

Dan Robbins

Hi Glen, thanks for getting back to me. I have actually managed to get the programme running now. It was my fault for not adding the path to both the MT directory and the affine folder within the MT directory (I am new to MATLAB!), sorry about the confusion. In the readme file the first reference does not have citation info, please can you let me know the full citation so I can see how fascicle length and pennation angle are calculated? I am hoping to use the program for a study I am planning so will of course also use this to reference your work.
Thanks again

Glen Lichtwark

Glen Lichtwark (view profile)

Dan, you'll have to be more specific. Can you get the video file to open at all? If not, then this is probably due to an incompatibility of the video compression. Try installing DivX as described. If you are getting an error message then I'll need to know what the message is. Please ensure you are also using Matlab 2009 onwards.

Hi, I cannot get the example file to track. Is this likely to be due to the video file or some sort of setting I am getting wrong? Thanks Dan



Added relevant publications to description.


Added access for Matlab 2009 users to load videos.

MATLAB Release
MATLAB 7.10 (R2010a)

Inspired by: Rubberband Line, Affine optic flow

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video