Matlab processing video of a beating heart. code supplemented

I am trying to write code. Helps me in my biology. The concept of the code is to analyze the video file of contracting cells in the tissue.

Example 1

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

And write down the following:

  • The number of beats per minute.
  • Severity beat
  • Regular beatings

And so I wrote Matlab code that will scroll the video and compare each frame with the one that follows it, and see if there were any changes in the frames and draw these changes on the curve.

Example of my code Results enter image description here

I wrote the core of the current 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) && (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, this is my code, but is there any way to improve it so that I can get better results?

because I get that imabsdiff is not quite what I should use, because my video contains a lot of noise and that greatly affects my results, and I think that all the data from my amplifier is really faked!

In addition, I can actually only get the beat rate from this by counting the peaks, but how can I improve my code to be able to extract all the necessary data from it?

thanks also really appreciate your help, this is a small part of the code, if you need more information, please let me know. thanks

+7
source share
3 answers

You say you are trying to write "simple code", but this is not a simple problem. If you want to accurately measure motion, you must use the optical flow algorithm or look at the strain field c .

EDIT: As Matt says, and as we can see from your curve, your method is suitable for extracting the number of strokes and the regularity. To find the exact force of the blows, you need to calculate the movement of the cells (more movement = stronger blow). Unfortunately, this is not straight forward, and that is why I gave you links to two algorithms that can calculate the movement for you.

+9
source

A few pretty simple things that might help:

  • I would consider in detail what your threshold is doing, and whether this is really what you want to do. I don’t know what graythresh does, but it’s possible that it resets different functions that you would like to distinguish from the same pixel values. Have you tried drawing differences between images without thresholds? Or you can spawn multiple classes, not just black and white.
  • If noise is the main problem, you can try to smooth out the images before accepting the difference, so that the differences in noise will be smoothed out, but differences in large functions caused by motion will still be present.
  • You might try to identify your images before making a decision.

As the previous responder mentioned, you can also learn motion tracking and registration algorithms that will evaluate the actual movement between each image, and not just tell you if the images are different or not. I think this is a decent resume on Wikipedia: http://en.wikipedia.org/wiki/Video_tracking . But they can be quite complicated.

I think that if you only need to find the time and period of contractions, you will not need to do detailed tracking of movement or deformable registration between images. All you need to know is when they change significantly. (The “strength” of contraction is another matter to determine that strictly you probably need to know what kind of movement is going on.)

+4
source

What are the structures that we see in the video? For example, what is a large dark object at the bottom of an image? This object could be easily tracked, but could the data from this object be related to obtaining cell reduction data?

Is this an image from a light microscope? At what magnification? What is the scale? From the video you can see that there are several movements and areas of movement. So should you focus on a smaller or larger area to get your measurements? Cell contraction or area contraction? From experience I know that changing what you do in a microscope can be much better than complex image processing;)

I had a bitch with Gunn and Nixons Dual Snake for a similar problem: http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.64.6831

I put the first approximation in the first frame manually and used the segmentation result as the initial curv for the next frame and so on. My implementation for this is from 2000, and I only have it on paper, but if you find an interesting article by Gunn and Nixon, I will probably find my code and scan it.

@Matt suggested smoothing and edge detection to improve your results. This is a good recommendation. You can combine anti-aliasing, threshold, and edge detection in one function call, the Canny border detector. Then you can draw edges to get more overlap between frames. A little overlap probably means a lot of movement between frames. You can use it the same way as before to find the rhythm. Now you can make a second pass and add all the images with sketched edges associated with one hit. This should give you an idea of ​​the area tracked by the cells as they move through compression. Perhaps this can be used as a useful measure to compress a large cluster of cells.

I do not have access to Matlab and Image Processing Toolbox, so I can not give you verified code. Here are some tips: http://www.mathworks.se/help/toolbox/images/ref/edge.html, http://www.mathworks.se/help/toolbox/images/ref/imdilate.html and http: .//www.mathworks.se/help/toolbox/images/ref/imadd.html

+4
source

All Articles