<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/248358</link>
    <title>MATLAB Central Newsreader - Motion Sensor, unable to find the threshold, image differences problem. Important !</title>
    <description>Feed for thread: Motion Sensor, unable to find the threshold, image differences problem. Important !</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Sat, 04 Apr 2009 23:47:38 -0400</pubDate>
      <title>Motion Sensor, unable to find the threshold, image differences problem. Important !</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/248358#640348</link>
      <author>Ongun Palaoglu</author>
      <description>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. &lt;br&gt;
&lt;br&gt;
This is my code.&lt;br&gt;
&lt;br&gt;
function main&lt;br&gt;
&lt;br&gt;
clc;&lt;br&gt;
clear;&lt;br&gt;
&lt;br&gt;
global filename;&lt;br&gt;
global z;&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
%Figure&lt;br&gt;
fig = figure('uni','pix','pos',[600 550 400 300],'menub','no','na',...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'Junior Design','resize','off','color',[.8 .8 .8],...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'numbert','of');&lt;br&gt;
bkgc = [0.83    0.82    0.78];&lt;br&gt;
&lt;br&gt;
%Frame #1&lt;br&gt;
frm1 = uicontrol(fig,'sty','fr','pos',[40 230 170 60],'backg',bkgc);&lt;br&gt;
&lt;br&gt;
txt0 = uicontrol(fig,'sty','te','pos',[75 265 100 20],'backg',...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[.85 .85 .85],'str','Video file Selection','fontw','bo',...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'fonts',10);&lt;br&gt;
%Button #2&lt;br&gt;
handles.pushbutton1=uicontrol(fig,'sty','pushbutton',...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'str','Browse',...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'position',[60 240 130 20],...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'tooltipstring','Choose the Video File');&lt;br&gt;
&lt;br&gt;
set(handles.pushbutton1,'callback',{@pushbutton1_callback,handles});&lt;br&gt;
&lt;br&gt;
%Frame #2&lt;br&gt;
frm2 = uicontrol(fig,'sty','fr','pos',[40 150 270 60],'backg',bkgc);&lt;br&gt;
&lt;br&gt;
txt1 = uicontrol(fig,'sty','te','pos',[130 185 100 20],'backg',...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[.85 .85 .85],'str','Start','fontw','bo');&lt;br&gt;
%Button #2&lt;br&gt;
handles.playbutton=uicontrol(fig,'style','pushbutton',...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'string','Start',...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'position',[150 160 65 20],...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'tooltipstring','Start');&lt;br&gt;
&lt;br&gt;
set(handles.playbutton,'callback',{@playbutton_callback,handles});&lt;br&gt;
&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
%call Back Functions&lt;br&gt;
&lt;br&gt;
function pushbutton1_callback(gcf,event_data,handles)&lt;br&gt;
&lt;br&gt;
global filename;&lt;br&gt;
&lt;br&gt;
[filename, pathname] = uigetfile({'*.avi';'*.mpg'} );&lt;br&gt;
&lt;br&gt;
if isequal(filename,0) || isequal(pathname,0)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;disp('User pressed cancel')&lt;br&gt;
else&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;disp(['User selected ', fullfile(pathname, filename)]);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;filename=mmreader(filename);&lt;br&gt;
end&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
function playbutton_callback(gcf,event_data,handles)&lt;br&gt;
&lt;br&gt;
global filename;&lt;br&gt;
obj       = filename;&lt;br&gt;
vidFrames = read(obj);&lt;br&gt;
numFrames = get(obj, 'numberOfFrames');&lt;br&gt;
&lt;br&gt;
% reading each frame&lt;br&gt;
&lt;br&gt;
for k=1:numFrames&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;img(k).cdata = vidFrames(:,:,:,k);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;img(k).colormap = [];&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
% finding threshold&lt;br&gt;
for n=2:numFrames&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;global z;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;d(i)=sum(sum(uint8(img(n-1).cdata)-uint8(img(n).cdata)));&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;z=mean(d);&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
%detecting motion&lt;br&gt;
k=1;&lt;br&gt;
for j=1:numFrames&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;y=abs(sum(sum(img(k).cdata-img(j).cdata)));&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;disp(y);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if y&amp;gt;=z&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;k==y;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;disp('Motion Detected')&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end&lt;br&gt;
end&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
1. I want to find the threshold by average differences of the pictures in a row.&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;a. MATLAB displays&quot;Subscript indices must either be real positive integers or logicals.&quot;&lt;br&gt;
error &quot; , can someone help me with this part of the code.&lt;br&gt;
&lt;br&gt;
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&lt;br&gt;
&lt;br&gt;
. Thank you very much.&lt;br&gt;
&lt;br&gt;
By the way I want to say thank you to Matt Figg, I used his imsubtract code as reference.!&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;</description>
    </item>
    <item>
      <pubDate>Sun, 05 Apr 2009 00:57:01 -0400</pubDate>
      <title>Re: Motion Sensor, unable to find the threshold, image differences problem. Important !</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/248358#640356</link>
      <author>Image Analyst</author>
      <description>Ongun Palaoglu&lt;br&gt;
1.  In  d(i)=sum(sum(uint8(img(n-1).cdata)-uint8(img(n).cdata)));&lt;br&gt;
can you tell me what value i has?  I thought not.&lt;br&gt;
2.  This is not a question.&lt;br&gt;
Good luck,&lt;br&gt;
ImageAnalyst</description>
    </item>
    <item>
      <pubDate>Sun, 05 Apr 2009 02:48:01 -0400</pubDate>
      <title>Re: Motion Sensor, unable to find the threshold, image differences problem. Important !</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/248358#640365</link>
      <author>Ongun Palaoglu</author>
      <description>Hey,  i is a matrix, I collect all the values of output in i matrix then I find the mean value of that!</description>
    </item>
    <item>
      <pubDate>Sun, 05 Apr 2009 14:37:53 -0400</pubDate>
      <title>Re: Motion Sensor, unable to find the threshold, image differences </title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/248358#640444</link>
      <author>ImageAnalyst</author>
      <description>On Apr 4, 10:48=A0pm, &quot;Ongun Palaoglu&quot; &amp;lt;on...@mac.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; Hey, =A0i is a matrix, I collect all the values of output in i matrix the=&lt;br&gt;
