Thread Subject: Motion Sensor, unable to find the threshold, image differences problem. Important !

Subject: Motion Sensor, unable to find the threshold, image differences problem. Important !

From: Ongun Palaoglu

Date: 4 Apr, 2009 23:47:38

Message: 1 of 9

Hello guys, I almost completed my project. I am designing a motion sensor. I am done with my GUI. I have questions about subtracting images and finding the threshold.

This is my code.

function main

clc;
clear;

global filename;
global z;



%Figure
fig = figure('uni','pix','pos',[600 550 400 300],'menub','no','na',...
    'Junior Design','resize','off','color',[.8 .8 .8],...
    'numbert','of');
bkgc = [0.83 0.82 0.78];

%Frame #1
frm1 = uicontrol(fig,'sty','fr','pos',[40 230 170 60],'backg',bkgc);

txt0 = uicontrol(fig,'sty','te','pos',[75 265 100 20],'backg',...
    [.85 .85 .85],'str','Video file Selection','fontw','bo',...
    'fonts',10);
%Button #2
handles.pushbutton1=uicontrol(fig,'sty','pushbutton',...
    'str','Browse',...
    'position',[60 240 130 20],...
    'tooltipstring','Choose the Video File');

set(handles.pushbutton1,'callback',{@pushbutton1_callback,handles});

%Frame #2
frm2 = uicontrol(fig,'sty','fr','pos',[40 150 270 60],'backg',bkgc);

txt1 = uicontrol(fig,'sty','te','pos',[130 185 100 20],'backg',...
    [.85 .85 .85],'str','Start','fontw','bo');
%Button #2
handles.playbutton=uicontrol(fig,'style','pushbutton',...
    'string','Start',...
    'position',[150 160 65 20],...
    'tooltipstring','Start');

set(handles.playbutton,'callback',{@playbutton_callback,handles});

end

%call Back Functions

function pushbutton1_callback(gcf,event_data,handles)

global filename;

[filename, pathname] = uigetfile({'*.avi';'*.mpg'} );

if isequal(filename,0) || isequal(pathname,0)
    disp('User pressed cancel')
else
    disp(['User selected ', fullfile(pathname, filename)]);
    filename=mmreader(filename);
end
end


function playbutton_callback(gcf,event_data,handles)

global filename;
obj = filename;
vidFrames = read(obj);
numFrames = get(obj, 'numberOfFrames');

% reading each frame

for k=1:numFrames
    img(k).cdata = vidFrames(:,:,:,k);
    img(k).colormap = [];
end

% finding threshold
for n=2:numFrames
    global z;
    
    d(i)=sum(sum(uint8(img(n-1).cdata)-uint8(img(n).cdata)));
   
    z=mean(d);
end

%detecting motion
k=1;
for j=1:numFrames
    y=abs(sum(sum(img(k).cdata-img(j).cdata)));
    disp(y);
    if y>=z
        k==y;
        disp('Motion Detected')
    end
end
end

1. I want to find the threshold by average differences of the pictures in a row.
   a. MATLAB displays"Subscript indices must either be real positive integers or logicals."
error " , can someone help me with this part of the code.

2. while detecting motion. I am simply comparing previous image(reference) with the current one, if it is more than the threshold,current frame becomes my reference frame

. Thank you very much.

By the way I want to say thank you to Matt Figg, I used his imsubtract code as reference.!


   

Subject: Motion Sensor, unable to find the threshold, image differences problem. Important !

From: Image Analyst

Date: 5 Apr, 2009 00:57:01

Message: 2 of 9

Ongun Palaoglu
1. In d(i)=sum(sum(uint8(img(n-1).cdata)-uint8(img(n).cdata)));
can you tell me what value i has? I thought not.
2. This is not a question.
Good luck,
ImageAnalyst

Subject: Motion Sensor, unable to find the threshold, image differences problem. Important !

From: Ongun Palaoglu

Date: 5 Apr, 2009 02:48:01

Message: 3 of 9

