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)
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
videoFileReader = VideoReader('dune Video.MP4');
% This value determine the speed of the sliding effect
speed = 10;
col = videoFileReader.width;
% Display video
depVideoPlayer = vision.DeployableVideoPlayer;
%% Process each frame
while hasFrame(videoFileReader)
% Left to Right
for idx = 1:speed:col
videoFrame = readFrame(videoFileReader);
% 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
videoFrame = readFrame(videoFileReader);
% 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:
  1 Comment
Wesley
Wesley on 14 Apr 2021
Edited: Matt J on 14 Apr 2021
Calculate the code for the rice particles in a picture.How should I apply it to the video?
clear; clc;
% Read the picture rice.png
I=imread(rice.png);
% 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

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!