title: Matlab video processing of heart beating. code supplemented
body: <p>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</p>
  
  <p><a href="http://youtube.com/watch?v=f9xgDnkkPt0" rel="nofollow noreferrer">Example 1</a> </p>
  
  <p>Example 2: youtube.com/watch?v=uG_WOdGw6Rk</p>
  
  <p>And plot out the following:</p>
  
  <ol>
  <li>Count of beats per min.</li>
  <li>Strenght of Beat</li>
  <li>Regularity of beating</li>
  </ol>
  
  <p>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.</p>
  
  <p>Example of My code Results
  <img src="https://i.stack.imgur.com/4eFZz.jpg" alt="enter image description here"></p>
  
  <p>Core of Current code i wrote:</p>
  
  <pre><code>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);
  </code></pre>
  
  <p>=====================</p>
  
  <p>So thats my code, but is there a way i can improve it so i can get better results ?</p>
  
  <p>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 !</p>
  
  <p>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 ??</p>
  
  <p>thanks also really appreciate your help, this is a small portion of code, if u need more info please let me know.
  thanks</p>