<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Randomizing Discovery // Life :: Work :: Play &#187; convolution</title>
	<atom:link href="http://www.randomizingdiscovery.com/tag/convolution/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.randomizingdiscovery.com</link>
	<description>Exploring basic programmatic concepts to create complex visualizations. The work and experiments of Corey Hankey. Processing, Actionscript,  Web Development.</description>
	<lastBuildDate>Sat, 06 Mar 2010 19:39:52 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Detecting Motion.</title>
		<link>http://www.randomizingdiscovery.com/2008/06/28/detecting-motion/</link>
		<comments>http://www.randomizingdiscovery.com/2008/06/28/detecting-motion/#comments</comments>
		<pubDate>Sat, 28 Jun 2008 05:28:27 +0000</pubDate>
		<dc:creator>chankey</dc:creator>
				<category><![CDATA[Discoveries]]></category>
		<category><![CDATA[convolution]]></category>
		<category><![CDATA[image manipulation]]></category>
		<category><![CDATA[motion detection]]></category>
		<category><![CDATA[proce55ing]]></category>
		<category><![CDATA[Processing]]></category>

		<guid isPermaLink="false">http://www.randomizingdiscovery.com/?p=18</guid>
		<description><![CDATA[After taking a little time to research how other people were creating motion detection algorithms I decided to go with using the difference blend mode to detect what was changing from frame to frame. The first few tests I ran were very efficient but the results were not very accurate. I created a previous and [...]]]></description>
			<content:encoded><![CDATA[<p>After taking a little time to research how other people were creating motion detection algorithms I decided to go with using the difference blend mode to detect what was changing from frame to frame. The first few tests I ran were very efficient but the results were not very accurate. I created a previous and next pixel array that stored the two images&#8217; data and then blended the two images together into a new pixel array.</p>
<p>Now that I had all the pixel data I took a closer look at the convolution filter section in the Processing book. Convolution filters enhance certain features in an the image based on a multi-dimensional kernel array that is used to manipulate the pixels. After a little work and some experimenting I found a kernel that enhanced the motion changes in the image.</p>
<p>The problem now was that this process was very processor intensive and wouldn&#8217;t allow for more features to be added to the program. I shrank the camera capture dimensions and ran the algorithm on the new pixel data. Then I just scaled the final pixel data to fit the screen as it was drawn. This change took the load on the processor down from 50% to 27% while keeping the results of the motion detection.</p>
<p>Here are the Results (application zip): <a href="http://content.coreyhankey.com/motion_detect_01/motion_detect.zip" target="_blank">Motion Detection 01</a></p>
<pre class="brush: java">
import processing.video.*;
Capture cam;
PImage prev;
PImage cur;
int count;
// convolution kernal
float[][] kernal = { { -1, -2, -1 },
                     { 0, 0, 0 },
                     { 1, 2, 1 } };

void setup() {

  size(640, 480);
  count = 0;
  // If no device is specified, will just use the default.
  cam = new Capture(this, 320, 240);
  frameRate(24);
  // create previous and current images =====
  prev = createImage(width/2, height/2, RGB);
  cur = createImage(width/2, height/2, RGB);
  prev.loadPixels();
  cur.loadPixels();
}

void draw() {

  if (cam.available() == true) {
     cam.read();
    // capture every third frame into the previous image
    // this can be changed to get more drastic results =
    if(count &gt; 2)
    {
      arraycopy(cur.pixels, prev.pixels);
      count = 0;
    }
    count ++;
    cam.loadPixels();
    cur.pixels = cam.pixels;
    prev.updatePixels();
    cur.updatePixels();

    // calculate the difference in the 2 frames ==================
    cur.blend(prev,0,0,width/2,height/2,0,0,width/2,height/2, DIFFERENCE);
    cur.loadPixels();

    // create a new image to store the pixel data in =================
    PImage eImg = createImage(320, 240, RGB);

    // run convolution filter =============
    // from book : Processing pg. 360 =====
    for(int y = 1; y &lt; 240-1; y++)
    {
      for(int x =1; x &lt; 320-1; x++)
       {
          float sum = 0;
          for(int ky = -1; ky &lt;= 1; ky ++)
          {
            for(int kx= -1; kx &lt;= 1; kx ++)
            {
              // calc next pixel =========
              int pos = (y+ky)*320 + (x+kx);
              float val = red(cur.pixels[pos]);
              sum += kernal[ky+1][kx+1]+ val;
            }
          }
          eImg.pixels[y*320 + x] = color(sum);
       }
    }
     eImg.updatePixels();
     // scale image up to fill th screen ===========
     scale(2,2);

     // draw manipulated data to the screen =========
     image(eImg, 0,0);

     // thresh hold filter converts to black and white only ====
     filter(THRESHOLD, .95);
  }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.randomizingdiscovery.com/2008/06/28/detecting-motion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
