motion detection using pca n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Motion Detection using PCA PowerPoint Presentation
Download Presentation
Motion Detection using PCA

Loading in 2 Seconds...

play fullscreen
1 / 30

Motion Detection using PCA - PowerPoint PPT Presentation


  • 382 Views
  • Uploaded on

Motion Detection using PCA. Roland Miezianko rmiezian@temple.edu Video Analysis Project Spring 2004 Advisor: Prof. Dr. Longin Jan Latecki. Agenda. Motion Detection Input Video Algorithm Steps (2-D and 3-D blocks) Results Sample Videos and Results Video with 8x8 Detection Blocks

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Motion Detection using PCA' - ember


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
motion detection using pca

Motion Detectionusing PCA

Roland Miezianko

rmiezian@temple.edu

Video Analysis Project

Spring 2004

Advisor: Prof. Dr. Longin Jan Latecki

agenda
Agenda
  • Motion Detection
    • Input Video
    • Algorithm Steps (2-D and 3-D blocks)
    • Results
  • Sample Videos and Results
    • Video with 8x8 Detection Blocks
    • Video with 32x32 Detection Blocks
  • Matlab Code
    • Source Code
input video
Input Video
  • MPEG video converted to 2688 JPEG image frames
  • Full RGB color
algorithm steps
Algorithm Steps
  • Reshape image to 8x8 blocks
  • Collect blocks from every frame, normalize and reshape array from 3-D 8x8 blocks
  • Compute PCA projection matrix per block
  • Compute PCA score by projecting blocks from each frame onto that block’s 3-PCA projection
  • Compute EV values with W=3 for each block
  • Generate global threshold based on all blocks and frames
  • Generate local dynamic threshold for each block/frame with W=3
  • Generate motion matrix based on local and global dynamic threshold for all blocks-frames
step 1 details
Step 1 - Details
  • Read the color image
  • Resize the image by scale factor of 0.5
  • Convert the image to gray scale
  • Reshape the image into 8x8 distinct blocks
  • Transpose and save the data
  • Note: save per frame block data
step 1 code
Step 1 - Code

fileName = ...;

imN = imread(fileName);

imN = imresize(imN,0.5);

imN = rgb2gray(imN);

imCols = im2col(imN,[bH bW],'distinct');

imT = imCols';

step 1 8x8 block size
Step 1 - 8x8 Block Size

Block size relative to image size

Block 26x25

Image Size:

36x48 blocks

step 2 collect blocks
Step 2 - Collect Blocks
  • Collect same block from all the frames
  • Create a single matrix for each block location
  • Reshape vector from 3-D 8x8 blocks
  • There are 1728 matrices holding pixel values
  • Each matrix is 2688 x 64 (frames x pixels/block)
step 2 normalize blocks
Step 2-Normalize Blocks
  • Normalize each block by its mean value
  • Each block has its mean subtracted from each of the 64 pixel values
  • Store the normalized block data to be used in Step 3 and Step 4
step 2 code
Step 2 - Code

fileName = ...;load(fileName, '-mat'); % matrix is BlockX

% BlockN will be the normalized version of BlockX BlockN = BlockX;

