MATLAB Image Processing

The following MATLAB code compares a "baseline" image with a "live" image and detects objects in the live image by subtracting the baseline image from the live image and looking at the result.  It took 2 hours to get working properly and can potentially be ported to C/C++ using MATLAB's Real-Time Workshop.


%Ryan Wolfarth
%Program used to detect differences in images
%Used as a baseline utility to understand the
%process of detecting people in a live camera
%feed versus a static image of the background.

clear all
close all
close all hidden

%User input section: get file names
file1 = input('Enter the name of the background file without the file''s extention. ', 's');
fileEx1 = input('Now enter the file extention. ', 's');

disp(' ');

file2 = input('Enter the name of the live file without the file''s extention. ', 's');
fileEx2 = input('Now enter the file extention. ', 's');


%Read images
im1 = imread(strcat(file1, '.', fileEx1));
im2 = imread(strcat(file2, '.', fileEx2));

%Subtract the background from the live image
im3 = im2 - im1;
%Display result
disp(' ');
disp('Showing the processed image.');

%Calculations to determine if a "person" is present.
    %Takes the sum of the maximum values
if(sum(sum(max(im3))) > 25000)
    disp('There is a person in the room.');
    disp('The room is empty.');

disp('The result of a sum of max values:');

disp(sum(sum(max(im3))) - 25000);
disp('A higher number generally indicates a larger "blob."');


 The Real-Time Workshop mentioned above proved to be unattainable without a license, so it was not possible to use the code above directly in our project.

Project Links:


Project Proposal

Detection Method

Sensor Design and Construction

Test Room

VGA Sensor Display 

Control Logic


Conclusions and Future Work