Friday, May 3, 2024
HomeMatlabQuantitative Video Evaluation: Measuring a Container Filling with Liquid » Steve on...

Quantitative Video Evaluation: Measuring a Container Filling with Liquid » Steve on Picture Processing with MATLAB


As we speak’s submit is by visitor blogger Isaac Bruss. Isaac has been a course developer for MathWorks since 2019. His PhD is in computational physics from UMass Amherst. Isaac has helped launch and help a number of programs on Coursera, on matters corresponding to robotics, machine studying, and pc imaginative and prescient. Isaac’s submit is predicated on a lesson from the Picture Processing for Engineering and Science Specialization on Coursera.

Introduction

On this submit, I’ll analyze a video of a container filling with liquid. Now, which may not sound like probably the most thrilling factor on this planet, however think about, for instance, you are a high quality management engineer answerable for guaranteeing that the speed of filling bottles is constant. You must decide if this price is fixed or varies over time. To reply this query, you’d must course of every particular person body from the video file. However the place would you begin?

Effectively, on this case, I began out with the Video Viewer App to turn into extra accustomed to the video. This app means that you can see the video’s dimension, body price, and complete variety of frames alongside the underside bar. Through the use of this app, you may rapidly get a way of what I’m working with by enjoying the video and navigating between frames.
movie-player.gif

Creating the Segmentation Operate

With the purpose of measuring the liquid inside the container, I wanted a segmentation perform that may separate the liquid from the background. To make sure I develop a sturdy algorithm, I export just a few consultant frames to create and check a segmentation perform.

export-frames.gif
The Shade Thresholder App is a strong software for interactively segmenting photos primarily based on shade. This app is especially helpful for photos which have distinct shade variations between the thing of curiosity and the background. On this case, I used the area choice software to spotlight pixels of curiosity inside the L*a*b* shade area. This allowed me to isolate the darkish liquid from each the purple background and white foam on the high.
color-thresholder.gif

As soon as I am glad with my thresholding outcomes, I export this segmentation perform from the app as a “.m” file named “liquidMask”.

Test the Segmentation Operate

This practice perform was developed utilizing solely the few frames I exported from the video. However to be assured within the outcomes, I want to make sure that it precisely isolates the darkish liquid in all of the frames. To do that, I first create a video reader object.

v = VideoReader(“liquidVideo.mp4”)

Then I loop by way of the frames utilizing the hasFrame perform. Contained in the loop, every body is handed into the customized liquidMask perform, and the ensuing masks is displayed side-by-side utilizing the montage perform.

whereas hasFrame(v) % Loop by way of all frames

img = readFrame(v); % Learn a body

bw = liquidMask(img); % Apply the customized segmentation perform

montage({img,bw},‘BorderSize’,[20,20],‘BackgroundColor’,[0.5,0.5,0.5]);

mask-generation.gif

The ensuing segmented video frames look nice! Additional morphological operations to raised section the area of curiosity are attainable, however to get a fast instance up and working they aren’t wanted.

Analyzing Liquid Proportion

Now I can transfer on to the ultimate half: calculating the proportion of the container that’s full of water at every body.

To get began, I must rewind the video to the start utilizing the CurrentTime property of the VideoReader.

Subsequent, I initialize two variables to retailer values for every body: the proportion of the container stuffed, and the time stamp.

percents = zeros(nFrames,1);

occasions = zeros(nFrames,1);

Now I’m prepared to make use of a for-loop to learn by way of the video, section every picture, and calculate the proportion of the container stuffed at every body. The share calculation is finished by counting the variety of pixels which can be full of liquid and dividing it by the entire variety of pixels.

for i = 1:nFrames % Loop by way of all frames

img = readFrame(v); % Learn a body

bw = liquidMask(img); % Create the binary masks utilizing the customized perform

liquidPart = nnz(bw); % Calculate the variety of liquid (true) pixels

perc = liquidPart/numel(bw); % Calculate proportion full of liquid

time = v.CurrentTime; % Mark the present time

percents(i) = perc; % Save the fill-percentage worth

occasions(i) = time; % Save the time stamp

Now that the info has been gathered, I plot the proportion of the container stuffed versus time to see how rapidly the liquid fills the container.

title(‘Proportion of Container Stuffed with Liquid vs Time’)

ylabel(‘Proportion Crammed’)

Take a look at that! The fill price is just not constant. From the plot, I see that the movement slowed down round 8 seconds, elevated at 15 seconds, and slowed once more at 20 seconds.

___

Thanks, Isaac!

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments