# Matlab video processing of Contracting tissues. how to analyze movement?

I'm trying to write a code The helps me in my biology work. Concept of code is to analyze a video file of contracting cells in a tissue

And plot out the following:

1. Count of beats per min.
2. Strenght of Beat
3. Regularity of beating

And so i wrote a Matlab code that would loop through a video and compare each frame vs the one that follow it, and see if there was any changes in frames and plot these changes on a curve.

Example of My code Results

Core of Current code i wrote:

for i=2:totalframes
ref=rgb2gray(compared);%% convert to gray
level=graythresh(ref);%% calculate threshold
compared=im2bw(compared,level);%% convert to binary
differ=sum(sum(imabsdiff(vid,compared))); %% get sum of difference between 2 frames
if (differ ~=0) && (any(amp==differ)==0) %%0 is = no change happened so i dont wana record that !
amp(end+1)=differ;  % save difference to array amp wi
time(end+1)=i/framerate; %save to time array with sec's, used another array so i can filter both later.
vid=compared; %% save current frame as refrence to compare the next frame against.
end
end
figure,plot(amp,time);


=====================

So thats my code, but is there a way i can improve it so i can get better results ?

because i get fealing that imabsdiff is not exactly what i should use because my video contain alot of noise and that affect my results alot, and i think all my amp data is actually faked !

Also i actually can only extract beating rate out of this, by counting peaks, but how can i improve my code to be able to get all required data out of it ??

thanks also really appreciate your help, this is a small portion of code, if u need more info please let me know. thanks

• How would you visually assess the Strength of Beat? By the distance the tissue moves? – endolith Jan 4 '16 at 4:58
• not exactly, although its a 2 years old work, i remember the idea was to convert frame to black and white, since tissue color become black and background is white, you sum all pixels 'black = 1, white = 0' and compare difference, more black means tissue is relaxed 'higher value' more white means tissue is contracted 'result in lower value'.i also remember before i come up with this i tried identifying borders of tissue to compare size; yet that was a waste of time and effort, was never accurate – Zalaboza Jan 4 '16 at 7:13
• Yeah thresholding seems like a crude method. Tracking features in the image and measuring when and how far they move should work better – endolith Jan 4 '16 at 7:23

• The ratio of the autocorrelation secondary peak to the first peak ($r_0$) can be used as a good measure of beat strength.