<?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>jagged tooth v2.1</title>
	<atom:link href="http://incisors.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://incisors.wordpress.com</link>
	<description>Blog for AP 186</description>
	<lastBuildDate>Mon, 06 Oct 2008 13:54:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='incisors.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>jagged tooth v2.1</title>
		<link>http://incisors.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://incisors.wordpress.com/osd.xml" title="jagged tooth v2.1" />
	<atom:link rel='hub' href='http://incisors.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Activity 20: Neural Networks</title>
		<link>http://incisors.wordpress.com/2008/10/01/activity-20-neural-networks/</link>
		<comments>http://incisors.wordpress.com/2008/10/01/activity-20-neural-networks/#comments</comments>
		<pubDate>Wed, 01 Oct 2008 02:38:00 +0000</pubDate>
		<dc:creator>jptugaff</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://incisors.wordpress.com/?p=408</guid>
		<description><![CDATA[A neural network is a mathematical model based on the workings of the human brains. It is composed of neurons arranged in layers that is fully connected with the preceding layer. The layers are called the input, hidden and output layers respectively. The input layer is where the input features are fed and forwarded to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=incisors.wordpress.com&amp;blog=3941311&amp;post=408&amp;subd=incisors&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:left;">A neural network is a mathematical model based on the workings of the human brains. It is composed of neurons arranged in layers that is fully connected with the preceding layer. The layers are called the input, hidden and output layers respectively. The input layer is where the input features are fed and forwarded to the hidden layer which is again forwarded to the output layer.</p>
<p style="text-align:center;"><img class="size-medium wp-image-410 aligncenter" title="nn_architecture1" src="http://incisors.files.wordpress.com/2008/10/nn_architecture1.png?w=300&#038;h=160" alt="" width="300" height="160" /></p>
<p style="text-align:left;">After the neurons are placed in the input, they are fed forward to the hidden neurons. The hidden neurons would have value <img class="alignnone size-full wp-image-414" title="y" src="http://incisors.files.wordpress.com/2008/10/y.png?w=495" alt=""   /> where <img class="alignnone size-full wp-image-416" title="wih" src="http://incisors.files.wordpress.com/2008/10/wih.png?w=495" alt=""   /> are the weights (strength of connection) association with the <em>i<sup>th</sup></em> and <em>h<sup>th</sup></em> neuron. <img class="alignnone size-full wp-image-422" title="fh1" src="http://incisors.files.wordpress.com/2008/10/fh1.png?w=495" alt=""   /> is called the activation function because it mimics the the all-or-nothing firing of the neurons. Both hidden and output layers have activation functions given by</p>
<p style="text-align:center;"><img class="aligncenter size-full wp-image-411" title="fh" src="http://incisors.files.wordpress.com/2008/10/fh.png?w=495" alt=""   /></p>
<p style="text-align:center;"><img class="aligncenter size-full wp-image-412" title="fo" src="http://incisors.files.wordpress.com/2008/10/fo.png?w=495" alt=""   /></p>
<p style="text-align:left;">The tansig function is one of the most often used activation functions is pattern recognition problems. The output of the neural network is given by</p>
<p style="text-align:center;"><a href="http://incisors.files.wordpress.com/2008/10/output.png"><img class="alignnone size-full wp-image-413" title="output" src="http://incisors.files.wordpress.com/2008/10/output.png?w=495" alt=""   /></a></p>
<p style="text-align:left;">where <img class="alignnone size-full wp-image-423" title="dh" src="http://incisors.files.wordpress.com/2008/10/dh.png?w=495" alt=""   /> is the weight associated with the hidden and output layers. The goal of NN is to minimize the error function E given by</p>
<p style="text-align:center;"><img class="alignnone size-full wp-image-415" title="error" src="http://incisors.files.wordpress.com/2008/10/error.png?w=495" alt=""   /></p>
<p style="text-align:left;">where <img class="alignnone size-full wp-image-424" title="psi" src="http://incisors.files.wordpress.com/2008/10/psi.png?w=495" alt=""   /> is the actual output of the fed input pattern. This neural network is also called supervised neural network because you have an idea of what the output is. In a way, you can also look at it as forcing the NN to adjust weights such that a given input has the desired output.</p>
<p style="text-align:left;">The weights <img class="alignnone size-full wp-image-416" title="wih" src="http://incisors.files.wordpress.com/2008/10/wih.png?w=495" alt=""   /> are updated as</p>
<p style="text-align:left;"><img class="aligncenter size-full wp-image-417" title="delta_wih" src="http://incisors.files.wordpress.com/2008/10/delta_wih.png?w=495" alt=""   /></p>
<p style="text-align:left;">where <img class="alignnone size-full wp-image-418" title="wihq" src="http://incisors.files.wordpress.com/2008/10/wihq.png?w=495" alt=""   /> is the weight at the <em>qth </em>iteration. A similar process is done for <img class="alignnone size-full wp-image-423" title="dh" src="http://incisors.files.wordpress.com/2008/10/dh.png?w=495" alt=""   />.</p>
<p style="text-align:left;">As a note, a neural network may have more than one output neuron. For a 3-class classification, we can have group A would output 0-0, group B would have 0-1 and group C would have 1-1. It is also important to normalize the inputs to between 0 and 1 because sigmoidal functions plateus at high values. That is, tansigmoidal of 100 is similar to tansigmoidal 200. Finally, the output of NN would not always be 1s or 0s. Thus, some sort of thresholding is done, like if the output is greater then 0.5 it is 1, otherwise 0.</p>
<p style="text-align:left;">For my classification my results are as follows.</p>
<p style="text-align:center;"><img class="size-medium wp-image-419 aligncenter" title="confusion" src="http://incisors.files.wordpress.com/2008/10/confusion.png?w=115&#038;h=75" alt="" width="115" height="75" /></p>
<p style="text-align:left;">This has accuracy of 93.3%. Also, the training set has 100% classification results. My code written in matlab is as follows:</p>
<p style="text-align:left;">net=newff(minmax(training),[25,2],{&#8216;tansig&#8217;,'tansig&#8217;},&#8217;traingd&#8217;);<br />
net.trainParam.show = 50;<br />
net.trainParam.lr = 0.01;<br />
%net.trainParam.lr_inc = 1.05;<br />
net.trainParam.epochs = 1000;<br />
net.trainParam.goal = 1e-2;<br />
[net,tr]=train(net,training,training_out);<br />
a = sim(net,training);<br />
a = 1*(a&gt;=0.5);<br />
b = sim(net,test);<br />
b = 1*(b&gt;=0.5);<br />
diff = abs(training_out &#8211; b);<br />
diff = diff(1,:) + diff(2, <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ;<br />
diff = 1*(diff&gt;=1);</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/incisors.wordpress.com/408/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/incisors.wordpress.com/408/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/incisors.wordpress.com/408/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/incisors.wordpress.com/408/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/incisors.wordpress.com/408/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/incisors.wordpress.com/408/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/incisors.wordpress.com/408/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/incisors.wordpress.com/408/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/incisors.wordpress.com/408/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/incisors.wordpress.com/408/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/incisors.wordpress.com/408/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/incisors.wordpress.com/408/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/incisors.wordpress.com/408/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/incisors.wordpress.com/408/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=incisors.wordpress.com&amp;blog=3941311&amp;post=408&amp;subd=incisors&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://incisors.wordpress.com/2008/10/01/activity-20-neural-networks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7180bfbb1df0d02507e75d02e265e0fa?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">jptugaff</media:title>
		</media:content>

		<media:content url="http://incisors.files.wordpress.com/2008/10/nn_architecture1.png?w=300" medium="image">
			<media:title type="html">nn_architecture1</media:title>
		</media:content>

		<media:content url="http://incisors.files.wordpress.com/2008/10/y.png" medium="image">
			<media:title type="html">y</media:title>
		</media:content>

		<media:content url="http://incisors.files.wordpress.com/2008/10/wih.png" medium="image">
			<media:title type="html">wih</media:title>
		</media:content>

		<media:content url="http://incisors.files.wordpress.com/2008/10/fh1.png" medium="image">
			<media:title type="html">fh1</media:title>
		</media:content>

		<media:content url="http://incisors.files.wordpress.com/2008/10/fh.png" medium="image">
			<media:title type="html">fh</media:title>
		</media:content>

		<media:content url="http://incisors.files.wordpress.com/2008/10/fo.png" medium="image">
			<media:title type="html">fo</media:title>
		</media:content>

		<media:content url="http://incisors.files.wordpress.com/2008/10/output.png" medium="image">
			<media:title type="html">output</media:title>
		</media:content>

		<media:content url="http://incisors.files.wordpress.com/2008/10/dh.png" medium="image">
			<media:title type="html">dh</media:title>
		</media:content>

		<media:content url="http://incisors.files.wordpress.com/2008/10/error.png" medium="image">
			<media:title type="html">error</media:title>
		</media:content>

		<media:content url="http://incisors.files.wordpress.com/2008/10/psi.png" medium="image">
			<media:title type="html">psi</media:title>
		</media:content>

		<media:content url="http://incisors.files.wordpress.com/2008/10/wih.png" medium="image">
			<media:title type="html">wih</media:title>
		</media:content>

		<media:content url="http://incisors.files.wordpress.com/2008/10/delta_wih.png" medium="image">
			<media:title type="html">delta_wih</media:title>
		</media:content>

		<media:content url="http://incisors.files.wordpress.com/2008/10/wihq.png" medium="image">
			<media:title type="html">wihq</media:title>
		</media:content>

		<media:content url="http://incisors.files.wordpress.com/2008/10/dh.png" medium="image">
			<media:title type="html">dh</media:title>
		</media:content>

		<media:content url="http://incisors.files.wordpress.com/2008/10/confusion.png?w=300" medium="image">
			<media:title type="html">confusion</media:title>
		</media:content>
	</item>
		<item>
		<title>Activity 19: Linear Discriminant Analysis</title>
		<link>http://incisors.wordpress.com/2008/10/01/activity-19-linear-discriminant-analysis/</link>
		<comments>http://incisors.wordpress.com/2008/10/01/activity-19-linear-discriminant-analysis/#comments</comments>
		<pubDate>Wed, 01 Oct 2008 02:15:53 +0000</pubDate>
		<dc:creator>jptugaff</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://incisors.wordpress.com/?p=406</guid>
		<description><![CDATA[Linear discriminant analysis is one of the simplest classification techniques to implement because it enables us to create a discriminant function from predictor variables. In this activity, i tried classifying between nova and piatos. The features i used where their RGB values and size. The f values are given as follows f1        f2 1 636.89 [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=incisors.wordpress.com&amp;blog=3941311&amp;post=406&amp;subd=incisors&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Linear discriminant analysis is one of the simplest classification techniques to implement because it enables us to create a discriminant function from predictor variables. In this activity, i tried classifying between nova and piatos. The features i used where their RGB values and size.</p>
<p><a href="http://incisors.files.wordpress.com/2008/10/n3.jpg"><img class="alignnone size-full wp-image-429" title="n3" src="http://incisors.files.wordpress.com/2008/10/n3.jpg?w=495" alt=""   /></a><a href="http://incisors.files.wordpress.com/2008/10/p5.jpg"><img class="alignnone size-full wp-image-430" title="p5" src="http://incisors.files.wordpress.com/2008/10/p5.jpg?w=495" alt=""   /></a></p>
<p>The f values are given as follows</p>
<p>f1        f2<br />
1<strong> 636.89</strong> 593.53<br />
1<strong> </strong><strong>588.54</strong> 551.74<br />
1<strong> </strong> <strong>587.14</strong> 561.56<br />
1<strong> </strong> <strong>553.42</strong> 515.54<br />
2 340.98	<strong>392.78</strong><br />
2  409.91	<strong>434.11</strong><br />
2  438.59	<strong>474.51</strong><br />
2  431.21	<strong>462.89</strong></p>
<p>An object is assigned a class with the highest f value. As can be seen, most of group 1 have high f1 values while those in group 2 have higher f2 values.</p>
<p>As can be seen in our confusion matrix, we have 100% classification</p>
<p style="text-align:center;"><a href="http://incisors.files.wordpress.com/2008/10/screenshot-1.png"><img class="size-full wp-image-428 aligncenter" title="screenshot-1" src="http://incisors.files.wordpress.com/2008/10/screenshot-1.png?w=495" alt=""   /></a></p>
<p style="text-align:left;">Here is my code:</p>
<p style="text-align:left;">clear all;<br />
chdir(&#8216;/home/jeric/Documents/Acads/ap186/AC18&#8242;);<br />
exec(&#8216;/home/jeric/scilab-5.0.1/include/scilab/ANN_Toolbox_0.4.2.2/loader.sce&#8217;);<br />
exec(&#8216;/home/jeric/scilab-5.0.1/include/scilab/sip-0.4.0-bin/loader.sce&#8217;);<br />
stacksize(4e7);<br />
getf(&#8216;imhist.sce&#8217;);<br />
getf(&#8216;segment.sce&#8217;);<br />
training=[];<br />
test=[];<br />
prop=[];<br />
loc=&#8217;im2/&#8217;;<br />
f=listfiles(loc);<br />
f=sort(f);<br />
[x1, y1]=size(f);<br />
for i=1:x1;<br />
im=imread(strcat([loc, f(i)]));<br />
im2=im2gray(im) ;<br />
if max(im2)&lt;=1<br />
im2=round(im2*255);<br />
end<br />
[val, num]=imhist(im2);<br />
im2=im2bw(im2, 210/255);<br />
im2=1-im2;<br />
ta=sum(im2); // theoretical area<br />
[x,y]=find(im2==1);<br />
temp=im(:,:,1);<br />
red=mean(temp(x));<br />
temp=im(:,:,2);<br />
green=mean(temp(x));<br />
temp=im(:,:,3);<br />
blue=mean(temp(x));<br />
prop(i,:)=[red, green, blue, ta];<br />
end<br />
max_a=max(prop(:,4));<br />
max_r=max(prop(:,1));<br />
max_g=max(prop(:,2));<br />
max_b=max(prop(:,3));<br />
prop(:,4) = prop(:,4)/max_a;<br />
prop(:,1) = prop(:,1)/max_r;<br />
prop(:,2) = prop(:,2)/max_g;<br />
prop(:,3) = prop(:,3)/max_b;<br />
training =  prop(1:2:x1,:);<br />
test = prop(2:2:x1, <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ;<br />
m1 = mean(training(1:4,:),1);<br />
m2 = mean(training(5:8,:),1);<br />
training1 = training(1:4, <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ;<br />
training2 = training(5:8,:);<br />
training1 = training1 &#8211; mtlb_repmat(m1, 4,1);</p>
<p style="text-align:left;">training2 = training2 &#8211; mtlb_repmat(m2, 4,1);</p>
<p>//LDA</p>
<p>n1 = 4;<br />
n2 = 4<br />
c1 = (training1)&#8217; * training1 / n1;<br />
c2 = (training2)&#8217; * training2 / n2;<br />
c = 1./8*(4*c1+4*c2);<br />
p = [1./2; 1./2];<br />
for i = 1:8<br />
f1(i) = m1*inv(c)*training(i,:)&#8217; &#8211; 0.5*m1*inv(c)*m1&#8242;+log(p(1));<br />
f2(i) = m2*inv(c)*training(i,:)&#8217; &#8211; 0.5*m2*inv(c)*m2&#8242;+log(p(2));<br />
if f1(i)&gt;f2(i) then<br />
class(i)=1;<br />
else class(i)=2;<br />
end<br />
end<br />
class</p>
<p>you may look take a look at <a href="http://people.revoledu.com/kardi/tutorial/LDA/LDA.html">http://people.revoledu.com/kardi/tutorial/LDA/LDA.html</a> for a more thorough discussion of LDA.</p>
<p style="text-align:left;">
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/incisors.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/incisors.wordpress.com/406/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/incisors.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/incisors.wordpress.com/406/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/incisors.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/incisors.wordpress.com/406/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/incisors.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/incisors.wordpress.com/406/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/incisors.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/incisors.wordpress.com/406/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/incisors.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/incisors.wordpress.com/406/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/incisors.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/incisors.wordpress.com/406/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=incisors.wordpress.com&amp;blog=3941311&amp;post=406&amp;subd=incisors&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://incisors.wordpress.com/2008/10/01/activity-19-linear-discriminant-analysis/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7180bfbb1df0d02507e75d02e265e0fa?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">jptugaff</media:title>
		</media:content>

		<media:content url="http://incisors.files.wordpress.com/2008/10/n3.jpg" medium="image">
			<media:title type="html">n3</media:title>
		</media:content>

		<media:content url="http://incisors.files.wordpress.com/2008/10/p5.jpg" medium="image">
			<media:title type="html">p5</media:title>
		</media:content>

		<media:content url="http://incisors.files.wordpress.com/2008/10/screenshot-1.png" medium="image">
			<media:title type="html">screenshot-1</media:title>
		</media:content>
	</item>
		<item>
		<title>Activity 18: Minimum Distance Classification</title>
		<link>http://incisors.wordpress.com/2008/09/17/activity-18-minimum-distance-classification/</link>
		<comments>http://incisors.wordpress.com/2008/09/17/activity-18-minimum-distance-classification/#comments</comments>
		<pubDate>Wed, 17 Sep 2008 13:05:48 +0000</pubDate>
		<dc:creator>jptugaff</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://incisors.wordpress.com/?p=394</guid>
		<description><![CDATA[Pattern recognition techniques has long been studied by scientists for their potential applications.  Human face recognition, coral reef analysis and gait analysis have been successful implentations of pattern recognition techniques. One of the most basic forms of pattern recognition techniques is through attibutes of a given sample and compare it with the attributes of a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=incisors.wordpress.com&amp;blog=3941311&amp;post=394&amp;subd=incisors&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Pattern recognition techniques has long been studied by scientists for their potential applications.  Human face recognition, coral reef analysis and gait analysis have been successful implentations of pattern recognition techniques.</p>
<p>One of the most basic forms of pattern recognition techniques is through attibutes of a given sample and compare it with the attributes of a training set. In this activity, we use different samples of chips, namely Chippy, Nova and Piatos and attempted to distinguish chips from each other through the attributes obtained form the training set.</p>
<p style="text-align:center;"><a href="http://incisors.files.wordpress.com/2008/09/chips.jpg"><img class="size-full wp-image-402 aligncenter" title="chips" src="http://incisors.files.wordpress.com/2008/09/chips.jpg?w=495&#038;h=371" alt="" width="495" height="371" /></a></p>
<p>Ten samples of each kind of chip was photographed with a camera. After which, cut each images to ascertain that a single image contains a single chip. Image processing techniques such segmentation was performed to remove the chip from the background. Afterwich the average value of the R, G and B of each chip was obtained as well as the area. The chip is then represented by the vector <strong>x </strong>containing the features of the chip. We do this for all chips in our training set. If we have <strong>W </strong>types of chips (chippy, nova, and piatos), we obtain the average feature vector of each class given by</p>
<p><img class="aligncenter size-full wp-image-395" title="mn" src="http://incisors.files.wordpress.com/2008/09/mn.png?w=495" alt=""   /></p>
<p>for all j=1,2,..W.</p>
<p>The features of each test chip are obtained and the distance from each class is computed using</p>
<p><img class="aligncenter size-full wp-image-397" title="d" src="http://incisors.files.wordpress.com/2008/09/d.png?w=495" alt=""   /></p>
<p>where</p>
<p><img class="aligncenter size-full wp-image-396" title="euc" src="http://incisors.files.wordpress.com/2008/09/euc.png?w=495" alt=""   /></p>
<p>The test chip is classified based on the class with the minimum distance. Take note also that I normalized each vector to eliminate bias towards features whose values are extremely large (area for example) and eliminate bias against small numbers (R value for example).</p>
<p>Here is the confusion matrix of the test set of my 3-class classification. This is good enough with accuracy of 87%.</p>
<p><img class="aligncenter size-full wp-image-398" title="conmat" src="http://incisors.files.wordpress.com/2008/09/conmat.png?w=495" alt=""   /></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/incisors.wordpress.com/394/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/incisors.wordpress.com/394/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/incisors.wordpress.com/394/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/incisors.wordpress.com/394/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/incisors.wordpress.com/394/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/incisors.wordpress.com/394/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/incisors.wordpress.com/394/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/incisors.wordpress.com/394/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/incisors.wordpress.com/394/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/incisors.wordpress.com/394/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/incisors.wordpress.com/394/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/incisors.wordpress.com/394/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/incisors.wordpress.com/394/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/incisors.wordpress.com/394/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/incisors.wordpress.com/394/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/incisors.wordpress.com/394/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=incisors.wordpress.com&amp;blog=3941311&amp;post=394&amp;subd=incisors&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://incisors.wordpress.com/2008/09/17/activity-18-minimum-distance-classification/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7180bfbb1df0d02507e75d02e265e0fa?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">jptugaff</media:title>
		</media:content>

		<media:content url="http://incisors.files.wordpress.com/2008/09/chips.jpg" medium="image">
			<media:title type="html">chips</media:title>
		</media:content>

		<media:content url="http://incisors.files.wordpress.com/2008/09/mn.png" medium="image">
			<media:title type="html">mn</media:title>
		</media:content>

		<media:content url="http://incisors.files.wordpress.com/2008/09/d.png" medium="image">
			<media:title type="html">d</media:title>
		</media:content>

		<media:content url="http://incisors.files.wordpress.com/2008/09/euc.png" medium="image">
			<media:title type="html">euc</media:title>
		</media:content>

		<media:content url="http://incisors.files.wordpress.com/2008/09/conmat.png" medium="image">
			<media:title type="html">conmat</media:title>
		</media:content>
	</item>
		<item>
		<title>Activity 17: Basic Video Processing</title>
		<link>http://incisors.wordpress.com/2008/09/04/activity-17-basic-image-processing/</link>
		<comments>http://incisors.wordpress.com/2008/09/04/activity-17-basic-image-processing/#comments</comments>
		<pubDate>Thu, 04 Sep 2008 02:49:03 +0000</pubDate>
		<dc:creator>jptugaff</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://incisors.wordpress.com/?p=334</guid>
		<description><![CDATA[Videos are becoming common with the advent of the digital era. Almost anyone can create their own videos. We can take advantage of this technology in exploring physics by performing experiments and monitor certain variables as a function of time. A video is simply a string of still images flashed one after the other. The [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=incisors.wordpress.com&amp;blog=3941311&amp;post=334&amp;subd=incisors&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Videos are becoming common with the advent of the digital era. Almost anyone can create their own videos. We can take advantage of this technology in exploring physics by performing experiments and monitor certain variables as a function of time.</p>
<p>A video is simply a string of still images flashed one after the other. The rate at which the video is captured is called the frame rate (measured in frames per second, fps). The higher the frame rate, the higher quality of the image in terms of smoothness of motion and time resolution. In our case, we used Cole&#8217;s web camera that can capture videos to see the dynamics of a physical pendulum (as opposed to a simple pendulem). His camera has frame rate of 15fps and, by Nyquist criterion, we can only resolve harmonic motion with frequency of less than 8Hz.</p>
<p>In this activity our group (me, cole and mark) decided that we want to invsitigate the period of a physical pendulum and compare it with theoretical predictions. For the first part, we captured video from the web cam and converted the frames to image files in *.jpg format (using avidemux) with the same fps but with reduced images size to 120 by 180 (from the original 480 by 720). The images were then subject to white balancing, chromaticity normalization, image segmentation (using color), binarization (using grayscale histogram), and opening and closing transformation. Basically we applied here everything we did for the entire sem. <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . Assumptions regarding the ruler include homogeneity in the density of the ruler, the pivot is at excatly at the edge, and that the center of mass located exactly in the middle of the ruler.</p>
<p style="text-align:center;"><img class="size-full wp-image-390 aligncenter" title="animation2" src="http://incisors.files.wordpress.com/2008/09/animation2.gif?w=495" alt=""   /></p>
<p>Here is the gif animation i made (i converted the images to gif animation to avoid problems with the UP blocking access to video sharing sites such as youtube). The left is the orginal set of images, the middle are the normalized ones and the last are the binarized images. The gif is quite large (1.6mb) but once it gets loaded, it keeps on rolling. <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  I also ensured the the speed of the gif is similar to the fps of the camera used.</p>
<p>A physical pendulum is a more generalized pendulum with no ideal strings. The period of oscillation of this pendulum is given by</p>
<p><img class="aligncenter size-full wp-image-366" title="t" src="http://incisors.files.wordpress.com/2008/09/t.png?w=495" alt=""   /></p>
<p>where <em>I</em> is the moment of inertia about the pivot and <em>L</em> is the distance of the center of mass from the pivot. <img class="aligncenter size-full wp-image-377" title="moi" src="http://incisors.files.wordpress.com/2008/09/moi.png?w=495" alt=""   /></p>
<p>For our ruler with length <em>h </em>and width <em>w</em> with pivot around the end the moment of inertia is given by</p>
<p style="text-align:center;"><img class="size-full wp-image-365 aligncenter" title="i1" src="http://incisors.files.wordpress.com/2008/09/i1.png?w=495" alt=""   /></p>
<p style="text-align:center;">
<p>The period of oscillation can be obtained from the graph by plotting the location of the center of mass as a function of time and getting the distance between two peaks.If this is what we use, we get a period of 1.2 sec</p>
<p style="text-align:center;"><img class="size-large wp-image-360 aligncenter" title="pendulum-plot1" src="http://incisors.files.wordpress.com/2008/09/pendulum-plot1.png?w=495&#038;h=329" alt="" width="495" height="329" /></p>
<p style="text-align:left;">I also used fft to get the dominating frequency of our signal above, and found it to 0.769 Hz or a period of around 1.3 sec which is not far from the above. I also believe that the frequency obtained by fft is more accurate than just picking peaks. <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p style="text-align:center;"><img class="alignnone size-medium wp-image-382" title="ft1" src="http://incisors.files.wordpress.com/2008/09/ft1.png?w=300&#038;h=199" alt="" width="300" height="199" /></p>
<p style="text-align:left;">Theoretically, this ruler with mass 174.8g, length of 63.5cm and width of 3cm would have a period of oscillation of 1.31s (the moment of inertia being 0.0235). This means we have error of only 0.76%. This is very near the expected value , considering that the we had a few assumptions regarding this ruler.</p>
<p style="text-align:center;">-oOo-</p>
<p><img class="alignnone size-full wp-image-379" title="a17-1" src="http://incisors.files.wordpress.com/2008/09/a17-1.png?w=495&#038;h=720" alt="" width="495" height="720" /></p>
<p><img class="alignnone size-full wp-image-380" title="a17-2" src="http://incisors.files.wordpress.com/2008/09/a17-2.png?w=495&#038;h=146" alt="" width="495" height="146" /></p>
<p style="text-align:center;">-oOo-</p>
<p style="text-align:left;">Here are the functions i made that were invoked above.</p>
<p style="text-align:left;">closing.sce</p>
<p><img class="alignnone size-full wp-image-345" title="closing" src="http://incisors.files.wordpress.com/2008/09/closing.png?w=495&#038;h=78" alt="" width="495" height="78" /></p>
<p>open.sce</p>
<p><img class="alignnone size-full wp-image-346" title="open" src="http://incisors.files.wordpress.com/2008/09/open.png?w=495&#038;h=75" alt="" width="495" height="75" /></p>
<p>imhist.sce</p>
<p><img class="alignnone size-full wp-image-347" title="imhist" src="http://incisors.files.wordpress.com/2008/09/imhist.png?w=495&#038;h=159" alt="" width="495" height="159" /></p>
<p>segment.sce</p>
<p><img class="alignnone size-large wp-image-387" title="segment1" src="http://incisors.files.wordpress.com/2008/09/segment1.png?w=495&#038;h=463" alt="" width="495" height="463" /></p>
<p>white_balance.sce</p>
<p><img class="alignnone size-full wp-image-349" title="whitebalance" src="http://incisors.files.wordpress.com/2008/09/whitebalance.png?w=495&#038;h=176" alt="" width="495" height="176" /></p>
<p style="text-align:center;">-oOo-</p>
<p>Collaborators: Mark, Cole</p>
<p>I want to give myself a 10 here because i believe I was able to complete what has to be done by applying almost everything we had learned.:)</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/incisors.wordpress.com/334/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/incisors.wordpress.com/334/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/incisors.wordpress.com/334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/incisors.wordpress.com/334/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/incisors.wordpress.com/334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/incisors.wordpress.com/334/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/incisors.wordpress.com/334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/incisors.wordpress.com/334/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/incisors.wordpress.com/334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/incisors.wordpress.com/334/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/incisors.wordpress.com/334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/incisors.wordpress.com/334/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/incisors.wordpress.com/334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/incisors.wordpress.com/334/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/incisors.wordpress.com/334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/incisors.wordpress.com/334/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=incisors.wordpress.com&amp;blog=3941311&amp;post=334&amp;subd=incisors&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://incisors.wordpress.com/2008/09/04/activity-17-basic-image-processing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7180bfbb1df0d02507e75d02e265e0fa?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">jptugaff</media:title>
		</media:content>

		<media:content url="http://incisors.files.wordpress.com/2008/09/animation2.gif" medium="image">
			<media:title type="html">animation2</media:title>
		</media:content>

		<media:content url="http://incisors.files.wordpress.com/2008/09/t.png" medium="image">
			<media:title type="html">t</media:title>
		</media:content>

		<media:content url="http://incisors.files.wordpress.com/2008/09/moi.png" medium="image">
			<media:title type="html">moi</media:title>
		</media:content>

		<media:content url="http://incisors.files.wordpress.com/2008/09/i1.png" medium="image">
			<media:title type="html">i1</media:title>
		</media:content>

		<media:content url="http://incisors.files.wordpress.com/2008/09/pendulum-plot1.png?w=495" medium="image">
			<media:title type="html">pendulum-plot1</media:title>
		</media:content>

		<media:content url="http://incisors.files.wordpress.com/2008/09/ft1.png?w=300" medium="image">
			<media:title type="html">ft1</media:title>
		</media:content>

		<media:content url="http://incisors.files.wordpress.com/2008/09/a17-1.png" medium="image">
			<media:title type="html">a17-1</media:title>
		</media:content>

		<media:content url="http://incisors.files.wordpress.com/2008/09/a17-2.png" medium="image">
			<media:title type="html">a17-2</media:title>
		</media:content>

		<media:content url="http://incisors.files.wordpress.com/2008/09/closing.png" medium="image">
			<media:title type="html">closing</media:title>
		</media:content>

		<media:content url="http://incisors.files.wordpress.com/2008/09/open.png" medium="image">
			<media:title type="html">open</media:title>
		</media:content>

		<media:content url="http://incisors.files.wordpress.com/2008/09/imhist.png" medium="image">
			<media:title type="html">imhist</media:title>
		</media:content>

		<media:content url="http://incisors.files.wordpress.com/2008/09/segment1.png?w=495" medium="image">
			<media:title type="html">segment1</media:title>
		</media:content>

		<media:content url="http://incisors.files.wordpress.com/2008/09/whitebalance.png" medium="image">
			<media:title type="html">whitebalance</media:title>
		</media:content>
	</item>
		<item>
		<title>Activity 16: Image Segmentation</title>
		<link>http://incisors.wordpress.com/2008/09/02/activity-16-image-segmentation/</link>
		<comments>http://incisors.wordpress.com/2008/09/02/activity-16-image-segmentation/#comments</comments>
		<pubDate>Tue, 02 Sep 2008 03:12:15 +0000</pubDate>
		<dc:creator>jptugaff</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://incisors.wordpress.com/?p=294</guid>
		<description><![CDATA[Segmentation (choosing of objects in colored images) is useful in many aspects of digital image processing like face detection. More often than not, an object would have one color, for example, a mug or a ball, or hand. However, lighting variations may affect the luminosity of our images and as such, we must remove these [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=incisors.wordpress.com&amp;blog=3941311&amp;post=294&amp;subd=incisors&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:center;"><img class="alignnone size-full wp-image-306" src="http://incisors.files.wordpress.com/2008/09/normalized_chromaticity.png?w=495" alt=""   /></p>
<p style="text-align:left;">Segmentation (choosing of objects in colored images) is useful in many aspects of digital image processing like face detection. More often than not, an object would have one color, for example, a mug or a ball, or hand. However, lighting variations may affect the luminosity of our images and as such, we must remove these luminosity attributes in processing our images. To remove luminosity effects we normalized each channel to</p>
<p style="text-align:center;"><img class="size-full wp-image-313 aligncenter" src="http://incisors.files.wordpress.com/2008/09/normalized.png?w=495" alt=""   /></p>
<p style="text-align:left;">where <img class="alignnone size-full wp-image-314" src="http://incisors.files.wordpress.com/2008/09/i.png?w=495" alt=""   />. We then crop a portion of the object (regions of interest, ROI) that we will segment and use this as a &#8220;model&#8221; from which certain parameters will be obtained. If our object is more or less monochromatic, it will more or less cover a small blob in our chromaticity diagram (figure above). We then. Here, we have a picture of Catherin Zeta-Jones taken from: <a href="http://www.latest-hairstyles.com/">http://www.latest-hairstyles.com/</a></p>
<p style="text-align:center;"><a href="http://www.latest-hairstyles.com/long/images/round-face-jones.jpg"><img class="size-full wp-image-296 aligncenter" src="http://incisors.files.wordpress.com/2008/09/face.jpg?w=495" alt=""   /></a></p>
<p style="text-align:left;">Our &#8220;model&#8221; is a patch form here neck down to her bust to gather as much colors as possible.</p>
<p style="text-align:left;"><img class="size-full wp-image-297 aligncenter" src="http://incisors.files.wordpress.com/2008/09/face_cropped.jpg?w=495" alt=""   /></p>
<p style="text-align:left;"><strong>Parametric Probability Distribution</strong></p>
<p style="text-align:left;">We assume that the distribution of colors in our ROI are normally distributed where the mean and the variance we obtain from our &#8220;model&#8221; cropped images. The probability that the red channel of a pixel is belonging to the red component of the &#8220;model&#8221; is given by</p>
<p style="text-align:center;"><img class="size-full wp-image-308 aligncenter" src="http://incisors.files.wordpress.com/2008/09/gaussian-red.png?w=495" alt=""   /></p>
<p style="text-align:center;"><img class="alignnone size-full wp-image-309" src="http://incisors.files.wordpress.com/2008/09/gaussian-green.png?w=495" alt=""   /></p>
<p style="text-align:left;">where <img class="alignnone size-full wp-image-310" src="http://incisors.files.wordpress.com/2008/09/mu.png?w=495" alt=""   /> and <img class="alignnone size-full wp-image-311" src="http://incisors.files.wordpress.com/2008/09/sigma.png?w=495" alt=""   /> are the mean and standard deviation respectively. The probability that a pixel belongs to the &#8220;model&#8221; is a joint probability given by</p>
<p style="text-align:left;"><img class="aligncenter size-full wp-image-312" src="http://incisors.files.wordpress.com/2008/09/p.png?w=495" alt=""   /></p>
<p style="text-align:left;">We perform this over all pixels and plot the probability that a pixel belongs to our ROI.</p>
<p style="text-align:left;">
<p>Here is our distrution but is not yet normalized.</p>
<p style="text-align:center;"><img class="alignnone size-medium wp-image-298" src="http://incisors.files.wordpress.com/2008/09/face_pdf.gif?w=300&#038;h=226" alt="" width="300" height="226" /></p>
<p>We obtained the joint probability distribution and used &#8220;imshow&#8221; to plot the probability that a pixel belongs to our ROI. As we can see, most of her torso, face and neck is colored almost white, which means there is high probability that hey belong to our ROI. And advantage of this method is it is more robust when it comes to color of the ROI not belonging to the &#8220;model&#8221;.</p>
<p style="text-align:center;"><img class="alignnone size-full wp-image-304" src="http://incisors.files.wordpress.com/2008/09/face_parametric.gif?w=495" alt=""   /></p>
<p style="text-align:left;"><strong>Non-parametric Probability Distribution (Histogram Backprojection)</strong></p>
<p style="text-align:left;">The next method is through histogram backprojection. In this method, we used a normalized chromaticity distribution histogram (obtained from the &#8220;model&#8221;) with 32 bins along the red and green. The histogram of the model is shown below.</p>
<p style="text-align:left;">This method works by getting the r and g values of a pixel and locates the probabilty that it belongs to the &#8220;model&#8221;. It replaces the pixel value with the probility of the pixel r-g values. The reconstruction is shown below.</p>
<p style="text-align:center;"><img class="alignnone size-medium wp-image-303" src="http://incisors.files.wordpress.com/2008/09/2d-hist.jpg?w=300&#038;h=199" alt="" width="300" height="199" /></p>
<p style="text-align:center;"><img class="alignnone size-full wp-image-302" src="http://incisors.files.wordpress.com/2008/09/face-hist-back.gif?w=495" alt=""   /></p>
<p style="text-align:left;">As can be seen, this has better segmentation of the face, torso and arms. Another advantage of this method is it doesn&#8217;t assume normality of distribution unlike parametric one.</p>
<p>&lt;!&#8211;</p>
<p style="text-align:left;"><strong>Extra Extra!</strong></p>
<p style="text-align:left;">Furthermore, I applied what we have learned in Activity 3 and Activity 9 in this activity. I threshold the image to get a black and white image, resulting to this:</p>
<p style="text-align:center;"><img class="size-full wp-image-320 aligncenter" src="http://incisors.files.wordpress.com/2008/09/binary.gif?w=495" alt=""   /></p>
<p style="text-align:left;">Looking closely, there are speckles in the hair, so i improved it by opening transformation and obtained this image</p>
<p style="text-align:center;"><img class="size-full wp-image-321 aligncenter" src="http://incisors.files.wordpress.com/2008/09/opened.gif?w=495" alt=""   /></p>
<p style="text-align:center;">
<p>&#8211;&gt;</p>
<p style="text-align:center;">-oOo-</p>
<p>clear all;<br />
st<span style="font-weight:bold;font-style:italic;color:#0000ff;">clear</span><span style="color:#000000;"> all;</span><br />
<span style="font-weight:bold;font-style:italic;color:#0000ff;">stacksize</span><span style="color:#000000;">(4e7);</span><br />
<span style="font-weight:bold;font-style:italic;color:#0000ff;">chdir</span><span style="color:#000000;">(&#8216;/home/jeric/Documents/Acads/ap186/a16&#8242;);</span><br />
<span style="color:#000000;">ROI=imread(&#8216;face.jpg&#8217;);</span><br />
<span style="color:#000000;">I=ROI(:,:,</span><span style="color:#0000ff;">1</span><span style="color:#000000;">)+ROI(:,:,</span><span style="color:#0000ff;">2</span><span style="color:#000000;">)+ROI(:,:,</span><span style="color:#0000ff;">3</span><span style="color:#000000;">);</span><br />
<span style="color:#000000;">I(</span><span style="font-weight:bold;font-style:italic;color:#0000ff;">find</span><span style="color:#000000;">(I==</span><span style="color:#0000ff;">0</span><span style="color:#000000;">))=</span><span style="color:#0000ff;">100</span><span style="color:#000000;">;</span><br />
<span style="color:#000000;">ROI(:,:,</span><span style="color:#0000ff;">1</span><span style="color:#000000;">)=ROI(:,:,</span><span style="color:#0000ff;">1</span><span style="color:#000000;">)./I;</span><br />
<span style="color:#000000;">ROI(:,:,</span><span style="color:#0000ff;">2</span><span style="color:#000000;">)=ROI(:,:,</span><span style="color:#0000ff;">2</span><span style="color:#000000;">)./I;</span><br />
<span style="color:#000000;">ROI(:,:,</span><span style="color:#0000ff;">3</span><span style="color:#000000;">)=ROI(:,:,</span><span style="color:#0000ff;">3</span><span style="color:#000000;">)./I;</span></p>
<p><span style="color:#000000;">ROI_sub=imread(&#8216;face_cropped.jpg&#8217;);</span><br />
<span style="color:#000000;">I=ROI_sub(:,:,</span><span style="color:#0000ff;">1</span><span style="color:#000000;">)+ROI_sub(:,:,</span><span style="color:#0000ff;">2</span><span style="color:#000000;">)+ROI_sub(:,:,</span><span style="color:#0000ff;">3</span><span style="color:#000000;">);</span><br />
<span style="color:#000000;">ROI_sub(:,:,</span><span style="color:#0000ff;">1</span><span style="color:#000000;">)=ROI_sub(:,:,</span><span style="color:#0000ff;">1</span><span style="color:#000000;">)./I;</span><br />
<span style="color:#000000;">ROI_sub(:,:,</span><span style="color:#0000ff;">2</span><span style="color:#000000;">)=ROI_sub(:,:,</span><span style="color:#0000ff;">2</span><span style="color:#000000;">)./I;</span><br />
<span style="color:#000000;">ROI_sub(:,:,</span><span style="color:#0000ff;">3</span><span style="color:#000000;">)=ROI_sub(:,:,</span><span style="color:#0000ff;">3</span><span style="color:#000000;">)./I;</span></p>
<p><span style="font-style:italic;color:#808080;">//probability estimatation</span><br />
<span style="color:#000000;">mu_r=</span><span style="font-weight:bold;font-style:italic;color:#0000ff;">mean</span><span style="color:#000000;">(ROI_sub(:,:,</span><span style="color:#0000ff;">1</span><span style="color:#000000;">)); st_r=stdev(ROI_sub(:,:,</span><span style="color:#0000ff;">1</span><span style="color:#000000;">));</span><br />
<span style="color:#000000;">mu_g=</span><span style="font-weight:bold;font-style:italic;color:#0000ff;">mean</span><span style="color:#000000;">(ROI_sub(:,:,</span><span style="color:#0000ff;">2</span><span style="color:#000000;">)); st_g=stdev(ROI_sub(:,:,</span><span style="color:#0000ff;">2</span><span style="color:#000000;">));</span></p>
<p><span style="color:#000000;">Pr=1.0*</span><span style="font-weight:bold;font-style:italic;color:#0000ff;">exp</span><span style="color:#000000;">(-((ROI(:,:,</span><span style="color:#0000ff;">1</span><span style="color:#000000;">)-mu_r).^</span><span style="color:#0000ff;">2</span><span style="color:#000000;">)/(</span><span style="color:#0000ff;">2</span><span style="color:#000000;">*st_r^</span><span style="color:#0000ff;">2</span><span style="color:#000000;">))/(st_r*</span><span style="font-weight:bold;font-style:italic;color:#0000ff;">sqrt</span><span style="color:#000000;">(</span><span style="color:#0000ff;">2</span><span style="color:#000000;">*</span><span style="font-weight:bold;color:#008080;">%pi</span><span style="color:#000000;">));</span><br />
<span style="color:#000000;">Pg=1.0*</span><span style="font-weight:bold;font-style:italic;color:#0000ff;">exp</span><span style="color:#000000;">(-((ROI(:,:,</span><span style="color:#0000ff;">2</span><span style="color:#000000;">)-mu_g).^</span><span style="color:#0000ff;">2</span><span style="color:#000000;">)/(</span><span style="color:#0000ff;">2</span><span style="color:#000000;">*st_g^</span><span style="color:#0000ff;">2</span><span style="color:#000000;">))/(st_r*</span><span style="font-weight:bold;font-style:italic;color:#0000ff;">sqrt</span><span style="color:#000000;">(</span><span style="color:#0000ff;">2</span><span style="color:#000000;">*</span><span style="font-weight:bold;color:#008080;">%pi</span><span style="color:#000000;">));</span><br />
<span style="color:#000000;">P=Pr.*Pg;</span><br />
<span style="color:#000000;">P=P/</span><span style="font-weight:bold;font-style:italic;color:#0000ff;">max</span><span style="color:#000000;">(P);</span><br />
<span style="color:#000000;">scf(</span><span style="color:#0000ff;">1</span><span style="color:#000000;">);</span><br />
<span style="color:#000000;">x=[-</span><span style="color:#0000ff;">1</span><span style="color:#000000;">:0.01:</span><span style="color:#0000ff;">1</span><span style="color:#000000;">];</span><br />
<span style="color:#000000;">Pr=1.0*</span><span style="font-weight:bold;font-style:italic;color:#0000ff;">exp</span><span style="color:#000000;">(-((x-mu_r).^</span><span style="color:#0000ff;">2</span><span style="color:#000000;">)/(</span><span style="color:#0000ff;">2</span><span style="color:#000000;">*st_r))/(st_r*</span><span style="font-weight:bold;font-style:italic;color:#0000ff;">sqrt</span><span style="color:#000000;">(</span><span style="color:#0000ff;">2</span><span style="color:#000000;">*</span><span style="font-weight:bold;color:#008080;">%pi</span><span style="color:#000000;">));</span><br />
<span style="color:#000000;">Pg=1.0*</span><span style="font-weight:bold;font-style:italic;color:#0000ff;">exp</span><span style="color:#000000;">(-((x-mu_g).^</span><span style="color:#0000ff;">2</span><span style="color:#000000;">)/(</span><span style="color:#0000ff;">2</span><span style="color:#000000;">*st_g))/(st_g*</span><span style="font-weight:bold;font-style:italic;color:#0000ff;">sqrt</span><span style="color:#000000;">(</span><span style="color:#0000ff;">2</span><span style="color:#000000;">*</span><span style="font-weight:bold;color:#008080;">%pi</span><span style="color:#000000;">));</span><br />
<span style="font-weight:bold;font-style:italic;color:#0000ff;">plot</span><span style="color:#000000;">(x,Pr, &#8216;r-&#8217;, x, Pg, &#8216;g-&#8217;);</span></p>
<p><span style="color:#000000;">scf(</span><span style="color:#0000ff;">2</span><span style="color:#000000;">);</span><br />
<span style="color:#000000;">imshow(P,[]);</span><br />
<span style="font-style:italic;color:#808080;">//roi=im2gray(ROI);</span><br />
<span style="font-style:italic;color:#808080;">//subplot(211);</span><br />
<span style="font-style:italic;color:#808080;">//imshow(roi, []);</span><br />
<span style="font-style:italic;color:#808080;">//subplot(212);</span></p>
<p><span style="font-style:italic;color:#808080;">//&lt;&#8212;&#8212;&#8212;&#8212;-histogram backprohection&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&gt;</span><br />
<span style="font-style:italic;color:#808080;">//histogram </span><br />
<span style="color:#000000;">r=</span><span style="font-weight:bold;font-style:italic;color:#0000ff;">linspace</span><span style="color:#000000;">(</span><span style="color:#0000ff;">0</span><span style="color:#000000;">,</span><span style="color:#0000ff;">1</span><span style="color:#000000;">, </span><span style="color:#0000ff;">32</span><span style="color:#000000;">);</span><br />
<span style="color:#000000;">g=</span><span style="font-weight:bold;font-style:italic;color:#0000ff;">linspace</span><span style="color:#000000;">(</span><span style="color:#0000ff;">0</span><span style="color:#000000;">,</span><span style="color:#0000ff;">1</span><span style="color:#000000;">, </span><span style="color:#0000ff;">32</span><span style="color:#000000;">);</span><br />
<span style="color:#000000;">prob=</span><span style="font-weight:bold;font-style:italic;color:#0000ff;">zeros</span><span style="color:#000000;">(</span><span style="color:#0000ff;">32</span><span style="color:#000000;">, </span><span style="color:#0000ff;">32</span><span style="color:#000000;">);</span><br />
<span style="color:#000000;">[x,y]=</span><span style="font-weight:bold;font-style:italic;color:#0000ff;">size</span><span style="color:#000000;">(ROI_sub);</span><br />
<span style="font-weight:bold;color:#000080;">for</span><span style="color:#000000;"> i=</span><span style="color:#0000ff;">1</span><span style="color:#000000;">: x</span><br />
<span style="color:#000000;"> </span><span style="font-weight:bold;color:#000080;">for</span><span style="color:#000000;"> j=</span><span style="color:#0000ff;">1</span><span style="color:#000000;">:y</span><br />
<span style="color:#000000;"> xr=</span><span style="font-weight:bold;font-style:italic;color:#0000ff;">find</span><span style="color:#000000;">(r&lt;=ROI_sub(i,j,</span><span style="color:#0000ff;">1</span><span style="color:#000000;">));</span><br />
<span style="color:#000000;"> xg=</span><span style="font-weight:bold;font-style:italic;color:#0000ff;">find</span><span style="color:#000000;">(g&lt;=ROI_sub(i,j,</span><span style="color:#0000ff;">2</span><span style="color:#000000;">));</span><br />
<span style="color:#000000;"> prob(xr(</span><span style="font-weight:bold;font-style:italic;color:#0000ff;">length</span><span style="color:#000000;">(xr)), xg(</span><span style="font-weight:bold;font-style:italic;color:#0000ff;">length</span><span style="color:#000000;">(xg)))=prob(xr(</span><span style="font-weight:bold;font-style:italic;color:#0000ff;">length</span><span style="color:#000000;">(xr)), xg(</span><span style="font-weight:bold;font-style:italic;color:#0000ff;">length</span><span style="color:#000000;">(xg)))+</span><span style="color:#0000ff;">1</span><span style="color:#000000;">;</span><br />
<span style="color:#000000;"> </span><span style="font-weight:bold;color:#000080;">end</span><br />
<span style="font-weight:bold;color:#000080;">end</span><br />
<span style="color:#000000;">prob=prob/</span><span style="font-weight:bold;font-style:italic;color:#0000ff;">sum</span><span style="color:#000000;">(prob);</span><br />
<span style="font-style:italic;color:#808080;">//show(prob,[]); xset(&#8220;colormap&#8221;, hotcolormap(256));</span><br />
<span style="color:#000000;">scf(</span><span style="color:#0000ff;">3</span><span style="color:#000000;">)</span><br />
<span style="color:#000000;">surf(prob);</span></p>
<p><span style="font-style:italic;color:#808080;">//backprojection</span><br />
<span style="color:#000000;">[x,y]=</span><span style="font-weight:bold;font-style:italic;color:#0000ff;">size</span><span style="color:#000000;">(ROI);</span><br />
<span style="color:#000000;">rec=</span><span style="font-weight:bold;font-style:italic;color:#0000ff;">zeros</span><span style="color:#000000;">(x,y);</span><br />
<span style="font-weight:bold;color:#000080;">for</span><span style="color:#000000;"> i=</span><span style="color:#0000ff;">1</span><span style="color:#000000;">: x</span><br />
<span style="color:#000000;"> </span><span style="font-weight:bold;color:#000080;">for</span><span style="color:#000000;"> j=</span><span style="color:#0000ff;">1</span><span style="color:#000000;">:y</span><br />
<span style="color:#000000;"> xr=</span><span style="font-weight:bold;font-style:italic;color:#0000ff;">find</span><span style="color:#000000;">(r&lt;=ROI(i,j,</span><span style="color:#0000ff;">1</span><span style="color:#000000;">));</span><br />
<span style="color:#000000;"> xg=</span><span style="font-weight:bold;font-style:italic;color:#0000ff;">find</span><span style="color:#000000;">(g&lt;=ROI(i,j,</span><span style="color:#0000ff;">2</span><span style="color:#000000;">));</span><br />
<span style="color:#000000;"> rec(i,j)=prob(xr(</span><span style="font-weight:bold;font-style:italic;color:#0000ff;">length</span><span style="color:#000000;">(xr)), xg(</span><span style="font-weight:bold;font-style:italic;color:#0000ff;">length</span><span style="color:#000000;">(xg)));</span><br />
<span style="color:#000000;"> </span><span style="font-weight:bold;color:#000080;">end</span><br />
<span style="font-weight:bold;color:#000080;">end</span><br />
<span style="color:#000000;">scf(</span><span style="color:#0000ff;">4</span><span style="color:#000000;">);</span><br />
<span style="color:#000000;">imshow(rec, []);</span><br />
<span style="color:#000000;">rec=</span><span style="font-weight:bold;font-style:italic;color:#0000ff;">round</span><span style="color:#000000;">(rec*255.0);</span><br />
<span style="font-weight:bold;font-style:italic;color:#0000ff;">getf</span><span style="color:#000000;">(&#8216;imhist.sce&#8217;);</span><br />
<span style="color:#000000;">[val, num]=imhist(rec);</span><br />
<span style="color:#000000;">scf(</span><span style="color:#0000ff;">5</span><span style="color:#000000;">);</span><br />
<span style="font-weight:bold;font-style:italic;color:#0000ff;">plot</span><span style="color:#000000;">(val, num);</span><br />
<span style="color:#000000;">scf(</span><span style="color:#0000ff;">6</span><span style="color:#000000;">);</span><br />
<span style="color:#000000;">rec=im2bw(rec, </span><span style="color:#0000ff;">70</span><span style="color:#000000;">/</span><span style="color:#0000ff;">255</span><span style="color:#000000;">);</span><br />
<span style="color:#000000;">imshow(rec, []);</span></p>
<p><span style="font-style:italic;color:#808080;">//opening</span><br />
<span style="color:#000000;">se=</span><span style="font-weight:bold;font-style:italic;color:#0000ff;">ones</span><span style="color:#000000;">(</span><span style="color:#0000ff;">3</span><span style="color:#000000;">,</span><span style="color:#0000ff;">3</span><span style="color:#000000;">);</span><br />
<span style="color:#000000;">im=rec;</span><br />
<span style="color:#000000;">im=erode(im, se);</span><br />
<span style="color:#000000;">im=dilate(im, se);</span><br />
<span style="color:#000000;">scf(</span><span style="color:#0000ff;">7</span><span style="color:#000000;">);</span><br />
<span style="color:#000000;">imshow(im, []);</span><br />
<span style="color:#000000;"> </span></p>
<p style="text-align:center;">-oOo-</p>
<p style="text-align:left;">I give myself a 10 here because I did well in segmenting the images. <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p style="text-align:left;">
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/incisors.wordpress.com/294/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/incisors.wordpress.com/294/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/incisors.wordpress.com/294/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/incisors.wordpress.com/294/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/incisors.wordpress.com/294/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/incisors.wordpress.com/294/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/incisors.wordpress.com/294/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/incisors.wordpress.com/294/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/incisors.wordpress.com/294/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/incisors.wordpress.com/294/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/incisors.wordpress.com/294/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/incisors.wordpress.com/294/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/incisors.wordpress.com/294/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/incisors.wordpress.com/294/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/incisors.wordpress.com/294/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/incisors.wordpress.com/294/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=incisors.wordpress.com&amp;blog=3941311&amp;post=294&amp;subd=incisors&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://incisors.wordpress.com/2008/09/02/activity-16-image-segmentation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7180bfbb1df0d02507e75d02e265e0fa?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">jptugaff</media:title>
		</media:content>

		<media:content url="http://incisors.files.wordpress.com/2008/09/normalized_chromaticity.png" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/09/normalized.png" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/09/i.png" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/09/face.jpg" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/09/face_cropped.jpg" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/09/gaussian-red.png" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/09/gaussian-green.png" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/09/mu.png" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/09/sigma.png" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/09/p.png" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/09/face_pdf.gif?w=300" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/09/face_parametric.gif" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/09/2d-hist.jpg?w=300" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/09/face-hist-back.gif" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/09/binary.gif" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/09/opened.gif" medium="image" />
	</item>
		<item>
		<title>Activity 15: White Balancing</title>
		<link>http://incisors.wordpress.com/2008/08/28/activity-15-white-balancing/</link>
		<comments>http://incisors.wordpress.com/2008/08/28/activity-15-white-balancing/#comments</comments>
		<pubDate>Thu, 28 Aug 2008 03:07:09 +0000</pubDate>
		<dc:creator>jptugaff</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://incisors.wordpress.com/?p=270</guid>
		<description><![CDATA[White balancing is a technique wherein in images captured under lighting conditions are corrected such that white appears white. It may not really be obvious (since the eyes have white balancing capabilities) unless we compare the object with the image itself. Here is an image of a rubix cube take under different white-balancing conditions in [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=incisors.wordpress.com&amp;blog=3941311&amp;post=270&amp;subd=incisors&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:left;">White balancing is a technique wherein in images captured under lighting conditions are corrected such that white appears white. It may not really be obvious (since the eyes have white balancing capabilities) unless we compare the object with the image itself. Here is an image of a rubix cube take under different white-balancing conditions in a room with fluorescent light.</p>
<p style="text-align:center;"><a href="http://incisors.files.wordpress.com/2008/08/auto.jpg"><img class="size-medium wp-image-264 aligncenter" src="http://incisors.files.wordpress.com/2008/08/auto.jpg?w=300&#038;h=225" alt="" width="300" height="225" /></a></p>
<p style="text-align:center;">Automatic white balancing.</p>
<p style="text-align:center;"><a href="http://incisors.files.wordpress.com/2008/08/cloudy.jpg"><img class="alignnone size-thumbnail wp-image-265" src="http://incisors.files.wordpress.com/2008/08/cloudy.jpg?w=128&#038;h=96" alt="" width="128" height="96" /></a><a href="http://incisors.files.wordpress.com/2008/08/daylight.jpg"><img class="alignnone size-thumbnail wp-image-266" src="http://incisors.files.wordpress.com/2008/08/daylight.jpg?w=128&#038;h=96" alt="" width="128" height="96" /></a><a href="http://incisors.files.wordpress.com/2008/08/fluorescent.jpg"><img class="alignnone size-thumbnail wp-image-267" src="http://incisors.files.wordpress.com/2008/08/fluorescent.jpg?w=128&#038;h=96" alt="" width="128" height="96" /></a></p>
<p style="text-align:center;">cloudy, daylight and fluorescent white balancing</p>
<p><a href="http://incisors.files.wordpress.com/2008/08/tungsten.jpg"><img class="aligncenter size-medium wp-image-261" src="http://incisors.files.wordpress.com/2008/08/tungsten.jpg?w=300&#038;h=225" alt="" width="300" height="225" /></a></p>
<p style="text-align:center;">tungsten white balancing</p>
<p style="text-align:left;">From the images above, we can see that if you just used any white balance, we may not get the desired image. And can be seen in the case of tungsten, white doesn&#8217;t appear white.This can be corrected via white balancing methods. There are two methods that can be used in performing white balancing, namely, the <strong>Reference White</strong> and the <strong>Gray World algorithm</strong>.</p>
<p style="text-align:left;">Let&#8217;s start with the basic. A digital image is composed of an MxNx3 matrix where MxN is the dimension of the image and there are 3 channels for that image. Each channel corresponds to one of the three primary colors namely red, green and blue. A pixel then is contains the information about the amount of red, green and blue in that channel. The reference white algorithm works by choosing a white object in the image and getting it&#8217;s RGB values. This is used as reference for determining which is &#8220;white&#8221; in the image. The red channels of each pixel is divided by the red value of the reference white object. The same is done for all other channels. The gray world algorithm on the other hand works by assuming the image is gray (ie, each pixel has equal R-G-B values).The gray world algorithim is implemented by averaging the R-G-B of each channel in the unbalanced image. The red channel of the unbalanced image is then divided by the R above. The same is done for the blue and green channels. If a channel exceeds 1.0 on any pixel, it is cut-off to 1.0 to avoid saturation.</p>
<p style="text-align:left;">Here is the result of white balancing using the gray world algo (left) and the reference white (right). As can be seen here, can see that reference white is superior in terms of image quality. The problem with GWA is that averaging channels puts bias to colors that are not abundant. In our case, there is bias against the green.</p>
<p><a href="http://incisors.files.wordpress.com/2008/08/tungstengw.jpg"><img class="alignnone size-medium wp-image-263" src="http://incisors.files.wordpress.com/2008/08/tungstengw.jpg?w=231&#038;h=172" alt="" width="231" height="172" /></a><a href="http://incisors.files.wordpress.com/2008/08/tungstenrw.jpg"><img class="alignnone size-medium wp-image-262" src="http://incisors.files.wordpress.com/2008/08/tungstenrw.jpg?w=231&#038;h=173" alt="" width="231" height="173" /></a></p>
<p>Here we tried to implement GWA and RW by making the background white to ensure more or less the same amount of colors present.</p>
<p><a href="http://incisors.files.wordpress.com/2008/08/leaf_and_all-006.jpg"><img class="aligncenter size-medium wp-image-273" src="http://incisors.files.wordpress.com/2008/08/leaf_and_all-006.jpg?w=235&#038;h=300" alt="" width="235" height="300" /></a></p>
<p>Here is the results for GWA (left) and RF (right). The rendering of white of GWA is OK, and is close to the actual image. On the other hand, the RF method produced a very brightly colored image. Now, we can see that a disadvantage of RF is that it relies on what should be white and is highly subjective then. A problem would exist in RF if there are no white objects in the image (or if a reference white is not exactly white).</p>
<p><a href="http://incisors.files.wordpress.com/2008/08/leaf_and_all-006gw.jpg"><img class="alignnone size-full wp-image-274" src="http://incisors.files.wordpress.com/2008/08/leaf_and_all-006gw.jpg?w=495" alt=""   /></a><a href="http://incisors.files.wordpress.com/2008/08/leaf_and_all-006rw.jpg"><img class="alignnone size-medium wp-image-275" src="http://incisors.files.wordpress.com/2008/08/leaf_and_all-006rw.jpg?w=235&#038;h=300" alt="" width="235" height="300" /></a></p>
<p>Here we used many shades of green in performing white balancing.</p>
<p><a href="http://incisors.files.wordpress.com/2008/08/leaf_and_all-001.jpg"><img class="aligncenter size-medium wp-image-277" src="http://incisors.files.wordpress.com/2008/08/leaf_and_all-001.jpg?w=300&#038;h=225" alt="" width="300" height="225" /></a></p>
<p>We can see that the GWA produced better results than RF. Again, RF saturated with the white.</p>
<p><a href="http://incisors.files.wordpress.com/2008/08/leaf_and_all-001gw.jpg"><img class="alignnone size-medium wp-image-278" src="http://incisors.files.wordpress.com/2008/08/leaf_and_all-001gw.jpg?w=231&#038;h=173" alt="" width="231" height="173" /></a><a href="http://incisors.files.wordpress.com/2008/08/leaf_and_all-001rw.jpg"><img class="alignnone size-medium wp-image-279" src="http://incisors.files.wordpress.com/2008/08/leaf_and_all-001rw.jpg?w=219&#038;h=173" alt="" width="219" height="173" /></a></p>
<p>I give myself a 10 for this activity.</p>
<p style="text-align:center;">-oOo-</p>
<p style="text-align:left;">
<p><span style="font-weight:bold;font-style:italic;color:#0000ff;">clear</span><span style="color:#000000;"> all;</span><br />
<span style="font-weight:bold;font-style:italic;color:#0000ff;">stacksize</span><span style="color:#000000;">(4e7);</span><br />
<span style="color:#000000;">name=&#8217;leaf_and_all </span><span style="color:#0000ff;">001</span><span style="color:#000000;">&#8216;</span><br />
<span style="color:#000000;">im=imread(</span><span style="font-weight:bold;font-style:italic;color:#0000ff;">strcat</span><span style="color:#000000;">(name + &#8216;.jpg&#8217;));</span><br />
<span style="font-style:italic;color:#808080;">//imshow(im);</span><br />
<span style="font-style:italic;color:#808080;">//[b,xc,yc]=xclick()</span><br />
<span style="font-style:italic;color:#808080;">//reference white</span><br />
<span style="color:#000000;">x=</span><span style="color:#0000ff;">124</span><span style="color:#000000;">;</span><br />
<span style="color:#000000;">y=</span><span style="color:#0000ff;">184</span><span style="color:#000000;">;</span><br />
<span style="color:#000000;">r=im(x,y,</span><span style="color:#0000ff;">1</span><span style="color:#000000;">);</span><br />
<span style="color:#000000;">g=im(x,y,</span><span style="color:#0000ff;">2</span><span style="color:#000000;">);</span><br />
<span style="color:#000000;">b=im(x,y,</span><span style="color:#0000ff;">3</span><span style="color:#000000;">);</span><br />
<span style="color:#000000;">im1=[];</span><br />
<span style="color:#000000;">im1(:,:,</span><span style="color:#0000ff;">1</span><span style="color:#000000;">)=im(:,:,</span><span style="color:#0000ff;">1</span><span style="color:#000000;">)/r;</span><br />
<span style="color:#000000;">im1(:,:,</span><span style="color:#0000ff;">2</span><span style="color:#000000;">)=im(:,:,</span><span style="color:#0000ff;">2</span><span style="color:#000000;">)/g;</span><br />
<span style="color:#000000;">im1(:,:,</span><span style="color:#0000ff;">3</span><span style="color:#000000;">)=im(:,:,</span><span style="color:#0000ff;">3</span><span style="color:#000000;">)/b;</span><br />
<span style="color:#000000;">g=</span><span style="font-weight:bold;font-style:italic;color:#0000ff;">find</span><span style="color:#000000;">(im1&gt;1.0);</span><br />
<span style="color:#000000;">im1(g)=1.0;</span><br />
<span style="color:#000000;">imwrite(im1, </span><span style="font-weight:bold;font-style:italic;color:#0000ff;">strcat</span><span style="color:#000000;">(name +  &#8216;rw.jpg&#8217;));</span><br />
<span style="font-style:italic;color:#808080;">//imshow(im,[]);</span></p>
<p><span style="font-style:italic;color:#808080;">//grayworld</span><br />
<span style="color:#000000;">r=</span><span style="font-weight:bold;font-style:italic;color:#0000ff;">mean</span><span style="color:#000000;">(im(:,:,</span><span style="color:#0000ff;">1</span><span style="color:#000000;">));</span><br />
<span style="color:#000000;">g=</span><span style="font-weight:bold;font-style:italic;color:#0000ff;">mean</span><span style="color:#000000;">(im(:,:,</span><span style="color:#0000ff;">2</span><span style="color:#000000;">));</span><br />
<span style="color:#000000;">b=</span><span style="font-weight:bold;font-style:italic;color:#0000ff;">mean</span><span style="color:#000000;">(im(:,:,</span><span style="color:#0000ff;">3</span><span style="color:#000000;">));</span><br />
<span style="color:#000000;">im2=[]</span><br />
<span style="color:#000000;">im2(:,:,</span><span style="color:#0000ff;">1</span><span style="color:#000000;">)=im(:,:,</span><span style="color:#0000ff;">1</span><span style="color:#000000;">)/r;</span><br />
<span style="color:#000000;">im2(:,:,</span><span style="color:#0000ff;">2</span><span style="color:#000000;">)=im(:,:,</span><span style="color:#0000ff;">2</span><span style="color:#000000;">)/g;</span><br />
<span style="color:#000000;">im2(:,:,</span><span style="color:#0000ff;">3</span><span style="color:#000000;">)=im(:,:,</span><span style="color:#0000ff;">3</span><span style="color:#000000;">)/b;</span><br />
<span style="color:#000000;">im2=im2/</span><span style="font-weight:bold;font-style:italic;color:#0000ff;">max</span><span style="color:#000000;">(im2);</span><br />
<span style="color:#000000;">g=</span><span style="font-weight:bold;font-style:italic;color:#0000ff;">find</span><span style="color:#000000;">(im2&gt;1.0);</span><br />
<span style="color:#000000;">im2(g)=1.0;</span><br />
<span style="color:#000000;">imwrite(im2, </span><span style="font-weight:bold;font-style:italic;color:#0000ff;">strcat</span><span style="color:#000000;">(name + &#8216;gw.jpg&#8217;));</span><br />
<span style="font-style:italic;color:#808080;">//imshow(im,[]);</span></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/incisors.wordpress.com/270/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/incisors.wordpress.com/270/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/incisors.wordpress.com/270/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/incisors.wordpress.com/270/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/incisors.wordpress.com/270/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/incisors.wordpress.com/270/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/incisors.wordpress.com/270/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/incisors.wordpress.com/270/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/incisors.wordpress.com/270/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/incisors.wordpress.com/270/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/incisors.wordpress.com/270/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/incisors.wordpress.com/270/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/incisors.wordpress.com/270/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/incisors.wordpress.com/270/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/incisors.wordpress.com/270/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/incisors.wordpress.com/270/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=incisors.wordpress.com&amp;blog=3941311&amp;post=270&amp;subd=incisors&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://incisors.wordpress.com/2008/08/28/activity-15-white-balancing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7180bfbb1df0d02507e75d02e265e0fa?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">jptugaff</media:title>
		</media:content>

		<media:content url="http://incisors.files.wordpress.com/2008/08/auto.jpg?w=300" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/08/cloudy.jpg?w=128" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/08/daylight.jpg?w=128" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/08/fluorescent.jpg?w=128" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/08/tungsten.jpg?w=300" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/08/tungstengw.jpg?w=300" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/08/tungstenrw.jpg?w=300" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/08/leaf_and_all-006.jpg?w=235" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/08/leaf_and_all-006gw.jpg" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/08/leaf_and_all-006rw.jpg?w=235" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/08/leaf_and_all-001.jpg?w=300" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/08/leaf_and_all-001gw.jpg?w=300" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/08/leaf_and_all-001rw.jpg?w=300" medium="image" />
	</item>
		<item>
		<title>Activity 14: Stereometry</title>
		<link>http://incisors.wordpress.com/2008/08/12/activity-14-stereometry/</link>
		<comments>http://incisors.wordpress.com/2008/08/12/activity-14-stereometry/#comments</comments>
		<pubDate>Tue, 12 Aug 2008 03:08:27 +0000</pubDate>
		<dc:creator>jptugaff</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://incisors.wordpress.com/?p=234</guid>
		<description><![CDATA[here is the RQ factorization code from: http://www.cs.nyu.edu/faculty/overton/software/uncontrol/rq.m written by Michael Overton and modified by yours truly for scilab. -oOo- function [R,Q]= rq(A) //% full RQ factorization //% returns [R 0] and Q such that [R 0] Q = A //% where R is upper triangular and Q is unitary (square) //% and A is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=incisors.wordpress.com&amp;blog=3941311&amp;post=234&amp;subd=incisors&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>here is the RQ factorization code from: <a href="http://www.cs.nyu.edu/faculty/overton/software/uncontrol/rq.m">http://www.cs.nyu.edu/faculty/overton/software/uncontrol/rq.m</a> written by Michael Overton and modified by yours truly for scilab.</p>
<p style="text-align:center;">-oOo-</p>
<p>function [R,Q]= rq(A)<br />
//% full RQ factorization<br />
//% returns [R 0] and Q such that [R 0] Q = A<br />
//% where R is upper triangular and Q is unitary (square)<br />
//% and A is m by n, n &gt;= m  (A is short and fat)<br />
//% Equivalent to   A&#8217; = Q&#8217; [R']  (A&#8217; is tall and skinny)<br />
//%                         [0 ]<br />
//% or<br />
//%                 A&#8217;P = Q&#8217;[P 0] [P R' P]<br />
//%                         [0 I] [  0   ]<br />
//% where P is the reverse identity matrix of order m (small dim)<br />
//% This is an ordinary QR factorization, say Q2 R2.<br />
//% Written by Michael Overton, overton@cs.nyu.edu (last updated Nov 2003)</p>
<p>m = size(A,1);<br />
n = size(A,2);<br />
if n &lt; m<br />
error(&#8216;RQ requires m &lt;= n&#8217;)<br />
end<br />
P = mtlb_fliplr(mtlb_eye(m));<br />
AtP = A&#8217;*P;<br />
[Q2,R2] = qr(AtP);<br />
bigperm = [P zeros(m,n-m); zeros(n-m,m) mtlb_eye(n-m)];<br />
Q = (Q2*bigperm)&#8217;;<br />
R = (bigperm*R2*P)&#8217;;</p>
<p style="text-align:center;">-oOo-</p>
<p style="text-align:left;">you can invoke the function by saving the file as &#8216;rq.sce&#8217; and invoking at using getf(&#8216;rq.sce&#8217;);</p>
<p style="text-align:left;">
<p style="text-align:left;"><img class="aligncenter size-medium wp-image-242" src="http://incisors.files.wordpress.com/2008/08/ac14-fig11.png?w=289&#038;h=288" alt="" width="289" height="288" /></p>
<p style="text-align:left;">The principle behind stereometry is based on the human eye perception of depth. In humans, we perecieve depth by viewing the same object at two different angles (hence, two eyes). The lens in at position x=0 sees the object at X at different angle from x=b. Thus, by simple ratio and proportion, we can percieve depth z using the relation</p>
<p style="text-align:center;"><img class="size-full wp-image-254 aligncenter" src="http://incisors.files.wordpress.com/2008/08/z1.png?w=495" alt=""   /></p>
<p style="text-align:left;">where <em>b</em> is the separation distance of the lens, <em>f </em>is the focal length of the camera, and <em>x2</em> and <em>x1</em> are the location of the locations of the objects from the two different images.</p>
<p style="text-align:left;"><img class="alignnone size-medium wp-image-244" src="http://incisors.files.wordpress.com/2008/08/picture-010.jpg?w=234&#038;h=188" alt="" width="234" height="188" /><img class="alignnone size-medium wp-image-245" src="http://incisors.files.wordpress.com/2008/08/picture-011.jpg?w=250&#038;h=187" alt="" width="250" height="187" /></p>
<p style="text-align:center;"><img class="size-full wp-image-256 aligncenter" src="http://incisors.files.wordpress.com/2008/08/k1.png?w=495" alt=""   /></p>
<p style="text-align:left;">where <img class="alignnone size-full wp-image-257" src="http://incisors.files.wordpress.com/2008/08/ax.png?w=495" alt=""   /> and <img class="alignnone size-full wp-image-258" src="http://incisors.files.wordpress.com/2008/08/ay.png?w=495" alt=""   />. However, if we are lucky enough, we may not need to compute for K if pertinent information such as <em>f</em> is given in the metadata of our camera. In our case, <em>f</em>=5.4mm. In any case, i still calculated <em><strong>K</strong></em> and found it to be</p>
<p style="text-align:center;"><img class="size-full wp-image-251 aligncenter" src="http://incisors.files.wordpress.com/2008/08/k.png?w=495" alt=""   /></p>
<p style="text-align:left;">Note that xo=228 and y=329, which is near the center of a 480&#215;640 image. Take note, however, that the image center may not be the 1/2 the image dimensions.</p>
<p style="text-align:left;">Reconstruction is done by getting as much (x,y) corresponding values in the two images. Take note that each point should have a correspondence in the other image. After which, bicubic spline splin2d and interpolation interp2d is done to create a smooth surface for our reconstruction.</p>
<p style="text-align:center;">
<p style="text-align:left;">After reconstruction, we result in the following image. Although it may not actually be obvious at first glance, the resulting images do resemble the front and top facade of the rubix cube. Shown below are the reconstruction viewed from different angles (the thick black lines are aides in deciphering the shape of the object).</p>
<p style="text-align:center;"><a href="http://incisors.files.wordpress.com/2008/08/a14.gif"><img class="size-medium wp-image-247 aligncenter" src="http://incisors.files.wordpress.com/2008/08/a14.gif?w=300&#038;h=199" alt="" width="300" height="199" /></a></p>
<p style="text-align:center;"><a href="http://incisors.files.wordpress.com/2008/08/a14-2.gif"><img class="size-medium wp-image-248 aligncenter" src="http://incisors.files.wordpress.com/2008/08/a14-2.gif?w=300&#038;h=199" alt="" width="300" height="199" /></a></p>
<p style="text-align:center;"><a href="http://incisors.files.wordpress.com/2008/08/a14-3.gif"><img class="size-medium wp-image-249 aligncenter" src="http://incisors.files.wordpress.com/2008/08/a14-3.gif?w=300&#038;h=199" alt="" width="300" height="199" /></a></p>
<p style="text-align:left;">One of the obvious error in the reconstruction is the waviness of the surface. The reason for this is the finite number of points that we have chosen for reconstruction (in my case, 24) and the way splin2d and interp interpolates points in the mesh. Another possible error is the fact that our images are 2d and not 3d, and as such, any 2 points in the 3d object may have the same (x,y) coordinate in the image plane.</p>
<p style="text-align:left;">I want to give myself here a 9 because even though the reconstruction along the x seems flawed, i was able to extact depth (or z values) of the images.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/incisors.wordpress.com/234/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/incisors.wordpress.com/234/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/incisors.wordpress.com/234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/incisors.wordpress.com/234/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/incisors.wordpress.com/234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/incisors.wordpress.com/234/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/incisors.wordpress.com/234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/incisors.wordpress.com/234/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/incisors.wordpress.com/234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/incisors.wordpress.com/234/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/incisors.wordpress.com/234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/incisors.wordpress.com/234/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/incisors.wordpress.com/234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/incisors.wordpress.com/234/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/incisors.wordpress.com/234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/incisors.wordpress.com/234/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=incisors.wordpress.com&amp;blog=3941311&amp;post=234&amp;subd=incisors&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://incisors.wordpress.com/2008/08/12/activity-14-stereometry/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7180bfbb1df0d02507e75d02e265e0fa?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">jptugaff</media:title>
		</media:content>

		<media:content url="http://incisors.files.wordpress.com/2008/08/ac14-fig11.png?w=289" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/08/z1.png" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/08/picture-010.jpg?w=300" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/08/picture-011.jpg?w=300" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/08/k1.png" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/08/ax.png" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/08/ay.png" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/08/k.png" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/08/a14.gif?w=300" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/08/a14-2.gif?w=300" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/08/a14-3.gif?w=300" medium="image" />
	</item>
		<item>
		<title>Activity 13: Photometric Stereo</title>
		<link>http://incisors.wordpress.com/2008/08/07/activity-13-photometric-stereo/</link>
		<comments>http://incisors.wordpress.com/2008/08/07/activity-13-photometric-stereo/#comments</comments>
		<pubDate>Thu, 07 Aug 2008 03:13:05 +0000</pubDate>
		<dc:creator>jptugaff</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://incisors.wordpress.com/?p=197</guid>
		<description><![CDATA[We consider a point light source from infinity located at . The intensity as captured by the camera at image location (x,y) is proportional to the brightness . Thus we have then where We can approximate the shape of an object by varying the light source and taking the picture of the image at various [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=incisors.wordpress.com&amp;blog=3941311&amp;post=197&amp;subd=incisors&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>We consider a point light source from infinity located at <img class="alignnone size-medium wp-image-209" src="http://incisors.files.wordpress.com/2008/08/s1.png?w=12&#038;h=15" alt="" width="12" height="15" /> . The intensity <img class="alignnone size-medium wp-image-210" src="http://incisors.files.wordpress.com/2008/08/i.png?w=30&#038;h=12" alt="" width="30" height="12" /> as captured by the camera at image location (x,y) is proportional to the brightness <img class="alignnone size-medium wp-image-211" src="http://incisors.files.wordpress.com/2008/08/b.png?w=33&#038;h=12" alt="" width="33" height="12" />. Thus we have</p>
<p style="text-align:center;"><img class="aligncenter size-medium wp-image-227" src="http://incisors.files.wordpress.com/2008/08/intensity.png?w=84&#038;h=12" alt="" width="84" height="12" /></p>
<p style="text-align:left;">then</p>
<p style="text-align:center;"><img class="size-medium wp-image-213 aligncenter" src="http://incisors.files.wordpress.com/2008/08/eq4.png?w=135&#038;h=32" alt="" width="135" height="32" /></p>
<p style="text-align:left;">where</p>
<p style="text-align:left;"><img class="aligncenter size-medium wp-image-214" src="http://incisors.files.wordpress.com/2008/08/56.png?w=117&#038;h=29" alt="" width="117" height="29" /></p>
<p style="text-align:left;">
<p>We can approximate the shape of an object by varying the light source and taking the picture of the image at various locations. The (x,y,z) of the light sources are stored in the matrix <em>V</em>.</p>
<p>Thus, we have</p>
<p><img class="aligncenter size-medium wp-image-217" src="http://incisors.files.wordpress.com/2008/08/7.png?w=119&#038;h=81" alt="" width="119" height="81" /></p>
<p>which are the the (x,y,z) locations of the N sources. The intensity for each point in the image is given by</p>
<p><img class="aligncenter size-medium wp-image-219" src="http://incisors.files.wordpress.com/2008/08/8.png?w=162&#038;h=63" alt="" width="162" height="63" /></p>
<p>or in matrix form</p>
<p><img class="aligncenter size-medium wp-image-220" src="http://incisors.files.wordpress.com/2008/08/9.png?w=26&#038;h=12" alt="" width="26" height="12" /></p>
<p>Since we know <strong>I</strong> and <strong>V</strong>, we can solve for <strong>g</strong> using</p>
<p><img class="aligncenter size-medium wp-image-221" src="http://incisors.files.wordpress.com/2008/08/10.png?w=87&#038;h=18" alt="" width="87" height="18" /></p>
<p>We get the normalize vectors using</p>
<p><img class="aligncenter size-medium wp-image-222" src="http://incisors.files.wordpress.com/2008/08/11.png?w=35&#038;h=25" alt="" width="35" height="25" /></p>
<p>After some manipulations we can compute the elevation z=f(x,y) using at any given (x,y) using</p>
<p><img class="aligncenter size-medium wp-image-223" src="http://incisors.files.wordpress.com/2008/08/14.png?w=109&#038;h=27" alt="" width="109" height="27" /></p>
<p><img class="aligncenter size-medium wp-image-224" src="http://incisors.files.wordpress.com/2008/08/15.png?w=188&#038;h=31" alt="" width="188" height="31" /></p>
<p><a href="http://incisors.files.wordpress.com/2008/08/images.png"><img class="aligncenter size-medium wp-image-206" src="http://incisors.files.wordpress.com/2008/08/images.png?w=300&#038;h=291" alt="" width="300" height="291" /></a></p>
<p><a href="http://incisors.files.wordpress.com/2008/08/reconstruction1.png"><img class="aligncenter size-medium wp-image-231" src="http://incisors.files.wordpress.com/2008/08/reconstruction1.png?w=300&#038;h=226" alt="" width="300" height="226" /></a></p>
<p>code:<br />
<span style="color:#000000;">loadmatfile(&#8216;Photos.mat&#8217;);</span></p>
<p><span style="color:#000000;">V(</span><span style="color:#0000ff;">1</span><span style="color:#000000;">,: ) = [0.085832 0.17365 0.98106]; </span><br />
<span style="color:#000000;">V(</span><span style="color:#0000ff;">2</span><span style="color:#000000;">,: ) = [0.085832 -0.17365 0.98106];</span><br />
<span style="color:#000000;">V(</span><span style="color:#0000ff;">3</span><span style="color:#000000;">,: ) = [0.17365 </span><span style="color:#0000ff;">0</span><span style="color:#000000;"> 0.98481];</span><br />
<span style="color:#000000;">V(</span><span style="color:#0000ff;">4</span><span style="color:#000000;">,: ) = [0.16318 -0.34202 0.92542];</span></p>
<p><span style="color:#000000;">I(</span><span style="color:#0000ff;">1</span><span style="color:#000000;">, : ) = I1(: )&#8217;;</span><br />
<span style="color:#000000;">I(</span><span style="color:#0000ff;">2</span><span style="color:#000000;">, : ) = I2(: )&#8217;;</span><br />
<span style="color:#000000;">I(</span><span style="color:#0000ff;">3</span><span style="color:#000000;">, : ) = I3(: )&#8217;;</span><br />
<span style="color:#000000;">I(</span><span style="color:#0000ff;">4</span><span style="color:#000000;">, : ) = I4(: )&#8217;;</span></p>
<p><span style="color:#000000;">g = </span><span style="font-weight:bold;font-style:italic;color:#0000ff;">inv</span><span style="color:#000000;">(V&#8217;*V)*V&#8217;*I;</span><br />
<span style="color:#000000;">g = g;</span><br />
<span style="color:#000000;">ag = </span><span style="font-weight:bold;font-style:italic;color:#0000ff;">sqrt</span><span style="color:#000000;">((g(</span><span style="color:#0000ff;">1</span><span style="color:#000000;">,:).*g(</span><span style="color:#0000ff;">1</span><span style="color:#000000;">,: ))+(g(</span><span style="color:#0000ff;">2</span><span style="color:#000000;">,:).*g(</span><span style="color:#0000ff;">2</span><span style="color:#000000;">,: ))+(g(</span><span style="color:#0000ff;">3</span><span style="color:#000000;">,: ).*g(</span><span style="color:#0000ff;">3</span><span style="color:#000000;">,: )))+1e-6;</span></p>
<p><span style="font-weight:bold;color:#000080;">for</span><span style="color:#000000;"> i = </span><span style="color:#0000ff;">1</span><span style="color:#000000;">:</span><span style="color:#0000ff;">3</span><br />
<span style="color:#000000;"> n(i,: ) = g(i,: )./(ag);</span><br />
<span style="font-weight:bold;color:#000080;">end</span></p>
<p>//get derivatives</p>
<p><span style="color:#000000;">dfx = -n(</span><span style="color:#0000ff;">1</span><span style="color:#000000;">,: )./(nz+1e-6);</span><br />
<span style="color:#000000;">dfy = -n(</span><span style="color:#0000ff;">2</span><span style="color:#000000;">,: )./(nz+1e-6);</span></p>
<p>//get estimate of line integrals</p>
<p><span style="color:#000000;">int1 = </span><span style="font-weight:bold;font-style:italic;color:#0000ff;">cumsum</span><span style="color:#000000;">(</span><span style="font-weight:bold;font-style:italic;color:#0000ff;">matrix</span><span style="color:#000000;">(dfx,</span><span style="color:#0000ff;">128</span><span style="color:#000000;">,</span><span style="color:#0000ff;">128</span><span style="color:#000000;">),</span><span style="color:#0000ff;">2</span><span style="color:#000000;">);</span><br />
<span style="color:#000000;">int2 = </span><span style="font-weight:bold;font-style:italic;color:#0000ff;">cumsum</span><span style="color:#000000;">(</span><span style="font-weight:bold;font-style:italic;color:#0000ff;">matrix</span><span style="color:#000000;">(dfy,</span><span style="color:#0000ff;">128</span><span style="color:#000000;">,</span><span style="color:#0000ff;">128</span><span style="color:#000000;">),</span><span style="color:#0000ff;">1</span><span style="color:#000000;">);</span><br />
<span style="color:#000000;">z = int1+int2;</span><br />
<span style="font-weight:bold;font-style:italic;color:#0000ff;">plot3d</span><span style="color:#000000;">(</span><span style="color:#0000ff;">1</span><span style="color:#000000;">:</span><span style="color:#0000ff;">128</span><span style="color:#000000;">, </span><span style="color:#0000ff;">1</span><span style="color:#000000;">:</span><span style="color:#0000ff;">128</span><span style="color:#000000;">, z);</span></p>
<p>I give my self 10 points for this activity because there is high similarity in the shape of the actual object and photometric stereo.</p>
<p>Collaborators: Cole, Benj, Mark</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/incisors.wordpress.com/197/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/incisors.wordpress.com/197/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/incisors.wordpress.com/197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/incisors.wordpress.com/197/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/incisors.wordpress.com/197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/incisors.wordpress.com/197/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/incisors.wordpress.com/197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/incisors.wordpress.com/197/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/incisors.wordpress.com/197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/incisors.wordpress.com/197/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/incisors.wordpress.com/197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/incisors.wordpress.com/197/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/incisors.wordpress.com/197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/incisors.wordpress.com/197/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/incisors.wordpress.com/197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/incisors.wordpress.com/197/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=incisors.wordpress.com&amp;blog=3941311&amp;post=197&amp;subd=incisors&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://incisors.wordpress.com/2008/08/07/activity-13-photometric-stereo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7180bfbb1df0d02507e75d02e265e0fa?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">jptugaff</media:title>
		</media:content>

		<media:content url="http://incisors.files.wordpress.com/2008/08/s1.png?w=12" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/08/i.png?w=30" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/08/b.png?w=33" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/08/intensity.png?w=84" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/08/eq4.png?w=135" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/08/56.png?w=117" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/08/7.png?w=246" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/08/8.png?w=162" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/08/9.png?w=26" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/08/10.png?w=87" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/08/11.png?w=35" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/08/14.png?w=109" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/08/15.png?w=188" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/08/images.png?w=300" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/08/reconstruction1.png?w=300" medium="image" />
	</item>
		<item>
		<title>Activity 12: Correcting Geometric Distortions (partial)</title>
		<link>http://incisors.wordpress.com/2008/07/31/activity-12-image-distortion-correction-partial/</link>
		<comments>http://incisors.wordpress.com/2008/07/31/activity-12-image-distortion-correction-partial/#comments</comments>
		<pubDate>Thu, 31 Jul 2008 09:52:37 +0000</pubDate>
		<dc:creator>jptugaff</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://incisors.wordpress.com/?p=161</guid>
		<description><![CDATA[*note. i still have to implement grayscale interpolation. as of the moment, i only did the pixel coordinate correction. We can imagine our image as if it was warped through some linear transformation. To better visualize the problem, we assume that we have a straight grid as pictured in the right side of the above [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=incisors.wordpress.com&amp;blog=3941311&amp;post=161&amp;subd=incisors&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>*note. i still have to implement grayscale interpolation. as of the moment, i only did the pixel coordinate correction.</p>
<p><a href="http://incisors.files.wordpress.com/2008/07/distorted-capiz-window.jpg"><img class="aligncenter size-medium wp-image-162" src="http://incisors.files.wordpress.com/2008/07/distorted-capiz-window.jpg?w=200&#038;h=267" alt="" width="200" height="267" /></a></p>
<p>We can imagine our image as if it was warped through some linear transformation.</p>
<p><a href="http://incisors.files.wordpress.com/2008/08/pixel_correction.png"><img class="aligncenter size-medium wp-image-194" src="http://incisors.files.wordpress.com/2008/08/pixel_correction.png?w=400&#038;h=198" alt="" width="400" height="198" /></a></p>
<p>To better visualize the problem, we assume that we have a straight grid as pictured in the right side of the above image. However, since the camera has inherent geometrical aberrations, the picture we image would be warped and transformation is given as</p>
<p><img class="aligncenter size-medium wp-image-170" src="http://incisors.files.wordpress.com/2008/07/xmap.png?w=89&#038;h=22" alt="" width="89" height="22" /></p>
<p><img class="aligncenter size-medium wp-image-171" src="http://incisors.files.wordpress.com/2008/07/ymap.png?w=88&#038;h=22" alt="" width="88" height="22" /></p>
<p>where x&#8217; and y&#8217; are the coordinates of the pixels x,y (orig image) in the distorted image. Further, we assume that the transformation is is that of a bilinear function as shown below.</p>
<p><img class="aligncenter size-medium wp-image-169" src="http://incisors.files.wordpress.com/2008/07/r.png?w=242&#038;h=21" alt="" width="242" height="21" /></p>
<p><img class="aligncenter size-medium wp-image-173" src="http://incisors.files.wordpress.com/2008/07/s.png?w=241&#038;h=21" alt="" width="241" height="21" /></p>
<p>Thus, we have the transformation function as</p>
<p><img class="aligncenter size-medium wp-image-172" src="http://incisors.files.wordpress.com/2008/07/transformation.png?w=206&#038;h=44" alt="" width="206" height="44" /></p>
<p>The values of <em>c</em> are determined from the four vertices of corresponding polygon in the distorted image and ideal image. In this activity, I highlighted my region of interest and measured the actual and ideal pixel location of the region of interest. The green-highlighted section is the ideal locations of the grids.</p>
<p>However, the values of  <img class="alignnone size-medium wp-image-177" src="http://incisors.files.wordpress.com/2008/07/c1.png?w=15&#038;h=12" alt="" width="15" height="12" /> and <img class="alignnone size-medium wp-image-178" src="http://incisors.files.wordpress.com/2008/07/c8.png?w=16&#038;h=12" alt="" width="16" height="12" /> are valid in the included polygon.</p>
<p><a href="http://incisors.files.wordpress.com/2008/07/image2.jpg"><img class="aligncenter size-medium wp-image-163" src="http://incisors.files.wordpress.com/2008/07/image2.jpg?w=200&#038;h=267" alt="" width="200" height="267" /></a></p>
<p><a href="http://incisors.files.wordpress.com/2008/07/rotated_2.png"><img class="aligncenter size-medium wp-image-164" src="http://incisors.files.wordpress.com/2008/07/rotated_2.png?w=192&#038;h=254" alt="" width="192" height="254" /></a></p>
<p>My code below was executed from this set of instructions (from Dr Soriano&#8217;s lecture).</p>
<p>1. Obtain image.</p>
<p style="text-align:left;">2. From the most undistorted portion of the image, e.g. at the optical axis of the camera, count the number of pixels down and across one box.</p>
<p style="text-align:left;">3. Generate the ideal grid vertex points (just the coordinates).</p>
<p style="text-align:center;">4. For each rectangle compute c1 to c8 using pairs of equations (x&#8217;s,y&#8217;s) from the four corner points.<br />
<img class="size-medium wp-image-190 aligncenter" src="http://incisors.files.wordpress.com/2008/08/mat2.png?w=212&#038;h=249" alt="" width="212" height="249" /></p>
<p style="text-align:left;">In compact matrix form, we have <img class="alignnone size-medium wp-image-180" src="http://incisors.files.wordpress.com/2008/07/x.png?w=90&#038;h=16" alt="" width="90" height="16" /> and <img class="alignnone size-medium wp-image-187" src="http://incisors.files.wordpress.com/2008/07/y1.png?w=88&#038;h=17" alt="" width="88" height="17" />. We can solve for the c&#8217;s using</p>
<p style="text-align:left;"><img class="alignnone size-medium wp-image-182" src="http://incisors.files.wordpress.com/2008/07/c14.png?w=111&#038;h=22" alt="" width="111" height="22" /> and <img class="alignnone size-medium wp-image-183" src="http://incisors.files.wordpress.com/2008/07/c58.png?w=108&#038;h=23" alt="" width="108" height="23" />.</p>
<p style="text-align:left;">5. Per pixel in the ideal rectangle, determine the location of that point in the distorted image using</p>
<p><img class="aligncenter size-medium wp-image-172" src="http://incisors.files.wordpress.com/2008/07/transformation.png?w=206&#038;h=44" alt="" width="206" height="44" /></p>
<p>6. If the computed distorted location is integer-valued, copy the grayscale value from the distorted image onto the blank pixel. If the location is not integer-valued, compute the interpolated grayscale value using:</p>
<p style="text-align:center;"><img class="size-medium wp-image-184 aligncenter" src="http://incisors.files.wordpress.com/2008/07/v.png?w=215&#038;h=21" alt="" width="215" height="21" /></p>
<p><span style="color:#000000;">im=imread(&#8216;image.jpg&#8217;);</span><br />
<span style="color:#000000;">im=im2gray(im);</span><br />
<span style="color:#000000;">[x,y]=</span><span style="font-weight:bold;font-style:italic;color:#0000ff;">size</span><span style="color:#000000;">(im);</span><br />
<span style="color:#000000;">ideal=</span><span style="font-weight:bold;font-style:italic;color:#0000ff;">zeros</span><span style="color:#000000;">(x,y);</span><br />
<span style="font-weight:bold;color:#000080;">for</span><span style="color:#000000;"> i=</span><span style="color:#0000ff;">1</span><span style="color:#000000;"> : </span><span style="color:#0000ff;">10</span><span style="color:#000000;"> : x</span><br />
<span style="color:#000000;"> ideal(i, <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> =</span><span style="font-weight:bold;font-style:italic;color:#0000ff;">ones</span><span style="color:#000000;">(y);</span><br />
<span style="font-weight:bold;color:#000080;">end</span></p>
<p><span style="font-weight:bold;color:#000080;">for</span><span style="color:#000000;"> j=</span><span style="color:#0000ff;">1</span><span style="color:#000000;">:</span><span style="color:#0000ff;">8</span><span style="color:#000000;">:y</span><br />
<span style="color:#000000;"> ideal(:, j)=</span><span style="font-weight:bold;font-style:italic;color:#0000ff;">ones</span><span style="color:#000000;">(x);</span><br />
<span style="font-weight:bold;color:#000080;">end</span><br />
<span style="color:#000000;">scf(</span><span style="color:#0000ff;">1</span><span style="color:#000000;">);</span><br />
<span style="color:#000000;">imshow(ideal, []);</span><br />
<span style="color:#000000;">blank=[];</span><br />
<span style="color:#000000;">xi=[</span><span style="color:#0000ff;">31</span><span style="color:#000000;">; </span><span style="color:#0000ff;">183</span><span style="color:#000000;">; </span><span style="color:#0000ff;">183</span><span style="color:#000000;">; </span><span style="color:#0000ff;">31</span><span style="color:#000000;">];</span><br />
<span style="color:#000000;">yi=[</span><span style="color:#0000ff;">48</span><span style="color:#000000;">; </span><span style="color:#0000ff;">50</span><span style="color:#000000;">; </span><span style="color:#0000ff;">97</span><span style="color:#000000;">; </span><span style="color:#0000ff;">95</span><span style="color:#000000;">];</span><br />
<span style="color:#000000;">T=[</span><span style="color:#0000ff;">31</span><span style="color:#000000;"> </span><span style="color:#0000ff;">48</span><span style="color:#000000;"> </span><span style="color:#0000ff;">31</span><span style="color:#000000;">*</span><span style="color:#0000ff;">48</span><span style="color:#000000;"> </span><span style="color:#0000ff;">1</span><span style="color:#000000;">; </span><span style="color:#0000ff;">245</span><span style="color:#000000;"> </span><span style="color:#0000ff;">48</span><span style="color:#000000;"> </span><span style="color:#0000ff;">245</span><span style="color:#000000;">*</span><span style="color:#0000ff;">48</span><span style="color:#000000;"> </span><span style="color:#0000ff;">1</span><span style="color:#000000;">; </span><span style="color:#0000ff;">245</span><span style="color:#000000;"> </span><span style="color:#0000ff;">95</span><span style="color:#000000;"> </span><span style="color:#0000ff;">145</span><span style="color:#000000;">*</span><span style="color:#0000ff;">95</span><span style="color:#000000;"> </span><span style="color:#0000ff;">1</span><span style="color:#000000;">; </span><span style="color:#0000ff;">31</span><span style="color:#000000;"> </span><span style="color:#0000ff;">95</span><span style="color:#000000;"> </span><span style="color:#0000ff;">31</span><span style="color:#000000;">*</span><span style="color:#0000ff;">95</span><span style="color:#000000;"> </span><span style="color:#0000ff;">1</span><span style="color:#000000;">];</span><br />
<span style="color:#000000;">c14=</span><span style="font-weight:bold;font-style:italic;color:#0000ff;">inv</span><span style="color:#000000;">(T)*xi;</span><br />
<span style="color:#000000;">c56=</span><span style="font-weight:bold;font-style:italic;color:#0000ff;">inv</span><span style="color:#000000;">(T)*yi;</span><br />
<span style="font-weight:bold;color:#000080;">for</span><span style="color:#000000;"> i=</span><span style="color:#0000ff;">1</span><span style="color:#000000;"> : x</span><br />
<span style="color:#000000;"> </span><span style="font-weight:bold;color:#000080;">for</span><span style="color:#000000;"> j=</span><span style="color:#0000ff;">1</span><span style="color:#000000;">:y</span><br />
<span style="color:#000000;"> x_im=c14(</span><span style="color:#0000ff;">1</span><span style="color:#000000;">)*i+c14(</span><span style="color:#0000ff;">2</span><span style="color:#000000;">)*j+c14(</span><span style="color:#0000ff;">3</span><span style="color:#000000;">)*i*j+c14(</span><span style="color:#0000ff;">4</span><span style="color:#000000;">);</span><br />
<span style="color:#000000;"> y_im=c56(</span><span style="color:#0000ff;">1</span><span style="color:#000000;">)*i+c56(</span><span style="color:#0000ff;">2</span><span style="color:#000000;">)*j+c56(</span><span style="color:#0000ff;">3</span><span style="color:#000000;">)*i*j+c56(</span><span style="color:#0000ff;">4</span><span style="color:#000000;">);</span><br />
<span style="color:#000000;"> </span><span style="font-weight:bold;color:#000080;">if</span><span style="color:#000000;"> x_im&gt;=x </span><br />
<span style="color:#000000;"> x_im=x;</span><br />
<span style="color:#000000;"> </span><span style="font-weight:bold;color:#000080;">end</span><br />
<span style="color:#000000;"> </span><span style="font-weight:bold;color:#000080;">if</span><span style="color:#000000;"> y_im&gt;=y</span><br />
<span style="color:#000000;"> y_im=y;</span><br />
<span style="color:#000000;"> </span><span style="font-weight:bold;color:#000080;">end</span><br />
<span style="color:#000000;"> blank(i, j)=im(</span><span style="font-weight:bold;font-style:italic;color:#0000ff;">round</span><span style="color:#000000;">(x_im), </span><span style="font-weight:bold;font-style:italic;color:#0000ff;">round</span><span style="color:#000000;">(y_im));</span><br />
<span style="color:#000000;"> </span><span style="font-weight:bold;color:#000080;">end</span><br />
<span style="font-weight:bold;color:#000080;">end</span><br />
<span style="color:#000000;">scf(</span><span style="color:#0000ff;">2</span><span style="color:#000000;">);</span><br />
<span style="color:#000000;">imshow(blank, []);</span><br />
<span style="font-style:italic;color:#808080;">//for j=1:10:y</span><br />
<span style="font-style:italic;color:#808080;">//  ideal(:, y)=ones(x);</span><br />
<span style="font-style:italic;color:#808080;">//end </span></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/incisors.wordpress.com/161/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/incisors.wordpress.com/161/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/incisors.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/incisors.wordpress.com/161/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/incisors.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/incisors.wordpress.com/161/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/incisors.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/incisors.wordpress.com/161/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/incisors.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/incisors.wordpress.com/161/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/incisors.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/incisors.wordpress.com/161/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/incisors.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/incisors.wordpress.com/161/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/incisors.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/incisors.wordpress.com/161/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=incisors.wordpress.com&amp;blog=3941311&amp;post=161&amp;subd=incisors&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://incisors.wordpress.com/2008/07/31/activity-12-image-distortion-correction-partial/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7180bfbb1df0d02507e75d02e265e0fa?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">jptugaff</media:title>
		</media:content>

		<media:content url="http://incisors.files.wordpress.com/2008/07/distorted-capiz-window.jpg?w=200" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/08/pixel_correction.png?w=300" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/07/xmap.png?w=89" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/07/ymap.png?w=88" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/07/r.png?w=242" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/07/s.png?w=241" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/07/transformation.png?w=206" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/07/c1.png?w=15" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/07/c8.png?w=16" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/07/image2.jpg?w=200" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/07/rotated_2.png?w=227" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/08/mat2.png?w=212" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/07/x.png?w=90" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/07/y1.png?w=88" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/07/c14.png?w=111" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/07/c58.png?w=108" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/07/transformation.png?w=206" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/07/v.png?w=215" medium="image" />
	</item>
		<item>
		<title>Activity 11: Camera Calibration</title>
		<link>http://incisors.wordpress.com/2008/07/29/activity-11-camera-calibration/</link>
		<comments>http://incisors.wordpress.com/2008/07/29/activity-11-camera-calibration/#comments</comments>
		<pubDate>Tue, 29 Jul 2008 12:41:06 +0000</pubDate>
		<dc:creator>jptugaff</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://incisors.wordpress.com/?p=141</guid>
		<description><![CDATA[In this activity, we calibrate a camera to determine the mapping of each location (3D) on an object to its camera image (2D). This is shown in the figure below from Dr Soriano&#8217;s lecture. After some algebra, we are lead to this equation where the &#8220;o&#8221; subscript refer to the object and the &#8220;i&#8221; subscript [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=incisors.wordpress.com&amp;blog=3941311&amp;post=141&amp;subd=incisors&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In this activity, we calibrate a camera to determine the mapping of each location (3D) on an object to its camera image (2D). This is shown in the figure below from Dr Soriano&#8217;s lecture.</p>
<p><a href="http://incisors.files.wordpress.com/2008/07/iim12.png"><img class="aligncenter size-medium wp-image-155" src="http://incisors.files.wordpress.com/2008/07/iim12.png?w=300&#038;h=215" alt="" width="300" height="215" /></a></p>
<p>After some algebra, we are lead to this equation where the &#8220;o&#8221; subscript refer to the object and the &#8220;i&#8221; subscript refer to the image. As can be seen, the there are only two equation for the mapping since the image is flat.</p>
<p><a href="http://incisors.files.wordpress.com/2008/07/eq1.png"><img class="aligncenter size-medium wp-image-146" src="http://incisors.files.wordpress.com/2008/07/eq1.png?w=495" alt="" /></a></p>
<p>In matrix form, the above equation is written as</p>
<p><a href="http://incisors.files.wordpress.com/2008/07/mat1.png"><img class="aligncenter size-medium wp-image-158" src="http://incisors.files.wordpress.com/2008/07/mat1.png?w=300&#038;h=155" alt="" width="300" height="155" /></a></p>
<p style="text-align:center;">
<p style="text-align:left;">However, this is for a single image, and we have to append the Q and d matrix as we increase the number of points that will be used to determine the mapping. In compact matrix form, we have<a href="http://incisors.files.wordpress.com/2008/07/eq2.png"><img class="size-medium wp-image-149 aligncenter" src="http://incisors.files.wordpress.com/2008/07/eq2.png?w=495" alt="" /></a></p>
<p style="text-align:left;">We can solve for the transformation matrix <strong><em>a </em></strong>using some matrix algebra which results to<img class="aligncenter size-medium wp-image-151" src="http://incisors.files.wordpress.com/2008/07/eq31.png?w=495" alt="" /></p>
<p style="text-align:left;">The image that we have obtained by taking a picture of the checker board is shown below. The location of the points used in determining the mapping is shown in my program.</p>
<p style="text-align:left;"><a href="http://incisors.files.wordpress.com/2008/07/image.jpg"><img class="aligncenter size-medium wp-image-144" src="http://incisors.files.wordpress.com/2008/07/image.jpg?w=250&#038;h=237" alt="" width="250" height="237" /></a></p>
<p>x=[0 0 0 0 1 1 2 0 1 0 3 1 0 3 0 2 0 0 0 1 ];<br />
y=[0 1 0 3 0 0 0 1 0 5 0 0 2 0 2 0 5 3 0 0 ];<br />
z=[0 12  3 2 1 2 5 8 1 3 8 9 6 10 7 7 9 10 9];<br />
yi=[127 139 126 164 115 115 102 139 113 191 90 114 152 88 152 101 193 166 125 112];<br />
zi=[200 187 169 161 172 189 175 123 73  200  161 73 57 112 40 91 97 58 138 56];<br />
obj=[];<br />
im=[];<br />
for i=0:length(x)-1<br />
obj(2*i+1, <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> =[x(i+1) y(i+1) z(i+1) 1 0 0 0 0 -yi(i+1).*x(i+1) -yi(i+1).*y(i+1) -yi(i+1).*z(i+1)];<br />
obj(2*i+2, <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> =[0 0 0 0 x(i+1) y(i+1) z(i+1) 1 -zi(i+1).*x(i+1) -zi(i+1).*y(i+1) -zi(i+1).*z(i+1)];<br />
im(2*i+1)=yi(i+1);<br />
im(2*i+2)=zi(i+1);<br />
end<br />
a=inv(obj&#8217;*obj)*obj&#8217;*im;<br />
a(12)=1.0;<br />
a=matrix(a, 4, 3)&#8217;;<br />
testx=1;<br />
testy=0;<br />
testz=2;<br />
ty=(a(1,1)*testx+a(1,2)*testy+a(1,3)*testz+a(1,4))/(a(3,1)*testx+a(3,2)*testy+a(3,3)*testz+a(3,4));<br />
tz=(a(2,1)*testx+a(2,2)*testy+a(2,3)*testz+a(2,4))/(a(3,1)*testx+a(3,2)*testy+a(3,3)*testz+a(3,4));<br />
ty<br />
tz</p>
<p>We&#8217;ve verified that this works with error of a few pixels. As of the moment, more accurate methods of getting the points is needed for a more accurate calibration. In our data, the actual pixel values of (1,0,2) are (114, 172) while the value from the calibration is (122, 177). A possible source of error, other than inaccuracy in getting the pixel values is radial distortion (as was mentioned by Dr Soriano). Another source of error is the high resolution of the image which causes error in choosing which pixel is the corner of the board.</p>
<p>I give my self 9.5/10 because of some inaccuracies encountered. Although i am satisfied enough with the result.</p>
<p>Tnx to Julie for the help with the image. <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/incisors.wordpress.com/141/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/incisors.wordpress.com/141/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/incisors.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/incisors.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/incisors.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/incisors.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/incisors.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/incisors.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/incisors.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/incisors.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/incisors.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/incisors.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/incisors.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/incisors.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/incisors.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/incisors.wordpress.com/141/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=incisors.wordpress.com&amp;blog=3941311&amp;post=141&amp;subd=incisors&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://incisors.wordpress.com/2008/07/29/activity-11-camera-calibration/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7180bfbb1df0d02507e75d02e265e0fa?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">jptugaff</media:title>
		</media:content>

		<media:content url="http://incisors.files.wordpress.com/2008/07/iim12.png?w=300" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/07/eq1.png" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/07/mat1.png?w=300" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/07/eq2.png" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/07/eq31.png" medium="image" />

		<media:content url="http://incisors.files.wordpress.com/2008/07/image.jpg?w=250" medium="image" />
	</item>
	</channel>
</rss>