Hey, i is a matrix, I collect all the values of output in i matrix then I find the mean value of that!

Subject: Motion Sensor, unable to find the threshold, image differences

From: ImageAnalyst

Date: 5 Apr, 2009 14:37:53

Message: 4 of 9

On Apr 4, 10:48=A0pm, "Ongun Palaoglu" <on...@mac.com> wrote:
> Hey, =A0i is a matrix, I collect all the values of output in i matrix the=
n I find the mean value of that!

-----------------------------------------------------------
Ongun Palaoglu:
i can be a matrix, though we don't advise using i since it's also sqrt
(-1) and that opens up the possibility of problems. Excuse me for not
seeing where you defined i, but I looked again in your
playbutton_callback() and I still don't see where it is defined. If
you put a breakpoint there, does it give any values? Are they foating
point or integer or logical? If you do see values in the debugger,
then perhaps you just snipped out some of your code before you posted
it.

And #2 is "still" not a question.
Regards,
ImageAnalyst

Subject: Motion Sensor, unable to find the threshold, image differences

From: Ongun Palaoglu

Date: 5 Apr, 2009 17:13:01

Message: 5 of 9

Hey, Yes i did not defined i. I thought , since it is on the left side of the equation I thought it is not necessary. I am getting different error.

"Subscript indices must either be real positive integers or logicals."

my second question is. about my last art of the code, is it a good way to find the motion ?

* possibly,there are many errors , I am newbie to Matlab. I apology.

Thank you.

Subject: Motion Sensor, unable to find the threshold, image differences

From: ImageAnalyst

Date: 5 Apr, 2009 20:04:59

Message: 6 of 9

On Apr 5, 1:13=A0pm, "Ongun Palaoglu" <on...@mac.com> wrote:
> Hey, =A0Yes =A0i did not defined i. =A0I thought , since it is on the lef=
t side of the equation I thought it is =A0not necessary. I am getting diffe=
rent error.
>
> "Subscript indices must either be real positive integers or logicals."
>
> my second question is. about my last art of the code, is it a good way to=
 find the motion ?
>
> * possibly,there are many errors , I am newbie to Matlab. I apology.
>
> Thank you.
---------------------------------------------------------------------------=
--------------

Your "i" is not on the left side of an assignment - your i is inside
parentheses. That means it must already have some values defined.
Since you don't, you are getting the error message. I don't see
different error messages - I see only the one that you posted.

I'm not an expert on motion estimation. I suggest you look here for
suggestions:

http://iris.usc.edu/Vision-Notes/bibliography/contentsmotion-f.html#Motion%=
20--%20Feature-Based,%20Long%20Range,%20Motion%20and%20Structure%20Estimate=
s,%20Tracking,%20Surveillance,%20Activities

http://www.mee.tcd.ie/~sigmedia/Research/RigRemoval

Good luck,
ImageAnalyst

Subject: Motion Sensor, unable to find the threshold, image differences

From: Ongun Palaoglu

Date: 5 Apr, 2009 22:23:01

Message: 7 of 9

Hey, How can I fix that part?

Subject: Motion Sensor, unable to find the threshold, image differences

From: Image Analyst

Date: 5 Apr, 2009 23:19:01

Message: 8 of 9

"Ongun Palaoglu" <ongun@mac.com> wrote in message <grbb05$bdh$1@fred.mathworks.com>...
> Hey, How can I fix that part?
-----------------------------------------------------------------------
With a spark of brilliance, sheer ingenuity, confidence in your abilities, hard work, and dedication to getting it right. Plus MATLAB.

Subject: Motion Sensor, unable to find the threshold, image differences

From: Ongun Palaoglu

Date: 6 Apr, 2009 00:34:01

Message: 9 of 9

=) very encouraging thank you

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
threshold Ongun Palaoglu 4 Apr, 2009 19:50:04
image subtraction Ongun Palaoglu 4 Apr, 2009 19:50:04
motion detection Ongun Palaoglu 4 Apr, 2009 19:50:04
rssFeed for this Thread

Contact us at files@mathworks.com