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

Example 1 

Example 2: youtube.com/watch?v=uG_WOdGw6Rk

And plot out the following:


Count of beats per min.
Strenght of Beat
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
        compared=read(vidObj,i);
        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) &amp;&amp; (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
You could try a simple non-linear denoising filter (3x3 or 5x5 median filter) on your image sequence to make your detection more robust to noise ; but I get the feeling that the moving details on these images or quite thin and that too much filtering would harm your detection. And it looks like you are already thresholding the images before comparison, so the only noise that matters here are pixels moving above and below the threshold at each frame.

To get a beating rate you could also compute the auto-correlation of the sequence. It will show a secondary maximum at the beating rate. The autocorrelation is actually an interesting representation for your task because:


A very regular beat will mean a very sharp secondary peak on the AC sequence ; while a more irregular beat will show a flattened, spread out secondary peak in the AC sequence.
The ratio of the autocorrelation secondary peak to the first peak ($r_0$) can be used as a good measure of beat strength.


But back in time domain you could also consider:


The kurtosis of the sequence as a measure of "peakedness" (and thus beat strength). Other measures of peakedness include the ratio of geometric mean to arithmetic mean.
The standard deviation of the time intervals between peaks as a measure of beat regularity. The downside is that you will have to detect peaks, which will be a bit imprecise in your case especially given the low temporal resolution of your data (and this is why I thought about doing things from the AC function first!)