n I find the mean value of that!&lt;br&gt;
&lt;br&gt;
-----------------------------------------------------------&lt;br&gt;
Ongun Palaoglu:&lt;br&gt;
i can be a matrix, though we don't advise using i since it's also sqrt&lt;br&gt;
(-1) and that opens up the possibility of problems.  Excuse me for not&lt;br&gt;
seeing where you defined i, but I looked again in your&lt;br&gt;
playbutton_callback() and I still don't see where it is defined.  If&lt;br&gt;
you put a breakpoint there, does it give any values?  Are they foating&lt;br&gt;
point or integer or logical?  If you do see values in the debugger,&lt;br&gt;
then perhaps you just snipped out some of your code before you posted&lt;br&gt;
it.&lt;br&gt;
&lt;br&gt;
And #2 is &quot;still&quot; not a question.&lt;br&gt;
Regards,&lt;br&gt;
ImageAnalyst</description>
    </item>
    <item>
      <pubDate>Sun, 05 Apr 2009 17:13:01 -0400</pubDate>
      <title>Re: Motion Sensor, unable to find the threshold, image differences</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/248358#640470</link>
      <author>Ongun Palaoglu</author>
      <description>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.&lt;br&gt;
&lt;br&gt;
&quot;Subscript indices must either be real positive integers or logicals.&quot;&lt;br&gt;
&lt;br&gt;
my second question is. about my last art of the code, is it a good way to find the motion ? &lt;br&gt;
&lt;br&gt;
* possibly,there are many errors , I am newbie to Matlab. I apology. &lt;br&gt;
&lt;br&gt;
Thank you.</description>
    </item>
    <item>
      <pubDate>Sun, 05 Apr 2009 20:04:59 -0400</pubDate>
      <title>Re: Motion Sensor, unable to find the threshold, image differences</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/248358#640500</link>
      <author>ImageAnalyst</author>
      <description>On Apr 5, 1:13=A0pm, &quot;Ongun Palaoglu&quot; &amp;lt;on...@mac.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; Hey, =A0Yes =A0i did not defined i. =A0I thought , since it is on the lef=&lt;br&gt;
t side of the equation I thought it is =A0not necessary. I am getting diffe=&lt;br&gt;
rent error.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &quot;Subscript indices must either be real positive integers or logicals.&quot;&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; my second question is. about my last art of the code, is it a good way to=&lt;br&gt;
&amp;nbsp;find the motion ?&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; * possibly,there are many errors , I am newbie to Matlab. I apology.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Thank you.&lt;br&gt;
---------------------------------------------------------------------------=&lt;br&gt;
--------------&lt;br&gt;
&lt;br&gt;
Your &quot;i&quot; is not on the left side of an assignment - your i is inside&lt;br&gt;
parentheses.  That means it must already have some values defined.&lt;br&gt;
Since you don't, you are getting the error message.  I don't see&lt;br&gt;
different error messages - I see only the one that you posted.&lt;br&gt;
&lt;br&gt;
I'm not an expert on motion estimation.  I suggest you look here for&lt;br&gt;
suggestions:&lt;br&gt;
&lt;br&gt;
&lt;a href=&quot;http://iris.usc.edu/Vision-Notes/bibliography/contentsmotion-f.html#Motion%=&quot;&gt;http://iris.usc.edu/Vision-Notes/bibliography/contentsmotion-f.html#Motion%=&lt;/a&gt;&lt;br&gt;
20--%20Feature-Based,%20Long%20Range,%20Motion%20and%20Structure%20Estimate=&lt;br&gt;
s,%20Tracking,%20Surveillance,%20Activities&lt;br&gt;
&lt;br&gt;
&lt;a href=&quot;http://www.mee.tcd.ie/~sigmedia/Research/RigRemoval&quot;&gt;http://www.mee.tcd.ie/~sigmedia/Research/RigRemoval&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
Good luck,&lt;br&gt;
ImageAnalyst</description>
    </item>
    <item>
      <pubDate>Sun, 05 Apr 2009 22:23:01 -0400</pubDate>
      <title>Re: Motion Sensor, unable to find the threshold, image differences</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/248358#640521</link>
      <author>Ongun Palaoglu</author>
      <description>Hey, How can I fix that part? </description>
    </item>
    <item>
      <pubDate>Sun, 05 Apr 2009 23:19:01 -0400</pubDate>
      <title>Re: Motion Sensor, unable to find the threshold, image differences</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/248358#640533</link>
      <author>Image Analyst</author>
      <description>&quot;Ongun Palaoglu&quot; &amp;lt;ongun@mac.com&amp;gt; wrote in message &amp;lt;grbb05$bdh$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hey, How can I fix that part? &lt;br&gt;
-----------------------------------------------------------------------&lt;br&gt;
With a spark of brilliance, sheer ingenuity, confidence in your abilities, hard work, and dedication to getting it right.  Plus MATLAB.</description>
    </item>
    <item>
      <pubDate>Mon, 06 Apr 2009 00:34:01 -0400</pubDate>
      <title>Re: Motion Sensor, unable to find the threshold, image differences</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/248358#640543</link>
      <author>Ongun Palaoglu</author>
      <description>=) very encouraging thank you</description>
    </item>
  </channel>
</rss>

