<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Brett Walenz</title>
	<atom:link href="http://brettwalenz.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://brettwalenz.org</link>
	<description>Interpretation Error</description>
	<lastBuildDate>Tue, 15 May 2012 20:08:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='brettwalenz.org' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Brett Walenz</title>
		<link>http://brettwalenz.org</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://brettwalenz.org/osd.xml" title="Brett Walenz" />
	<atom:link rel='hub' href='http://brettwalenz.org/?pushpress=hub'/>
		<item>
		<title>FFmpeg build dependency order</title>
		<link>http://brettwalenz.org/2012/01/29/ffmpeg-build-dependency-order/</link>
		<comments>http://brettwalenz.org/2012/01/29/ffmpeg-build-dependency-order/#comments</comments>
		<pubDate>Sun, 29 Jan 2012 16:43:38 +0000</pubDate>
		<dc:creator>bwalenz</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://brettwalenz.org/2012/01/29/ffmpeg-build-dependency-order/</guid>
		<description><![CDATA[I&#8217;m not sure why this gave me such trouble, but to build properly under Linux I couldn&#8217;t find the correct build order (with all the split out libraries now), so here&#8217;s what I used: -lavformat -lavcodec -lavdevice -lavfilter -lavutil -lz -lm -lswscale -lSDL Here&#8217;s hoping! <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brettwalenz.org&#038;blog=8459579&#038;post=188&#038;subd=bwalenz&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m not sure why this gave me such trouble, but to build properly under Linux I couldn&#8217;t find the correct build order (with all the split out libraries now), so here&#8217;s what I used:</p>
<p>-lavformat -lavcodec -lavdevice -lavfilter -lavutil -lz -lm -lswscale -lSDL</p>
<p>Here&#8217;s hoping! </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bwalenz.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bwalenz.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bwalenz.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bwalenz.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bwalenz.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bwalenz.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bwalenz.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bwalenz.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bwalenz.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bwalenz.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bwalenz.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bwalenz.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bwalenz.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bwalenz.wordpress.com/188/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brettwalenz.org&#038;blog=8459579&#038;post=188&#038;subd=bwalenz&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://brettwalenz.org/2012/01/29/ffmpeg-build-dependency-order/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0cfb052531593c46dfbabf7a8c77804b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bwalenz</media:title>
		</media:content>
	</item>
		<item>
		<title>Thoughts on the Stanford Online Machine Learning course</title>
		<link>http://brettwalenz.org/2011/12/14/thoughts-on-the-stanford-online-machine-learning-course/</link>
		<comments>http://brettwalenz.org/2011/12/14/thoughts-on-the-stanford-online-machine-learning-course/#comments</comments>
		<pubDate>Wed, 14 Dec 2011 17:30:45 +0000</pubDate>
		<dc:creator>bwalenz</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://brettwalenz.org/?p=173</guid>
		<description><![CDATA[This week is the last week of the Stanford Machine Learning course (ml-class.org), so here is my basic review of the course. Overall, the quality is quite good. The lectures are easily the most valuable part, as Andrew Ng is very organized and provides insightful explanations over the approaches and algorithms. The homework problems use [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brettwalenz.org&#038;blog=8459579&#038;post=173&#038;subd=bwalenz&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This week is the last week of the Stanford Machine Learning course (ml-class.org), so here is my basic review of the course. Overall, the quality is quite good. The lectures are easily the most valuable part, as Andrew Ng is very organized and provides insightful explanations over the approaches and algorithms. </p>
<p>The homework problems use Octave, a mostly clone version of Matlab (including down to language spec), so it&#8217;s pretty easy to pick up for most math-inclined people. </p>
<p>The homework assignments themselves were mildly&#8230; disappointing? I&#8217;m not sure that&#8217;s the right word, but I feel they were really lacking in improving understanding of the primary concept at hand. At the start of the course, the homework assignments are concerned with implementing cost functions for linear regression and neural networks. At the end of the course, the homework assignments are concerned with implementing cost functions for k-means clustering &#8211; so it gets fairly repetitive, and doesn&#8217;t really make you aware of the steps involved with the different algorithms. Most of the supporting code that goes into the algorithms is written for you by the course team. Let&#8217;s take a look at what I mean.</p>
<p>In the following example, the course walks you through a collaborative filtering example to recommend movies that you might enjoy based on previous ratings. There are a number of steps that go into it:</p>
<ol>
<li>Load the data</li>
<li>Normalize the ratings</li>
<li>Set initial values for X and Theta</li>
<li>Create a cost function</li>
<li>Find values of Theta that minimize the cost function</li>
<li>Use X and Theta to produce a prediction</li>
</ol>
<p></p>
<p>In this assignment, the only step you do is 4. Creating a cost function, so you don&#8217;t really get a sense of what is going on unless you step through the code yourself, and it generally moves fast enough that I&#8217;m guessing most people don&#8217;t. And, for the most part, that&#8217;s my only criticism. The course does talk about, from week to week, mean normalization, regularization, etc., but you never really &#8216;connect the dots&#8217; in an assignment. It&#8217;s always:</p>
<ul>
<li>Fill out formula</li>
<li>Run magic program</li>
<li>Did formula look right? If so, submit.</li>
<li>If not, look at formula again.</li>
</ul>
<p></p>
<p>Gripe aside, again, I really enjoyed the class. The lectures really are outstanding. And he pays a lot of attention at the start to talk about regression (linear and logistic), and neural networks &#8211; while explaining them in a clear and concise manner, avoiding a lot of ugly statistics that most people get lost in. Actually, that&#8217;s another nice part. He does a really good job of mixing data mining terms and statistics terms so that you understand there are multiple ways to describe something. That way if you go someplace else to read about it, you won&#8217;t be lost(weights vs. parameters, fitting vs. learning). </p>
<p>The other topics covered are SVM&#8217;s, K-means clustering, anomaly detection, and practical applications of machine learning, as well as some large scale discussions.</p>
<p>So I&#8217;d recommend it, with one caveat &#8211; make sure you don&#8217;t fall into the trap of &#8220;make formula go&#8221;, and understand the underlying connecting parts.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bwalenz.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bwalenz.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bwalenz.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bwalenz.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bwalenz.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bwalenz.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bwalenz.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bwalenz.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bwalenz.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bwalenz.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bwalenz.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bwalenz.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bwalenz.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bwalenz.wordpress.com/173/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brettwalenz.org&#038;blog=8459579&#038;post=173&#038;subd=bwalenz&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://brettwalenz.org/2011/12/14/thoughts-on-the-stanford-online-machine-learning-course/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0cfb052531593c46dfbabf7a8c77804b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bwalenz</media:title>
		</media:content>
	</item>
		<item>
		<title>FFMpeg Shared Libraries, Relocation Errors, Etc.</title>
		<link>http://brettwalenz.org/2011/08/17/ffmpeg-shared-libraries-relocation-errors-etc/</link>
		<comments>http://brettwalenz.org/2011/08/17/ffmpeg-shared-libraries-relocation-errors-etc/#comments</comments>
		<pubDate>Wed, 17 Aug 2011 20:35:10 +0000</pubDate>
		<dc:creator>bwalenz</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://brettwalenz.org/?p=154</guid>
		<description><![CDATA[After installing OpenCV 2.2 and FFMpeg 7.1 on Ubuntu 11.04, I wasn&#8217;t able to run FFMpeg because of linker issues. Turns out the problem was my system wasn&#8217;t aware of /usr/local/lib which is where the built libraries got placed. So I ended up getting errors like: You can do something fairly easy which might fix [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brettwalenz.org&#038;blog=8459579&#038;post=154&#038;subd=bwalenz&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>After installing OpenCV 2.2 and FFMpeg 7.1 on Ubuntu 11.04, I wasn&#8217;t able to run FFMpeg because of linker issues. Turns out the problem was my system wasn&#8217;t aware of /usr/local/lib which is where the built libraries got placed. So I ended up getting errors like:</p>
<p><pre class="brush: plain;">
ffmpeg: relocation error: /usr/local/lib/libavfilter.so.1: symbol av_expr_free, version LIBAVUTIL_50 not defined in file libavutil.so.50 with link time reference
</pre></p>
<p>You can do something fairly easy which might fix it:</p>
<p>$ export LD_LIBRARY_PATH=/usr/local/lib</p>
<p>Or you can do this:</p>
<p>There&#8217;s a file in /etc called ld.so.conf. This contains a path to a directory which contains all the ld conf files. In that directory there should be one called libc.conf. Put the line /usr/local/lib in there (or if it already is), then run:</p>
<p>$ sudo ldconfig -v</p>
<p>This reloads the ld cache. If the file IS NOT there, then you can create one called /etc/ld.so.conf.d/ffmpeg.conf and add the line, then rerun sudo ldconfig -v. This should point ffmpeg to the proper files.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bwalenz.wordpress.com/154/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bwalenz.wordpress.com/154/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bwalenz.wordpress.com/154/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bwalenz.wordpress.com/154/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bwalenz.wordpress.com/154/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bwalenz.wordpress.com/154/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bwalenz.wordpress.com/154/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bwalenz.wordpress.com/154/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bwalenz.wordpress.com/154/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bwalenz.wordpress.com/154/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bwalenz.wordpress.com/154/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bwalenz.wordpress.com/154/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bwalenz.wordpress.com/154/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bwalenz.wordpress.com/154/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brettwalenz.org&#038;blog=8459579&#038;post=154&#038;subd=bwalenz&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://brettwalenz.org/2011/08/17/ffmpeg-shared-libraries-relocation-errors-etc/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0cfb052531593c46dfbabf7a8c77804b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bwalenz</media:title>
		</media:content>
	</item>
		<item>
		<title>Playing video with OpenCV 2.2, Python, and wxWidgets</title>
		<link>http://brettwalenz.org/2011/08/12/playing-video-with-opencv-2-2-python-and-wxwidgets/</link>
		<comments>http://brettwalenz.org/2011/08/12/playing-video-with-opencv-2-2-python-and-wxwidgets/#comments</comments>
		<pubDate>Fri, 12 Aug 2011 21:08:05 +0000</pubDate>
		<dc:creator>bwalenz</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://brettwalenz.org/?p=148</guid>
		<description><![CDATA[This is a fairly specific entry &#8211; but there&#8217;s a lot of tidbits scattered about here and there that I had to get through to make this work. The basic gist is this: I needed to play back video from a file (or stream) in a toy application I was writing for a project. I&#8217;ve [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brettwalenz.org&#038;blog=8459579&#038;post=148&#038;subd=bwalenz&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This is a fairly specific entry &#8211; but there&#8217;s a lot of tidbits scattered about here and there that I had to get through to make this work.</p>
<p>The basic gist is this: I needed to play back video from a file (or stream) in a toy application I was writing for a project. I&#8217;ve been encoding stuff using x264 and ffmpeg, so I figured anything that took advantage of the same libraries would be a big help, and OpenCV has a lot of other useful algorithms.</p>
<p>So first, install OpenCV, Python, and wxPython. This writing works with OpenCV 2.2, Python 2.7, and wxPython 2.8. On Ubuntu 11.04.</p>
<p>For installing these things on Ubuntu 11.04, you can follow the <a href="http://www.samontab.com/web/2011/06/installing-opencv-2-2-in-ubuntu-11-04/">guide</a>.</p>
<p>So now it&#8217;s pretty straightforward. The process is:</p>
<p>1. Load the file through OpenCV.<br />
2. Create a timer using wx that simulate the FPS of the video.<br />
3. On each tick, grab the next frame from OpenCV, and display it<br />
on the panel. </p>
<p>The entire code is located on my <a href="https://bitbucket.org/bwalenz/random/src">bitbucket repository</a>, under player.py. </p>
<p>The only tricky bit is when you try to switch between OpenCV&#8217;s frame and a wx Bitmap:</p>
<p><pre class="brush: plain;">
def createBitmap(self, frame):
        # Convert the color to the space wx works in. 
        cv.CvtColor(frame, frame, cv.CV_BGR2RGB)
            
        Img = wx.EmptyImage(frame.width, frame.height)
        # Unsure why this works, assuming frame.tostring() places it in a well-known format
        Img.SetData(frame.tostring())
        
        return wx.BitmapFromImage(Img)
</pre></p>
<p>Also I found the wxPython documentation fairly out of date, and the OpenCV Python interface has changed a lot, so be wary of reading things that don&#8217;t tell you what version it&#8217;s for. </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bwalenz.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bwalenz.wordpress.com/148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bwalenz.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bwalenz.wordpress.com/148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bwalenz.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bwalenz.wordpress.com/148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bwalenz.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bwalenz.wordpress.com/148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bwalenz.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bwalenz.wordpress.com/148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bwalenz.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bwalenz.wordpress.com/148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bwalenz.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bwalenz.wordpress.com/148/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brettwalenz.org&#038;blog=8459579&#038;post=148&#038;subd=bwalenz&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://brettwalenz.org/2011/08/12/playing-video-with-opencv-2-2-python-and-wxwidgets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0cfb052531593c46dfbabf7a8c77804b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bwalenz</media:title>
		</media:content>
	</item>
		<item>
		<title>Video coding concepts</title>
		<link>http://brettwalenz.org/2011/07/28/video-coding-concepts/</link>
		<comments>http://brettwalenz.org/2011/07/28/video-coding-concepts/#comments</comments>
		<pubDate>Thu, 28 Jul 2011 18:38:50 +0000</pubDate>
		<dc:creator>bwalenz</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://brettwalenz.org/?p=142</guid>
		<description><![CDATA[This is mostly just a reference post for me to assemble thoughts on what I&#8217;ve read about video encoding over the past couple of days. It might not make much sense. First, a good starting point is the book H.264 &#8211; Advanced Video Compression Standard by Iain E. Richardson. It&#8217;s where I&#8217;ve picked up most [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brettwalenz.org&#038;blog=8459579&#038;post=142&#038;subd=bwalenz&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This is mostly just a reference post for me to assemble thoughts on what I&#8217;ve read about video encoding over the past couple of days. It might not make much sense.</p>
<p>First, a good starting point is the book <a href="http://www.google.com/url?sa=t&amp;source=web&amp;cd=1&amp;ved=0CCQQFjAA&amp;url=http%3A%2F%2Fwww.amazon.com%2FH-264-Advanced-Video-Compression-Standard%2Fdp%2F0470516925&amp;ei=hawxTpOmMYTf0QHQmcXZCw&amp;usg=AFQjCNEhYmbAXOIdyGJfW-gN026VR7deAA&amp;sig2=AWE0wWMQjJl_FUICpcoS4Q">H.264 &#8211; Advanced Video Compression Standard</a> by Iain E. Richardson. It&#8217;s where I&#8217;ve picked up most of the relevant information. The concepts and technologies are pretty involved with a lot of terminology, so the book was helpful in that regard. But if you read Chapter 3, Video Coding Concepts, it&#8217;s a lot easier to understand H.264 and V8.</p>
<p>So how does a video stream go from raw to compressed? It&#8217;s actually a fairly interesting process. In most cases, it goes something like this (although implementations/specs may vary):</p>
<p>1. An input video frame, F, is processed in macroblocks, usually 16 x 16 pixel area of the frame.</p>
<p>2. A motion estimation function finds a 16 x 16 pixel region in the reference frame (usually the previous frame encoded) that most closely matches the current macroblock. The offset between the previous frame&#8217;s position and current is calculated &#8211; this information helps the compression algorithm in the next step and enables compression to continue in the cases where the camera is panning. This offset is called the motion vector.</p>
<p>3. Using the motion vector, a prediction is generated which basically states what the current frame might look like based on the previous frame and motion vector.</p>
<p>4. The prediction is subtracted from the current macroblock and produces a residual macroblock. This residual macroblock represents the regions that have changed since the previous frame, taking into account motion of the camera itself. Therefore, we&#8217;ve now reduced transmission of an entire frames data into only the residual data required to represent change.</p>
<p>5. Now, the residual macroblock undergoes a transformation to reduce the information contents further. This transformation is typically in the form of a Discrete Cosine Transformation, which basically takes a macroblock and translates the values into coefficients of a matrix. This lets the algorithm chop off some of the coefficients since we can fairly closely reconstruct the matrix from a majority of the coefficients. Remember, we are working with small pixel regions so being &#8220;close enough&#8221; is a good trade-off.</p>
<p>6. The coefficients are quantized. Quantization means the removal (or indexing) of unnecessary or repetitive data. In some cases, this can mean a lookup table that is shared by the encoder or decoder for common coefficient sequences.</p>
<p>7. These quantized coefficients are reordered. Since it&#8217;s likely that there are a large number of zero-valued coefficients, special encoding is used to compress these blocks and only represent the non-zero coefficients, called run-level encoding.</p>
<p>8. The coefficients, motion vector and all other header information required for the decoder to recreate the original frames is entropy encoded to create a bitstream. Examples of entropy encoding are Huffman codes or arithmetic coding techniques.</p>
<p>A reverse process is used by the decoder to reproduce the frame/macroblock.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bwalenz.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bwalenz.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bwalenz.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bwalenz.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bwalenz.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bwalenz.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bwalenz.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bwalenz.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bwalenz.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bwalenz.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bwalenz.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bwalenz.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bwalenz.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bwalenz.wordpress.com/142/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brettwalenz.org&#038;blog=8459579&#038;post=142&#038;subd=bwalenz&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://brettwalenz.org/2011/07/28/video-coding-concepts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0cfb052531593c46dfbabf7a8c77804b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bwalenz</media:title>
		</media:content>
	</item>
		<item>
		<title>Integrating Maven, Eclipse, Checkstyle, Findbugs, etc</title>
		<link>http://brettwalenz.org/2011/05/06/integrating-maven-eclipse-checkstyle-findbugs-etc/</link>
		<comments>http://brettwalenz.org/2011/05/06/integrating-maven-eclipse-checkstyle-findbugs-etc/#comments</comments>
		<pubDate>Fri, 06 May 2011 03:27:22 +0000</pubDate>
		<dc:creator>bwalenz</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://brettwalenz.org/?p=139</guid>
		<description><![CDATA[So you want to use Eclipse, Maven, and not have to duplicate Checkstyle, PMD, Findbugs, and all that jazz? Good luck. It&#8217;s *almost* black magic. Random eclipse update sites. Random projects. Clean, Install, hope it runs. So without further adieu, here is the list I use to reliably get my workspace up and running. First, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brettwalenz.org&#038;blog=8459579&#038;post=139&#038;subd=bwalenz&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>So you want to use Eclipse, Maven, and not have to duplicate Checkstyle, PMD, Findbugs, and all that jazz? Good luck. It&#8217;s *almost* black magic. Random eclipse update sites. Random projects. Clean, Install, hope it runs. So without further adieu, here is the list I use to reliably get my workspace up and running.</p>
<p>First, a note on plugins. There are three required plugins that most people get confused about.</p>
<ol>
<li>m2eclipse &#8211; provides base maven-eclipse integration</li>
<li>m2eclipse-extras &#8211; provides integration for web tools platform</li>
<li>m2eclipse-extensions &#8211; provides integration for checkstyle</li>
</ol>
<div>However, unless you randomly find m2eclipse-extensions, you probably won&#8217;t come across it. It&#8217;s sort of buried. Searching for &#8220;maven eclipse&#8221; yields loads of useless links. Dead projects. Stuff you don&#8217;t need. Gah!</div>
<div>So here&#8217;s the order of installation:</div>
<div>
<ol>
<li>Install m2eclipse-0.10 (as of writing) : <a href="http://m2eclipse.sonatype.org/sites/archives/m2e-0.10.2.20100623-1649/">http://m2eclipse.sonatype.org/sites/archives/m2e-0.10.2.20100623-1649/</a></li>
<li>Install m2eclipse-extras WTP integration (for version 0.10): <a href="http://m2eclipse.sonatype.org/sites/archives/m2e-extras-20101029/">http://m2eclipse.sonatype.org/sites/archives/m2e-extras-20101029/</a></li>
<li>Install eclipse-cs: <a href="http://eclipse-cs.sourceforge.net/">http://eclipse-cs.sourceforge.net/</a></li>
<li>Install PMD-eclipse: <a href="http://pmd.sourceforge.net/eclipse/">http://pmd.sourceforge.net/eclipse/</a></li>
<li>Install Findbugs-Eclipse: <a href="http://findbugs.sourceforge.net/manual/eclipse.html">http://findbugs.sourceforge.net/manual/eclipse.html</a></li>
<li>Install m2eclipse-extensions: <a href="http://code.google.com/p/m2e-extensions/">http://code.google.com/p/m2e-extensions/</a></li>
</ol>
<div>The reason 0.10 is required is because m2e-extensions only works with 0.10 (again, as of this writing).</div>
</div>
<div>Once you have all of these installed, if you have your project configured to use any of the checkstyle, pmd, or findbugs projects, reimporting the project should get things working for you.</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bwalenz.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bwalenz.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bwalenz.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bwalenz.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bwalenz.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bwalenz.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bwalenz.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bwalenz.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bwalenz.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bwalenz.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bwalenz.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bwalenz.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bwalenz.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bwalenz.wordpress.com/139/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brettwalenz.org&#038;blog=8459579&#038;post=139&#038;subd=bwalenz&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://brettwalenz.org/2011/05/06/integrating-maven-eclipse-checkstyle-findbugs-etc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0cfb052531593c46dfbabf7a8c77804b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bwalenz</media:title>
		</media:content>
	</item>
		<item>
		<title>.NET Ajax.ActionLink</title>
		<link>http://brettwalenz.org/2011/03/27/net-ajax-actionlink/</link>
		<comments>http://brettwalenz.org/2011/03/27/net-ajax-actionlink/#comments</comments>
		<pubDate>Sun, 27 Mar 2011 01:06:16 +0000</pubDate>
		<dc:creator>bwalenz</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://brettwalenz.org/?p=134</guid>
		<description><![CDATA[@Ajax.ActionLink giving you a brand new page? Wiping away your existing page, when all you wanted to do was update a div? You probably just forgot javascript, or you have them included in the wrong order. Try this in your script definition: &#60;script src="@Url.Content("~/Scripts/jquery-1.4.4.min.js")" type="text/javascript"&#62;&#60;/script&#62; &#60;script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"&#62;&#60;/script&#62; &#60;script src="@Url.Content("~/Scripts/MicrosoftAjax.js")" type="text/javascript"&#62;&#60;/script&#62; &#60;script src="@Url.Content("~/Scripts/MicrosoftMvcAjax.js")" type="text/javascript"&#62;&#60;/script&#62;<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brettwalenz.org&#038;blog=8459579&#038;post=134&#038;subd=bwalenz&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>@Ajax.ActionLink giving you a brand new page? Wiping away your existing page, when all you wanted to do was update a div? </p>
<p>You probably just forgot javascript, or you have them included in the wrong order. </p>
<p>Try this in your script definition:</p>
<p><code></p>
<p>&lt;script src="@Url.Content("~/Scripts/jquery-1.4.4.min.js")" type="text/javascript"&gt;&lt;/script&gt;<br />
    &lt;script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"&gt;&lt;/script&gt;<br />
    &lt;script src="@Url.Content("~/Scripts/MicrosoftAjax.js")" type="text/javascript"&gt;&lt;/script&gt;<br />
    &lt;script src="@Url.Content("~/Scripts/MicrosoftMvcAjax.js")" type="text/javascript"&gt;&lt;/script&gt;</p>
<p></code></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bwalenz.wordpress.com/134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bwalenz.wordpress.com/134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bwalenz.wordpress.com/134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bwalenz.wordpress.com/134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bwalenz.wordpress.com/134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bwalenz.wordpress.com/134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bwalenz.wordpress.com/134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bwalenz.wordpress.com/134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bwalenz.wordpress.com/134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bwalenz.wordpress.com/134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bwalenz.wordpress.com/134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bwalenz.wordpress.com/134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bwalenz.wordpress.com/134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bwalenz.wordpress.com/134/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brettwalenz.org&#038;blog=8459579&#038;post=134&#038;subd=bwalenz&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://brettwalenz.org/2011/03/27/net-ajax-actionlink/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0cfb052531593c46dfbabf7a8c77804b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bwalenz</media:title>
		</media:content>
	</item>
		<item>
		<title>.NET Musings&#8230;</title>
		<link>http://brettwalenz.org/2011/03/26/net-musings/</link>
		<comments>http://brettwalenz.org/2011/03/26/net-musings/#comments</comments>
		<pubDate>Sat, 26 Mar 2011 22:21:40 +0000</pubDate>
		<dc:creator>bwalenz</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://brettwalenz.org/?p=131</guid>
		<description><![CDATA[This post is mostly link spam for my future reference. It could also be called &#8220;Things you should know if you are just entering the .NET world&#8221;. I&#8217;ve just started playing around with things, and it&#8217;s at least interesting so far. I wanted to build a simple web application, so I ran through the MvcMusicStore [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brettwalenz.org&#038;blog=8459579&#038;post=131&#038;subd=bwalenz&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This post is mostly link spam for my future reference. It could also be called &#8220;Things you should know if you are just entering the .NET world&#8221;. I&#8217;ve just started playing around with things, and it&#8217;s at least interesting so far. I wanted to build a simple web application, so I ran through the MvcMusicStore tutorial and was able to following along pretty easily.</p>
<p>.NET and Java EE share a lot in common, unfortunately it&#8217;s enough that when something doesn&#8217;t work things get really confusing. Not only that, but my common resort of &#8220;Consult Google&#8221; doesn&#8217;t work as well for API documentation. So with that said, here&#8217;s the links to the API docs! Never lose these&#8230;</p>
<p>http://msdn.microsoft.com/en-us/library</p>
<p>Secondly, I found the documentation for the MVC Model Binding to be very&#8230; shortcoming. Maybe I&#8217;m just missing it. But this link helped tie things together for me:</p>
<p>http://marcomagdy.com/2009/09/03/asp-net-mvc-model-binding-form-inputs-to-action-parameters/</p>
<p>Lastly, this post was a great help on how to nest a collections and add new items to a collection from a form:</p>
<p>http://jarrettmeyer.com/post/2995732471/nested-collection-models-in-asp-net-mvc-3</p>
<p>Although things didn&#8217;t work out properly, I had to do:</p>
<p><code><br />
 @foreach (var item in Model.Exercises)<br />
            {<br />
                @Html.EditorFor(model =&gt; item, "Exercise")<br />
            }<br />
</code></p>
<p>Instead of:<br />
<code><br />
@Html.EditorFor(model =&gt; model.Exercises)<br />
</code></p>
<p>No clue why. </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bwalenz.wordpress.com/131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bwalenz.wordpress.com/131/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bwalenz.wordpress.com/131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bwalenz.wordpress.com/131/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bwalenz.wordpress.com/131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bwalenz.wordpress.com/131/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bwalenz.wordpress.com/131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bwalenz.wordpress.com/131/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bwalenz.wordpress.com/131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bwalenz.wordpress.com/131/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bwalenz.wordpress.com/131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bwalenz.wordpress.com/131/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bwalenz.wordpress.com/131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bwalenz.wordpress.com/131/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brettwalenz.org&#038;blog=8459579&#038;post=131&#038;subd=bwalenz&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://brettwalenz.org/2011/03/26/net-musings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0cfb052531593c46dfbabf7a8c77804b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bwalenz</media:title>
		</media:content>
	</item>
		<item>
		<title>GEM Graph Layout in JavaScript</title>
		<link>http://brettwalenz.org/2011/01/18/gem-graph-layout-in-javascript/</link>
		<comments>http://brettwalenz.org/2011/01/18/gem-graph-layout-in-javascript/#comments</comments>
		<pubDate>Tue, 18 Jan 2011 01:22:27 +0000</pubDate>
		<dc:creator>bwalenz</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://brettwalenz.org/?p=125</guid>
		<description><![CDATA[Just a short note on what I&#8217;ve been working on lately. First, I put the public version of my master&#8217;s thesis up on https://bitbucket.org/bwalenz/sequencer-thesis. You can browse all the minute details of web crawling with Nutch, parsing documents using OpenNLP, and writing results to a database. I used GWT for visualization purposes, and had to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brettwalenz.org&#038;blog=8459579&#038;post=125&#038;subd=bwalenz&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Just a short note on what I&#8217;ve been working on lately. First, I put the public version of my master&#8217;s thesis up on <a href="https://bitbucket.org/bwalenz">https://bitbucket.org/bwalenz/sequencer-thesis</a>. You can browse all the minute details of web crawling with Nutch, parsing documents using OpenNLP, and writing results to a database. I used GWT for visualization purposes, and had to a bunch of wiring to transfer entities (as in named entities from text) from the database to the user interface.</p>
<p>Some good examples are:</p>
<p>Extracting code from text using OpenNLP and a specialized news article extraction algorithm:</p>
<p><a href="https://bitbucket.org/bwalenz/sequencer-thesis/src/fb19b1ff75be/sequencer.core/src/main/java/org/brettwalenz/sequencer/core/ner/EntityExtractor.java">EntityExtractor</a></p>
<p>Executing a Nutch crawl from a Windows machine using Cygwin: </p>
<p><a href="https://bitbucket.org/bwalenz/sequencer-thesis/src/fb19b1ff75be/sequencer.core/src/main/java/org/brettwalenz/sequencer/processor/NutchProcess.java">NutchProcess</a></p>
<p>On the flip side, here&#8217;s some code sending these extracted entities to GWT&#8217;s client javascript code. Uncommented (here there be dragons):</p>
<p><a href="https://bitbucket.org/bwalenz/sequencer-thesis/src/fb19b1ff75be/webapp/src/main/java/org/brettwalenz/sequencer/webapp/server/AreaChartTopicServlet.java">AreaChartServlet</a></p>
<p>On a completely unrelated note, I&#8217;ve included a JavaScript implementation of the GEM graph layout algorithm at: <a href="https://bitbucket.org/bwalenz/algorithms">https://bitbucket.org/bwalenz/algorithms</a>. If I get more time I&#8217;ll type up the explanation, it&#8217;s pretty neat.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bwalenz.wordpress.com/125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bwalenz.wordpress.com/125/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bwalenz.wordpress.com/125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bwalenz.wordpress.com/125/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bwalenz.wordpress.com/125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bwalenz.wordpress.com/125/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bwalenz.wordpress.com/125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bwalenz.wordpress.com/125/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bwalenz.wordpress.com/125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bwalenz.wordpress.com/125/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bwalenz.wordpress.com/125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bwalenz.wordpress.com/125/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bwalenz.wordpress.com/125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bwalenz.wordpress.com/125/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brettwalenz.org&#038;blog=8459579&#038;post=125&#038;subd=bwalenz&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://brettwalenz.org/2011/01/18/gem-graph-layout-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0cfb052531593c46dfbabf7a8c77804b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bwalenz</media:title>
		</media:content>
	</item>
		<item>
		<title>Centered Interval Trees</title>
		<link>http://brettwalenz.org/2010/09/28/centered-interval-trees/</link>
		<comments>http://brettwalenz.org/2010/09/28/centered-interval-trees/#comments</comments>
		<pubDate>Tue, 28 Sep 2010 13:50:58 +0000</pubDate>
		<dc:creator>bwalenz</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://brettwalenz.org/?p=94</guid>
		<description><![CDATA[An interval tree is a data structure for efficiently searching intervals. Surprise! An interval can be a continuous line segment, a time frame, etc. It is generally augmented with a secondary structure in each interval node to allow for windowing queries. A good example is quickly finding a rectangular region in a GIS application. I [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brettwalenz.org&#038;blog=8459579&#038;post=94&#038;subd=bwalenz&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>An interval tree is a data structure for efficiently searching intervals. Surprise! An interval can be a continuous line segment, a time frame, etc. It is generally augmented with a secondary structure in each interval node to allow for windowing queries. A good example is quickly finding a rectangular region in a GIS application. I couldn&#8217;t find a really straightforward explanation of the algorithm. The <a title="Wikipedia entry" href="http://en.wikipedia.org/wiki/Interval_tree" target="_self">Wikipedia entry</a>, while correct, was not well-explained from an implementation point of view. Most of this information comes from the great book Computational Geometry by Berg et. al.</p>
<p>There are different types of interval trees. The CLRS Introduction to Algorithms book uses a red-black tree as the starting point and outlines construction and querying for intervals. The approach outlined below is a centered interval tree, which uses a binary search tree where each subtree is also a centered interval tree. The value of each subtree is the median (left or right) endpoint of the intervals in the subtree.</p>
<p>An interval, at it&#8217;s barest, has a left and right endpoint. That&#8217;s it. Let&#8217;s look at how we&#8217;d construct an interval tree given a set of intervals. I&#8217;ll use pseudo-Java since I think it&#8217;s the friendliest to read.</p>
<p><pre class="brush: xml;">

CenteredIntervalTree constructIntervalTree(Set&lt;Interval&gt; intervals) {
    if intervals.isEmpty()
       return leaf;
    Compute xMid = Median of interval endpoints
    Compute iMid = the set of all intervals
                   where the left endpoint is &lt;= xMid
                   and the right endpoint is &gt;= xMid
    Compute iMidLeft = a copy of the set iMid sorted by left endpoint
    Compute iMidRight = a copy of the set iMid sorted by right endpoint
    Store xMid, iMidLeft, and iMidRight at the current node.
    Compute iLeft = a set of all intervals where the RIGHT endpoint is &lt; xMid
    Compute iRight = a set of all intervals where the LEFT endpoint is &gt; xMid
    leftSubTree = constructIntervalTree(iLeft)
    rightSubTree = constructIntervalTree(iRight)
    return currentTree;
}

</pre></p>
<p>The construction algorithms creates a roughly-balanced search tree by taking the median of the (right) endpoints and setting that as the root of the current tree. The data stored at each node is the set of intervals that contain that endpoint. To see how this construction algorithm works, assume we have the following set of intervals: {(1, 10), (17, 29), (31, 38), (30, 40), (15, 24)}. The resulting interval tree will appear as in the image below. The running time for the construction algorithm is O(n log n). For the proof, see Lemma 10.3 in Computation Geometry.</p>
<p style="text-align:center;"><a href="http://bwalenz.files.wordpress.com/2010/09/intervaltree.jpg"><img class="size-medium wp-image-107 aligncenter" title="intervalTree" src="http://bwalenz.files.wordpress.com/2010/09/intervaltree.jpg?w=300&h=152" alt="" width="300" height="152" /></a></p>
<p>So how do we query this? The answer should be obvious when looking at the image. The only trick is when you wish to query for all intervals intersecting another interval.</p>
<p>To query for a given point (say, to find all intervals containing the value 35 in the example), the following algorithm can be used:</p>
<p><pre class="brush: xml;">
Set&lt;Interval&gt; queryIntervalTree(tree, value) {
   if (tree does not have children)
      return currentSet;
   if (value &lt; xMid) {
      for (Interval interval : iMidLeft) {
         if (interval.contains(value))
            currentSet.add(interval);
         else
            break; //sorted so that nothing past this will contain value
      }
      currentSet.addAll(queryIntervalTree(tree.leftSubTree, value));
   } else {
       /* Repeat iteration from above but with iMidRight instead of iMidLeft;
      currentSet.addAll(queryIntervalTree(tree.rightSubTree, value));
   }
}

</pre></p>
<p>The query time is a very fast O(log n + k), where k is the number of intervals that are stored at a node. But what if we wanted to search for an interval? This is fairly easy, but can be difficult to express: We want to start at the left endpoint, and grab all intervals until we reach the right endpoint intersection. From an implementation perspective, it can be hard to do this correctly. You can&#8217;t just call queryIntervalTree for the left and right endpoint values, you might miss intervals that are completely enclosed by the passed in interval. So, when implementing, it might be smart to replace some of the recursion with iteration, or at least keep track of the parent nodes for a centered interval tree. This will make walking the tree much easier.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bwalenz.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bwalenz.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bwalenz.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bwalenz.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bwalenz.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bwalenz.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bwalenz.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bwalenz.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bwalenz.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bwalenz.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bwalenz.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bwalenz.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bwalenz.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bwalenz.wordpress.com/94/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brettwalenz.org&#038;blog=8459579&#038;post=94&#038;subd=bwalenz&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://brettwalenz.org/2010/09/28/centered-interval-trees/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0cfb052531593c46dfbabf7a8c77804b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bwalenz</media:title>
		</media:content>

		<media:content url="http://bwalenz.files.wordpress.com/2010/09/intervaltree.jpg?w=300" medium="image">
			<media:title type="html">intervalTree</media:title>
		</media:content>
	</item>
	</channel>
</rss>
