# How can I modify the code to count the number of particles leaking from the white sand pile? The video is Dune video 1.zip.

1 view (last 30 days)
Wesley on 13 Apr 2021
Edited: Matt J on 14 Apr 2021
MATLAB CODE:
%% Slider Effect in a Video
% This example shows how to create the slider effect in a video. One part
% of it detects edges using the Canny Method.
% Copyright 2018 The MathWorks, Inc.
%% Read the video into MATLAB
% This value determine the speed of the sliding effect
speed = 10;
% Display video
depVideoPlayer = vision.DeployableVideoPlayer;
%% Process each frame
% Left to Right
for idx = 1:speed:col
% Detect edges in the grayscale image
edgeFrame = edge(rgb2gray(videoFrame),'canny');
edgeFrame = edgeFrame * 255;
% Part of the Input Frame
n1 = videoFrame(:, 1 : idx,:);
% Part of the Edge Detected Frame
n2 = edgeFrame(:, idx+1 : col );
% Concatenating them together
finalFrame = [n1 cat(3,n2,n2,n2)];
depVideoPlayer(finalFrame);
end
% Right to Left
for idx = col:-speed:1
% Detect edges in the grayscale image
edgeFrame = edge(rgb2gray(videoFrame),'canny');
edgeFrame = edgeFrame * 255;
% Part of the Input Frame
n1 = videoFrame(:, 1 : idx,:);
% Part of the Edge Detected Frame
n2 = edgeFrame(:, idx+1 : col );
% Concatenating them together
finalFrame = [n1 cat(3,n2,n2,n2)];
depVideoPlayer(finalFrame);
end
end
PICTURE: Wesley on 14 Apr 2021
Calculate the code for the rice particles in a picture.How should I apply it to the video?
clear; clc;
% Get the background of the picture
BG=imopen(I,strel(disk,15));
% Get a picture with a uniform background
I2=imsubtract(I,BG);
% Get a binary image
level=graythresh(I2);
BW=im2bw(I2,level);
% labeled is the processed matrix, and numObjects is the number of rice grains;
[labeled,numObjects]=bwlabel(BW,8);
% Take an empty matrix A to store the number of pixels occupied by each grain of rice;
[m,n]=size(labeled);
A=zeros(numObjects,1);
% This loop is used to count the size of each rice grain, for example, the size of the i-th rice grain is stored in A(i);
for x=1:numObjects
for i=1:m
for j=1:n
if labeled(i,j)==x
A(x)=A(x)+1;
end
end
end
end