How to calculate velocity frame by frame

18 views (last 30 days)
Hello.
I recorded a reaction with a high speed camera (100000k frame rate) and I would like to calculate the velocity (total and frame by frame) of the reaction front. However, I do not know how to write a code to calculate the distance between frames. I have around 200 frames in each recording. I did this manually by measuring the distance between 10 frames and dividing by the time taken for the reaction front to go from frame 1 to frame 10 and it would be nice to have the velocity of the whole reaction (frames 1 to 200) and not only between 10 frames.
I attached 3 images to help understad what I need. The first picture is for frame 20, the second one for frame 70 and the last one after my sample was completely reacted, on frame 160. The reaction goes from right to left and the gray area is the reacted part.

Accepted Answer

Image Analyst
Image Analyst on 24 Jan 2022
I'd probably just get the velocity of the central part as it moves left. So take the average horizontal profile along some band in the middle
[rows, columns, numberOfColorChannels] = size(grayImage);
if numberOfColorChannels > 1
grayImage = rgb2gray(grayImage);
end
midRow = round(rows/2);
row1 = midRow - 10;
yline(row1, 'Color', 'g', 'LineWidth', 2)
row2 = midRow + 10;
yline(row2, 'Color', 'g', 'LineWidth', 2)
centralBand = grayImage(row1 : row2, :);
horizontalProfile = mean(centralBand, 1);
plot(horizontalProfile, 'b-');
grid on;
xlabel('column');
ylabel('Gray Level')
% Find threshold
threshold = mean([max(horizontalProfile), min(horizontalProfile)])
bw = horizontalProfile > threshold;
% Take largest region only in case there are multiple regions.
bw = bwareafilt(bw, 1);
% Find left most boundary.
leftEdge = find(bw, 1, 'first')
So do that for each frame. The pixel velocity is the change in left edge divided by the time between frames. To get real velocity multiply the pixel velocity by the number of mm per pixel.
  1 Comment
Maria Martins
Maria Martins on 24 Jan 2022
Thank you very much for your answer. It did help me.
One more question, is it possible to make this code run for a lot of pictures at once? Because for each reaction I have around 200 frames and it would save a lot of time if I could get all the profiles together.

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB Support Package for IP Cameras in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!