BlockXMean = (mean(BlockX'))';

for FrameIndex = FrameStart : FrameEnd

BlockN(FrameIndex,:) = BlockX(FrameIndex,:) - BlockXMean(FrameIndex,1);

End

% store normalized block matrix as BlockN

step 2 block matrix
Step 2 - Block Matrix

Each block X of 1728 total blocks has a matrix representation of size 2688x64

Each block is normalized by its mean value

N = 2688

step 2 3 d 8x8 blocks
Step 2 – 3-D 8x8 Blocks
  • Take 3 rows of Block matrix from previous slide 3x64
  • Reshape into 1x192 vector
  • 3-D blocks are overlapping
  • New 3-D Block Matrix is used in computing PCA scores and projection matrices
step 3 compute pca
Step 3 - Compute PCA
  • Load normalized block matrix from Step 2 and compute the PCA projection matrix for this block sequence
  • Code:

fileName = ...;

load(fileName, '-mat'); % matrix is BlockN

[pc,latent,explained] = pcacov(cov(BlockN));

step 3 pca projection
Step 3 - PCA Projection
  • The principal components projection matrix contains 64 rows representing each pixel location in the block and 64 columns representing 64 principal components
  • Only the first three components are used in projection (first 3 columns)
step 4 compute score
Step 4 - Compute Score
  • Load normalized block matrix from Step 2 and project it onto the PCA projection matrix computed in Step 3
  • Only the first 3 PCA projections are used
step 4 code
Step 4 - Code

fileName = ...;

load(fileName, '-mat'); % matrix is BlockN

fileName = ...;

load(fileName, '-mat'); % matrix is pc

Score = double(BlockN) * pc(:,1:3);

step 5 compute ev
Step 5 - Compute EV
  • For each block sequence, load the PCA score matrix computed in Step 4
  • Compute a covariance matrix using a moving window of size 3
  • Compute eigenvalues (EVs)
  • Sort to get the larges EV value
  • Store the data in one EV matrix, representing all blocks and all frames
step 5 ev matrix
Step 5 - EV Matrix
  • EV matrix will contain a single EV value for a block-frame spatiotemporal location
step 5 code
Step 5 - Code

fileName = ...;load(fileName, '-mat'); % matrix is Score

dd = Score;evx = zeros(FrameEnd,3);W = 3;

for i=W+1:length(dd)-W; cc = dd(i-W:i+W,:); cm = cov(cc); evx(i,:)=sort(eig(cm)');end

step 6 global threshold
Step 6- Global Threshold
  • Load EV matrix from Step 5
  • Compute mean and standard deviation
  • Find all entries in the EV matrix that are below mean+2*std
  • Update the EV matrix
step 6 code
Step 6 - Code

fileName ...;load(fileName, '-mat'); % matrix is ev

gmean = mean(mean(ev'));gstd = std(mean(ev'));

LessThanThr = find(ev < (gmean+2*gstd));ev(LessThanThr) = 20;

step 7 local threshold
Step 7 - Local Threshold
  • Use the updated EV matrix from Step 6
  • Compute a local dynamic threshold using window
  • Generate a Motion matrix of same size as the EV matrix with a simple 0/1 values (1=motion)
step 7 assumptions
Step 7 - Assumptions
  • Assume that first 100 frames have no detectable motion
  • Compute mean and std of first 100 frames for each block
  • Compute local threshold for each block using a moving window (W=3)
  • Adjust local threshold, when no moving object is detected
step 7 code 1
Step 7 - Code 1

for BlockIndex = 1 : NumBlocks

W=3; current sample

FrameStart = 100; % first frames = no motion

meanl=mean(ev(BlockIndex,1:FrameStart)); stdl=std(ev(BlockIndex,1:FrameStart)); movingobject=0;

for i = FrameStart+W : FrameEnd-W;

... (next slide)

end % i

end % BlockIndex

step 7 code 2
Step 7 - Code 2 (…)

lw=ev(BlockIndex,i-W:i); %left windowrw=ev(BlockIndex,i+1:i+W); %right window

if mean(rw)-meanl>50*stdl

mobin(i)=mean(rw)-meanl; %moving obj detected movingobject=1; Motion(BlockIndex,i) = 1;else if movingobject==0 meanl=0.9*meanl+0.1*mean(lw); stdl=0.9*stdl+0.1*std(lw); end

end

step 8 motion matrix
Step 8 - Motion Matrix
  • Motion matrix is of size 1728x2688, same size as the EV matrix
  • It contains values 0 or 1, where 1 = motion detected
  • Use the Motion matrix to create sample videos showing blocks where motion was detected
detected motion
Detected Motion

No motion Detected Motion

(red blocks)

conclusion
Conclusion
  • The method of motion detection using principal component analysis combined with dynamic thresholding yields very good results in detecting motion
  • Future projects will include processing images with variation in size of the blocks
questions answers
Questions & Answers
  • Sample Videos
    • 8x8 Blocks
    • 32x32 Blocks
  • Principal Component Analysis
  • Matlab Code