INTRODUCTION
The aim of this project is to analyze particle flow across images. This is a relatively common technical problem that arises in many disciplines. Obviously fluid dynamics, blood flow, or similarly the motion of surfaces as seen by motion of points. This is a unique project where the particles are sheeps herding in a lush green field. We will determine the flow of sheep gathering to cross through a small opening. For this project we have four sequential frames from the video, taken at interval of 1 sec starting at t = 38 sec.
Sequence 1
Sequence 2
Sequence 3
Sequence 4
The main objective of the project is to analyze the particle flow across the images and develop corresponding vectors indicating the direction of flow. To perform the analysis it is first important to convert the sheeps into a size of a particle. This is achived by toning down the sheeps to the level of a single or few pixels. To do so, various operations like thresholding, hit or miss etc are perfomed. The second major objective of the project was to see the movement of the entire sheep flock as a single unit. To do so, all the various operations like convolution, dilatation etc are performed. The work flow of the project and the steps are as follows -
Images taken as input
Elementary preprocessing done
Heat Map created
Preprocessing images to represent the entire flock of sheep herd as a single unit
Flow analysis and vector plotting
Preprocessing images to represent each sheep as a single unit.
Flow analysis and vector plotting
Velocity analysis
Heat map is a useful tool to understand the density of objects distributed with respect to the location in an image. The proposed function takes in two paramters as input.
Image
Map window
Map window is the size of square in which we are searching our object and evaluating the denisty. The code is self sustained and takes integer values as prescribed by the user. The workflow of the algorithm is as follows -
Input an image and convert it to binary
Divide this image into several windows (square) based on the Map window. Let's assume it is 40.
This forms a grid over the images, with the vertical and horizontal lines occuring at 1,41,81....(add 40 till th x and y dimensions are reached)
Sum the pixel values in each square and divide it by the square of Map window
This will give the normalized density of the sheep in the image when searched in a prescribed map window. Had each pixel represnted 1 sheep, we would have a normalised density of 1. This method therfore gives an approximated normalised distribution.
Heat map of sequence 1
Heat map of sequence 2
Heat map of sequence 3
Heat map of sequence 4
The images developed show a heat map with white being the coolest (least dense) and black dark red being the hottest (most dense) area.
The results are in line with what we see in the frames. The first few images have few sheep at the gates. In the last frame a large part of the herd is going through the gate hence in the last image there is a dark red spot near the gates. We see the flock moving through the gates and the middle of the flock moving about.
Processing images to represent all sheep as a single unit
The work flow of the algorithm is
Input image is thresholded
Converted to binary
Sheeps are then dilated using ones(3,3) matrix
This is repeated for 25 times
Since the image is big and sheeps are spread across a wider area, multiple iterations of dialation are needed to convert the image to be treated as a single flock. This number was decided to be 25 by trial
Sequence 1 showing all sheeps as single unit
Sequence 2 showing all sheeps as single unit
Sequence 3 showing all sheeps as single unit
Sequence 4 showing all sheeps as single unit
Motion tracking algorithm
The proposed algorithm intakes a two subsequent frames of the processed images
Search window size, Template window size and grid dimension are given as input
Image 1 acts as a template which is searched in Image 2.
Entire image is broken down into several windows based on the tracking parameters
Correlations are developed using normxcorr2to see the matching intensities
Extra developed padding is subtracted
Quiver plots are taken in account
Motion b/w sequence 1-2
Motion b/w sequence 2-3
Motion b/w sequence 3-4
The above images show a clear movement of the flock in north west direction. The length of the arrow is proportional to the length of the arrow. Since the diluted blob is tracked as a whole hence we can see a general movement in the northwest direction.
Processing images to represent each sheep as a single unit
The input images are first thresholded and then converted to binary images. These images are then further skeleton morphed to reduce the thickness of each sheep and finally different erode and hit/miss commands are taken into account. The sheeps can be assumed to have 4 different orientations namely Horizontal, Vertical, Leading diagnol and Falling diagnol.
Each of the image is first eroded using the hit structural element and then morphed using bwhitmiss(image,hit,miss) command in 4 different ways. All the four different parts are then added to represnt the entire image.
a) Horizontal
b1 =[0 0 0; 1 1 1; 0 0 0]; Hit
b2 = [1 1 1; 0 0 0;1 1 1]; Miss
b) Vertical
b1 =[0 1 0; 0 1 0; 0 1 0]; Hit
b2 = [1 0 1; 1 0 1;1 0 1]; Miss
c) Leading diagonal
b1 =[1 0 0; 0 1 0; 0 0 1]; Hit
b2 = [0 1 1; 1 0 1;1 1 0]; Miss
d) Falling diagonal
b1 =[0 0 1; 0 1 0; 1 0 0];
b2 = [1 1 0; 1 0 1;0 1 1];
As a result of these operations, we now have the final images which shows the sheep being represented by 1 or 2 pixels.
Sequence 1 showing each sheep as single unit
Sequence 2 showing each sheep as single unit
Sequence 3 showing each sheep as single unit
Sequence 4 showing each sheep as single unit
Motion b/w sequence 1-2
Motion b/w sequence 2-3
Motion b/w sequence 3-4
Zoomed images of top left corner
Motion b/w sequence 1-2
Motion b/w sequence 2-3
Motion b/w sequence 3-4
Velocity Analysis
To calculate the velocity, we first note the exact timestamp of each frame. The first frame is at 0:39, second frame is at 0:41, third frame is 0:43 and last frame is at around 0:45. Next, we need the distance traveled by sheep. This is achieved by plotting 'imagesc' plot and noing the average distance traveled by the pixels.
Location of the frontmost sheep in sequence 1 and sequence 2
As seen from the above image (left) the sheep is approximately 15 pixels long and in frame 1 to 2 the head of the sheep moved about 75 pixels up and 45 pixels to the left so the sheep moved around 85 pixels. An adult sheep is approximately 1.5 metres long hence each pixel represents about 1.5/15 m ~= 0.1 m. Therefore, the velocity is 85*0.1/2 ~= 4.25m/s or around 15 kmph.
The MATLAB code is available here