<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-223420158170109027</id><updated>2011-07-07T13:12:45.361-07:00</updated><title type='text'>Cole's AP186</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://cole-ap186.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/223420158170109027/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://cole-ap186.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Cole</name><uri>http://www.blogger.com/profile/17840780106218077983</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://2.bp.blogspot.com/_6ZpN6X5LZPw/SeFgyvHYwpI/AAAAAAAAAmc/H76Ym0zH_Mw/S220/fabros05+-+Copy.JPG'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>20</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-223420158170109027.post-4944528430843889749</id><published>2008-09-26T15:55:00.000-07:00</published><updated>2008-09-27T03:23:39.018-07:00</updated><title type='text'>Activity 20: Neural Networks</title><content type='html'>&lt;div style="text-align: justify;"&gt;In this activity, we use neural networks as another method to classify our objects into groups depending on the values of the extracted features. Similar to activity 19, we use 2 classes: &lt;span style="color: rgb(255, 204, 0);"&gt;kwekkwek and pillows&lt;/span&gt;. However, only 2 features are used to differentiate the 2 groups for simplicity. These are the length to height ratio and the red component of color.&lt;br /&gt;&lt;br /&gt;A neural network is a computational model of how neurons in the brain work. It is a preferred alternative to linear discriminant analysis in the pattern recognition because one does not need heuristics and recognition rules to perform classification. Instead neural networks “learn” the rules of a mapping by example. Although it may take a long time for a network to train, its recognition processing speed is faster once it has learned.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;source: &lt;span style="color: rgb(255, 204, 0);"&gt;M. Soriano, &lt;span style="font-style: italic;"&gt;A20 - Neural Networks.pdf&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;____________________________________________________________________&lt;br /&gt;&lt;br /&gt;A code was already prepared by J. Tugaff and it only needs to be modified depending on the  number and values of the input features. For our purposes, we have:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 153, 153);font-size:130%;" &gt;2 input features&lt;br /&gt;4 training objects from each class (kwekkwek and pillows)&lt;br /&gt;4 test objects from each class&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;We first train our neural network using the training set.&lt;br /&gt;&lt;br /&gt;Length/Height, Red component --(&lt;span style="color: rgb(255, 204, 0);"&gt;kwek kwek&lt;/span&gt;; &lt;span style="color: rgb(102, 51, 0);"&gt;pillows&lt;/span&gt;)&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;0.97, 0.74&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;1.00, 0.77&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;0.96, 0.73&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;0.91, 0.74&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 51, 0);"&gt;0.96, 0.30&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 51, 0);"&gt;1.00, 0.30&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 51, 0);"&gt;1.02, 0.33&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 51, 0);"&gt;1.02, 0.33&lt;/span&gt;&lt;br /&gt;____________________________________________________________________&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//original code c/o Jeric Tugaff&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//ensure the same starting point each time&lt;/span&gt;&lt;br /&gt;rand('seed',0);&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//network def.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//neurons per layer, including input&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//2 neurons in the input layer, 2 in the hidden layer and 1 in the output layer&lt;/span&gt;&lt;br /&gt;N  = [2,2,1];&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//inputs, 1st column = length/height, 2nd column = red component&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//training set&lt;/span&gt;&lt;br /&gt;x = [0.97, 0.74;&lt;br /&gt;  1.00, 0.77;&lt;br /&gt;  0.96, 0.73;&lt;br /&gt;  0.91, 0.74;&lt;br /&gt;  0.96, 0.30;&lt;br /&gt;  1.00, 0.30;&lt;br /&gt;  1.02, 0.33;&lt;br /&gt;  1.02, 0.33]';&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//targets, 0 if kwekkwek and 1 if pillows&lt;/span&gt;&lt;br /&gt;t = [0 0 0 0 1 1 1 1];&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//learning rate is 0.1 and 0 is the threshold for the error tolerated by the network&lt;/span&gt;&lt;br /&gt;lp = [0.1,0];&lt;br /&gt;&lt;br /&gt;W = ann_FF_init(N);&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//training cycles&lt;/span&gt;&lt;br /&gt;T = 1000;&lt;br /&gt;W = ann_FF_Std_online(x,t,N,W,lp,T);&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//x is the training, t is the output, W is the initialized weights, &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//N is the NN architecture, lp is the learning rate and T is the number of iterations&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//full run&lt;/span&gt;&lt;br /&gt;ann_FF_run(x,N,W)&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//the network N was tested using x as the test set, and W as the weights of the connections&lt;/span&gt;&lt;br /&gt;____________________________________________________________________&lt;br /&gt;&lt;br /&gt;We expect that this code will output values close to (0, 0, 0, 0, 1, 1, 1, 1), meaning that the first 4 objects will be classified as members of the 'kwekkwek' class while the last 4 objects will be classified as members of the 'pillows' class. &lt;span style="color: rgb(255, 204, 0);"&gt;The actual results are (0.1448030, 0.1291128, 0.1506565, 0.1342528, 0.8876302, 0.8956291, 0.8738883, 0.8738883)&lt;/span&gt;. We can now say that our neural network has "learned" the features of each class and has sorted the objects into the correct groups. We now use the test set to see whether the network can classify the other objects accurately as well.&lt;br /&gt;&lt;br /&gt;Length/Height, Red component --(&lt;span style="color: rgb(255, 204, 0);"&gt;kwek kwek&lt;/span&gt;; &lt;span style="color: rgb(102, 51, 0);"&gt;pillows&lt;/span&gt;)&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;0.67, 0.77&lt;br /&gt;0.81, 0.79&lt;br /&gt;1.08, 0.78&lt;br /&gt;1.00, 0.81&lt;br /&gt;&lt;span style="color: rgb(102, 51, 0);"&gt;1.09, 0.35&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 51, 0);"&gt;1.12, 0.35&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 51, 0);"&gt;1.05, 0.35&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 51, 0);"&gt;0.94, 0.32&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;Using the training parameters, the resulting values are (0.0900170, 0.0954682, 0.1355222, 0.1071037, 0.8711712, 0.8782258, 0.8610966, 0.8642343). A &lt;span style="color: rgb(255, 204, 0);"&gt;100% correct&lt;/span&gt; classification was achieved. Next, we try to tweak the parameters (&lt;span style="color: rgb(255, 204, 0);"&gt;learning rate and training cycles&lt;/span&gt;) to see whether the values will go closer to 0 and 1 or whether the clasification will still remain 100% correct.&lt;br /&gt;&lt;br /&gt;learning rate = from 0.1 &lt;span style="color: rgb(255, 204, 0);"&gt;--&gt;&lt;/span&gt; change to 1.0&lt;br /&gt;training cycles = from 1000 &lt;span style="color: rgb(255, 204, 0);"&gt;--&gt;&lt;/span&gt; change to 400&lt;br /&gt;result: (&lt;span style="color: rgb(255, 204, 0);"&gt;0.0201587, 0.0220962, 0.0384002, 0.0265042, 0.9631881, 0.9668789, 0.9575001, 0.9582095&lt;/span&gt;)&lt;br /&gt;&lt;br /&gt;The values are closer to 0 and 1 using the new training parameters and the classification is still 100% correct. Now, let us try to change the order of the test set to make sure that the 100% correct classification does not depend on the order.&lt;br /&gt;&lt;br /&gt;Length/Height, Red component --(&lt;span style="color: rgb(255, 204, 0);"&gt;kwek kwek&lt;/span&gt;; &lt;span style="color: rgb(102, 51, 0);"&gt;pillows&lt;/span&gt;)&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;0.67, 0.77&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 51, 0);"&gt;1.05, 0.35&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;1.08, 0.78&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 51, 0);"&gt;1.09, 0.35&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;0.81, 0.79&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 51, 0);"&gt;1.12, 0.35&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 51, 0);"&gt;0.94, 0.32&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;1.00, 0.81&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;learning rate = 1.0&lt;br /&gt;training cycles = 400&lt;br /&gt;result: (&lt;span style="color: rgb(255, 204, 0);"&gt;0.0201587, &lt;/span&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;0.9575001, &lt;/span&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;0.0384002, &lt;/span&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;0.9631881, &lt;/span&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;0.0220962, &lt;/span&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;0.9668789&lt;/span&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;0.9582095, &lt;/span&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;0.0265042&lt;/span&gt;)&lt;br /&gt;&lt;br /&gt;The classification is still 100% correct and we have shown that the order of the objects in the input matrix is not important.&lt;br /&gt;____________________________________________________________________&lt;br /&gt;&lt;br /&gt;I give myself &lt;span style="color: rgb(255, 204, 0);"&gt;10 points&lt;/span&gt; for this activity because of the &lt;span style="color: rgb(255, 204, 0);"&gt;100% correct classification &lt;/span&gt;of the objects into their respective classes. Thanks to &lt;span style="color: rgb(255, 204, 0);"&gt;Jeric Tugaff&lt;/span&gt; for the ANN toolbox and the code and &lt;span style="color: rgb(255, 204, 0);"&gt;Mark Leo Bejemino&lt;/span&gt; for helping me to apply the code to my objects and extracted features.&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/223420158170109027-4944528430843889749?l=cole-ap186.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cole-ap186.blogspot.com/feeds/4944528430843889749/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=223420158170109027&amp;postID=4944528430843889749' title='38 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/223420158170109027/posts/default/4944528430843889749'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/223420158170109027/posts/default/4944528430843889749'/><link rel='alternate' type='text/html' href='http://cole-ap186.blogspot.com/2008/09/activity-20-neural-networks.html' title='Activity 20: Neural Networks'/><author><name>Cole</name><uri>http://www.blogger.com/profile/17840780106218077983</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://2.bp.blogspot.com/_6ZpN6X5LZPw/SeFgyvHYwpI/AAAAAAAAAmc/H76Ym0zH_Mw/S220/fabros05+-+Copy.JPG'/></author><thr:total>38</thr:total></entry><entry><id>tag:blogger.com,1999:blog-223420158170109027.post-1116174489268079360</id><published>2008-09-18T11:13:00.000-07:00</published><updated>2008-09-18T01:11:29.044-07:00</updated><title type='text'>Activity 19: Probabilistic Classification</title><content type='html'>&lt;div style="text-align: justify;"&gt;In this activity, we apply a different method to classify objects into groups. In the previous activity, mean distance classification was used. Here, we employ probabilistic classification via &lt;span style="color: rgb(255, 204, 0);"&gt;Linear Discriminant Analysis (LDA)&lt;/span&gt;. A detailed discussion on the method and equations used can be viewed from &lt;span style="color: rgb(255, 204, 0);"&gt;Pattern_Recognition_2.pdf by Dr. S. Marcos&lt;/span&gt;. We use two classes of objects from the previous activity and see whether this method classifies them correctly or not.&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;Kwekkwek and Pillows&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SNG2Fhu1-aI/AAAAAAAAAlo/KwNPl4j9l3U/s1600-h/kwekkwek.JPG"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 275px; height: 205px;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SNG2Fhu1-aI/AAAAAAAAAlo/KwNPl4j9l3U/s400/kwekkwek.JPG" alt="" id="BLOGGER_PHOTO_ID_5247175246933784994" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SNGwiZ8hdlI/AAAAAAAAAlY/tLKBo7lirWs/s1600-h/pillows.JPG"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 275px; height: 206px;" src="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SNGwiZ8hdlI/AAAAAAAAAlY/tLKBo7lirWs/s400/pillows.JPG" alt="" id="BLOGGER_PHOTO_ID_5247169145990116946" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Also shown below are the values for length/height, R, G, B for each object.&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SNG2Q0HMllI/AAAAAAAAAlw/pTGA4BEhTgU/s1600-h/Untitled.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SNG2Q0HMllI/AAAAAAAAAlw/pTGA4BEhTgU/s400/Untitled.jpg" alt="" id="BLOGGER_PHOTO_ID_5247175440846329426" border="0" /&gt;&lt;/a&gt;Again, we separate the 8 objects per class into a test set and a training set. The training set is given below. From here the method is implemented and the code and results are also shown below.&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SNG4yreit_I/AAAAAAAAAl4/-SFOy_qIdxI/s1600-h/untitled1.JPG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SNG4yreit_I/AAAAAAAAAl4/-SFOy_qIdxI/s400/untitled1.JPG" alt="" id="BLOGGER_PHOTO_ID_5247178221667137522" border="0" /&gt;&lt;/a&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//act 19 code&lt;br /&gt;//this code just follows the procedure described in Pattern_Recognition_2.pdf&lt;br /&gt;&lt;/span&gt;x = [0.97 0.74 0.37 0.03;&lt;br /&gt;1.00 0.77 0.42 0.03;&lt;br /&gt;0.96 0.73 0.38 0.03;&lt;br /&gt;0.91 0.74 0.38 0.06;&lt;br /&gt;0.96 0.30 0.16 0.07;&lt;br /&gt;1.00 0.30 0.16 0.07;&lt;br /&gt;1.02 0.33 0.18 0.08;&lt;br /&gt;1.02 0.33 0.19 0.09];&lt;br /&gt;&lt;br /&gt;y = [1 1 1 1 2 2 2 2]';&lt;br /&gt;g = 2;&lt;br /&gt;x1 = x(1:4,:);&lt;br /&gt;x2 = x(5:8,:);&lt;br /&gt;&lt;br /&gt;u1 = [mean(x1(:,1)) mean(x1(:,2)) mean(x1(:,3)) mean(x1(:,4))];&lt;br /&gt;u2 = [mean(x2(:,1)) mean(x2(:,2)) mean(x2(:,3)) mean(x2(:,4))];&lt;br /&gt;u = [mean(x(:,1)) mean(x(:,2)) mean(x(:,3)) mean(x(:,4))];&lt;br /&gt;&lt;br /&gt;x1_o = [x1(1,:)-u; x1(2,:)-u; x1(3,:)-u; x1(4,:)-u];&lt;br /&gt;x2_o = [x2(1,:)-u; x2(2,:)-u; x2(3,:)-u; x2(4,:)-u];&lt;br /&gt;&lt;br /&gt;n1 = 4; n2 = n1;&lt;br /&gt;c1 = (x1_o'*x1_o)/n1;&lt;br /&gt;c2 = (x2_o'*x2_o)/n2;&lt;br /&gt;&lt;br /&gt;for r = 1:4&lt;br /&gt;for s = 1:4&lt;br /&gt;C(r,s) = (4/8)*(c1(r,s)+c2(r,s));&lt;br /&gt;end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;Cinv = inv(C);&lt;br /&gt;p = [4/8; 4/8];&lt;br /&gt;&lt;br /&gt;for k = 1:8&lt;br /&gt;f1(k) = u1*Cinv*x(k,:)' - 0.5*u1*Cinv*u1' + log(p(1));&lt;br /&gt;f2(k) = u2*Cinv*x(k,:)' - 0.5*u2*Cinv*u2' + log(p(2));&lt;br /&gt;end&lt;br /&gt;____________________________________________________________________&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);font-size:130%;" &gt;RESULTS:&lt;/span&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SNIEnjaE1uI/AAAAAAAAAmA/dkTGJRDPYTE/s1600-h/Untitled2.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SNIEnjaE1uI/AAAAAAAAAmA/dkTGJRDPYTE/s400/Untitled2.jpg" alt="" id="BLOGGER_PHOTO_ID_5247261593406068450" border="0" /&gt;&lt;/a&gt;From the table above, we can see that this method resulted in a &lt;span style="color: rgb(255, 204, 0);"&gt;100% correct&lt;/span&gt; classification for the training set. The &lt;span style="color: rgb(255, 204, 0);"&gt;higher value of f&lt;/span&gt; will determine which group the object is classified under. We implement this on the test set and see what happens.&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SNILZCPc-pI/AAAAAAAAAmI/J5WO1_3AUOo/s1600-h/Untitled1.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SNILZCPc-pI/AAAAAAAAAmI/J5WO1_3AUOo/s400/Untitled1.jpg" alt="" id="BLOGGER_PHOTO_ID_5247269040566368914" border="0" /&gt;&lt;/a&gt;Again, a &lt;span style="color: rgb(255, 204, 0);"&gt;100% correct&lt;/span&gt; classification is obtained. We have illustrated the success of this method in classifying objects into groups.&lt;br /&gt;____________________________________________________________________&lt;br /&gt;&lt;br /&gt;I give myself &lt;span style="color: rgb(255, 204, 0);"&gt;10 points&lt;/span&gt; for this activity since the method was implemented correctly and there is &lt;span style="color: rgb(255, 204, 0);"&gt;0% error&lt;/span&gt;.&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/223420158170109027-1116174489268079360?l=cole-ap186.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cole-ap186.blogspot.com/feeds/1116174489268079360/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=223420158170109027&amp;postID=1116174489268079360' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/223420158170109027/posts/default/1116174489268079360'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/223420158170109027/posts/default/1116174489268079360'/><link rel='alternate' type='text/html' href='http://cole-ap186.blogspot.com/2008/09/activity-19-probabilistic.html' title='Activity 19: Probabilistic Classification'/><author><name>Cole</name><uri>http://www.blogger.com/profile/17840780106218077983</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://2.bp.blogspot.com/_6ZpN6X5LZPw/SeFgyvHYwpI/AAAAAAAAAmc/H76Ym0zH_Mw/S220/fabros05+-+Copy.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_6ZpN6X5LZPw/SNG2Fhu1-aI/AAAAAAAAAlo/KwNPl4j9l3U/s72-c/kwekkwek.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-223420158170109027.post-7320684860443683236</id><published>2008-09-16T23:25:00.000-07:00</published><updated>2008-09-17T18:04:04.458-07:00</updated><title type='text'>Activity 18: Pattern Recognition</title><content type='html'>&lt;div style="text-align: justify;"&gt;In this activity, we try to test if a random object can be classified using pattern recognition. First, we obtain 8-10 pieces each of similar objects like leaves, fishballs, potato chips, etc. One category of objects is called a class. We assemble &lt;span style="color: rgb(255, 204, 0);"&gt;8-10 objects&lt;/span&gt; that can be classified into &lt;span style="color: rgb(255, 204, 0);"&gt;2-5 classes&lt;/span&gt;. Half of this will be used as a test set and the other as training set. In this case, I have assembled 8 pieces each of:&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;1. &lt;/span&gt;pillows (a chocolate-coated snack)&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;2.&lt;/span&gt; piatos potato chips&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;3.&lt;/span&gt; squidballs&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;4.&lt;/span&gt; kwek kwek (orange, flour-coated quail egg)&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SNGZbMgaBEI/AAAAAAAAAlA/hRXaCrSU52Q/s1600-h/pillows.JPG"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 224px; height: 169px;" src="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SNGZbMgaBEI/AAAAAAAAAlA/hRXaCrSU52Q/s400/pillows.JPG" alt="" id="BLOGGER_PHOTO_ID_5247143733356004418" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SNGZa-WVYII/AAAAAAAAAk4/cFVjgu4Bbzo/s1600-h/piatos.JPG"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 225px; height: 170px;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SNGZa-WVYII/AAAAAAAAAk4/cFVjgu4Bbzo/s400/piatos.JPG" alt="" id="BLOGGER_PHOTO_ID_5247143729555660930" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SNGZbJW632I/AAAAAAAAAlI/GFWEz62Xk7Y/s1600-h/squidballs.JPG"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 224px; height: 168px;" src="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SNGZbJW632I/AAAAAAAAAlI/GFWEz62Xk7Y/s400/squidballs.JPG" alt="" id="BLOGGER_PHOTO_ID_5247143732510908258" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SNGZa7DgNOI/AAAAAAAAAkw/KZvpwbJqvto/s1600-h/kwekkwek.JPG"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 223px; height: 168px;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SNGZa7DgNOI/AAAAAAAAAkw/KZvpwbJqvto/s400/kwekkwek.JPG" alt="" id="BLOGGER_PHOTO_ID_5247143728671372514" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;We extract certain features of these objects such as size, shape, and color and arrange these numbers into an organized set called a &lt;span style="color: rgb(255, 204, 0);"&gt;feature vector&lt;/span&gt;. For each individual object, the feature vector that I will use will have four dimensions namely:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;1.&lt;/span&gt; ratio of length to height of object (x-axis/y-axis)&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;2. &lt;/span&gt;red component of color&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;3. &lt;/span&gt;green component of color&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;4. &lt;/span&gt;blue component of color&lt;br /&gt;&lt;br /&gt;After finding these values for our 32 objects in total, we tabulate them in order to try to visualize clustering in 4-D feature space. We expect clustering to happen if objects are similar to each other. Thus, piatos chips should be clustered together with other piatos chips since they are similar in both size and color.&lt;br /&gt;&lt;br /&gt;To calculate for the size, I employed the following algorithm. Assuming that the each object under one class is depicted in one image, we open it in Scilab, convert to grayscale, look at its histogram to find the proper threshold value in order to convert it to B&amp;amp;W. After that, we do morphological operations to clean the image (close holes and connect/remove stray pixels). Then we use the follow function to measure the contour of the object, get the maximum and minimum values in the x and y axes, and find their ratio. To calculate for the color, we need to first separate the region of interest from the background. Once that is finished, we get the mean for each color channel. These numbers constitute our feature vector for each object. There are 8 objects each for 4 classes used so there are 32 feature vectors.&lt;br /&gt;____________________________________________________________________&lt;br /&gt;Shown below are the values for the feature vectors. For each class, half will be used as a test set and the other half as a training set.&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SNBl9tIcXzI/AAAAAAAAAkg/M0mZ0prZ8PM/s1600-h/Untitled.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 561px; height: 306px;" src="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SNBl9tIcXzI/AAAAAAAAAkg/M0mZ0prZ8PM/s400/Untitled.jpg" alt="" id="BLOGGER_PHOTO_ID_5246805676648062770" border="0" /&gt;&lt;/a&gt;____________________________________________________________________&lt;br /&gt;&lt;br /&gt;If we have any other random object, we can say whether it belongs to the class of squidballs or pillows through a method called minimum distance classification.&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SM715HBjaNI/AAAAAAAAAkY/DtsHRoKBCX4/s1600-h/Untitled.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 523px; height: 348px;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SM715HBjaNI/AAAAAAAAAkY/DtsHRoKBCX4/s400/Untitled.jpg" alt="" id="BLOGGER_PHOTO_ID_5246400977420118226" border="0" /&gt;&lt;/a&gt;&lt;span style="font-size:85%;"&gt;source: &lt;span style="color: rgb(255, 204, 0);"&gt;M. Soriano, &lt;/span&gt;&lt;span style="font-style: italic; color: rgb(255, 204, 0);"&gt;A18- Pattern Recognition.pdf&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;We use the training feature vectors to find the class representatives &lt;span style="font-weight: bold;"&gt;m&lt;/span&gt;j. Then, we classify the test feature vectors using this method.&lt;br /&gt;____________________________________________________________________&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);font-size:130%;" &gt;class representatives or mean feature vector, &lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(255, 204, 0);font-size:130%;" &gt;m&lt;/span&gt;&lt;span style="color: rgb(255, 204, 0);font-size:130%;" &gt;j:&lt;/span&gt;&lt;br /&gt;1. kwek kwek - [0.96, 0.75, 0.39, 0.04]&lt;br /&gt;2. squidballs - [1.03, 0.55, 0.35, 0.09]&lt;br /&gt;3. pillows - [1.00, 0.32, 0.17, 0.08]&lt;br /&gt;4. piatos - [1.35, 0.59, 0.45, 0.16]&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SNCUMleHTjI/AAAAAAAAAko/v8eMwNIG3Zo/s1600-h/Untitled1.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 566px; height: 283px;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SNCUMleHTjI/AAAAAAAAAko/v8eMwNIG3Zo/s400/Untitled1.jpg" alt="" id="BLOGGER_PHOTO_ID_5246856509824388658" border="0" /&gt;&lt;/a&gt;From this table it can be seen that &lt;span style="color: rgb(255, 204, 0);"&gt;only 2 out of the 16 objects were classified incorrectly&lt;/span&gt;. Thus, the success rate of this method is &lt;span style="color: rgb(255, 204, 0);"&gt;87.5%&lt;/span&gt;. Errors may have come from the calculation of the length to height ratio because the images might not have been thresholded and/or morphologically enhanced correctly.&lt;br /&gt;____________________________________________________________________&lt;br /&gt;&lt;br /&gt;I give myself &lt;span style="color: rgb(255, 204, 0);"&gt;10 points&lt;/span&gt; for this activity since the method was implemented resulting in  only a few errors. The success rate of this method in pattern recognition was found to be &lt;span style="color: rgb(255, 204, 0);"&gt;87.5%&lt;/span&gt;, which is a fairly acceptable number. Thanks to &lt;span style="color: rgb(255, 204, 0);"&gt;JC Nadora, Benj Palmares, Raf Jaculbia, Mer Camba, Ed David, Billy Narag, and Jorge Presto&lt;/span&gt; for buying the objects/food tested (kwek kwek, squidballs, piatos, pillows).&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/223420158170109027-7320684860443683236?l=cole-ap186.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cole-ap186.blogspot.com/feeds/7320684860443683236/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=223420158170109027&amp;postID=7320684860443683236' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/223420158170109027/posts/default/7320684860443683236'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/223420158170109027/posts/default/7320684860443683236'/><link rel='alternate' type='text/html' href='http://cole-ap186.blogspot.com/2008/09/activity-18-pattern-recognition.html' title='Activity 18: Pattern Recognition'/><author><name>Cole</name><uri>http://www.blogger.com/profile/17840780106218077983</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://2.bp.blogspot.com/_6ZpN6X5LZPw/SeFgyvHYwpI/AAAAAAAAAmc/H76Ym0zH_Mw/S220/fabros05+-+Copy.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_6ZpN6X5LZPw/SNGZbMgaBEI/AAAAAAAAAlA/hRXaCrSU52Q/s72-c/pillows.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-223420158170109027.post-2367062873984412938</id><published>2008-09-09T11:00:00.000-07:00</published><updated>2008-10-08T19:32:08.215-07:00</updated><title type='text'>Activity 17: Basic Video Processing</title><content type='html'>&lt;div style="text-align: justify;"&gt;Video, whether analog or digital, is a string of still images shown in rapid succession such that an impression of movement is perceived by an observer. Therefore, all image processing techniques we've learned so far may be applied on image frames of a video. The advantage of video is that it allows us access to another physical dimension, time. Thus, the dynamics and kinematics of a system can be extracted from video.&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;In this activity, we aim to extract some kinematic constants and variables like gravitational constant, position, and velocity upon taking a video of an event like dropping a ball or watching a spring reach equilibrium when initially stretched. These extracted variables will be plotted against time and the kinematic constants will be calculated. The results will be compared against analytical values.&lt;br /&gt;&lt;br /&gt;In order to do this with Scilab, we need to install a video processing toolbox. However, the SIVP toolbox cannot read more than two frames from an avi video so we have to use other software to achieve our goal. These are &lt;span style="color: rgb(255, 204, 0);"&gt;Windows Movie Maker&lt;/span&gt; - for capturing the video and saving it directly on the PC, &lt;span style="color: rgb(255, 204, 0);"&gt;Stoik Video Converter&lt;/span&gt; - for converting the .wmv file generated by Movie Maker into an .avi file, and &lt;span style="color: rgb(255, 204, 0);"&gt;Virtual Dub&lt;/span&gt; - to parse the .avi file into image sequences in either .jpg or .bmp formats. Once stored as individual images, the position, shape or area can be extracted using image processing techniques. We loop through the image sequence to get the time variation of the variables of interest.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;source: &lt;span style="color: rgb(255, 204, 0);"&gt;M. Soriano, &lt;/span&gt;&lt;span style="color: rgb(255, 204, 0); font-style: italic;"&gt;A17 - Basic Video Processing.pdf&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;The kinematic event that I used was &lt;span style="color: rgb(255, 204, 0);"&gt;using a steel ruler as a physical pendulum&lt;/span&gt;. From this, I can calculate for some quantities like the center of oscillation, its position after some time, the period of oscillation, etc.&lt;br /&gt;____________________________________________________________________&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 153, 153);font-size:130%;" &gt;Physical Pendulum&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);font-size:78%;" &gt;http://en.wikipedia.org/wiki/Pendulum#Physical_pendulum&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The simple pendulum assumes that the rod is massless and that the bob is small, so has negligible angular momentum in itself. A physical pendulum has significant size and mass, and hence a significant &lt;a href="http://en.wikipedia.org/wiki/Moment_of_inertia" title="Moment of inertia"&gt;&lt;/a&gt;moment of inertia. &lt;p&gt;A physical pendulum behaves like a simple pendulum but the expression for the period is modified.&lt;/p&gt; &lt;dl&gt;&lt;dd&gt;&lt;img class="tex" alt="T = 2 \pi \sqrt{\frac{I} {mgL}}" src="http://upload.wikimedia.org/math/b/5/e/b5e3838d81a413536ae167267d05d08c.png" /&gt;&lt;/dd&gt;&lt;/dl&gt; &lt;p&gt;where:&lt;/p&gt; &lt;dl&gt;&lt;dd&gt;&lt;span class="texhtml"&gt;&lt;i&gt;I&lt;/i&gt;&lt;/span&gt; is the &lt;span style="color: rgb(255, 204, 0);"&gt;moment of inertia&lt;/span&gt; of the pendulum about the pivot point&lt;/dd&gt;&lt;dd&gt;&lt;span class="texhtml"&gt;&lt;i&gt;L&lt;/i&gt;&lt;/span&gt; is the &lt;span style="color: rgb(255, 204, 0);"&gt;distance from the center of mass to the pivot point&lt;/span&gt;&lt;/dd&gt;&lt;dd&gt;&lt;span class="texhtml"&gt;&lt;i&gt;m&lt;/i&gt;&lt;/span&gt; is the &lt;span style="color: rgb(255, 204, 0);"&gt;mass&lt;/span&gt; of the pendulum&lt;/dd&gt;&lt;/dl&gt; &lt;p&gt;For a physical pendulum, since this has the same form as the simple pendulum, it is possible to define the &lt;span style="color: rgb(255, 204, 0);"&gt;center of oscillation&lt;/span&gt;. This is the distance from the pivot point, at which, if all the mass of the pendulum was concentrated (and thus forming a simple pendulum), would give the pendulum the same period.&lt;/p&gt; &lt;dl&gt;&lt;dd&gt;&lt;img class="tex" alt="\ell=\frac{I}{mL}" src="http://upload.wikimedia.org/math/5/1/7/517f3368dd5073345c932e798dc60d71.png" /&gt;&lt;/dd&gt;&lt;/dl&gt;The moment of inertia in this case is given by&lt;br /&gt;&lt;br /&gt;&lt;img class="tex" alt="I_e = \frac {m(h^2)}{3}+\frac {m(w^2)}{12}" src="http://upload.wikimedia.org/math/5/b/7/5b78b38aef1c0a83fa6b03873fb48d90.png" /&gt;&lt;br /&gt;&lt;br /&gt;with height &lt;i&gt;h&lt;/i&gt;, width &lt;i&gt;w&lt;/i&gt;, and mass &lt;i&gt;m&lt;/i&gt;&lt;span style="font-style: italic;"&gt; &lt;/span&gt;(Axis of rotation at the end of the plate)&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);font-size:78%;" &gt;http://en.wikipedia.org/wiki/List_of_moments_of_inertia&lt;/span&gt;&lt;br /&gt;____________________________________________________________________&lt;br /&gt;&lt;br /&gt;Before calculating the desired quantities, we first need to process our images. This activity utilizes most of the techniques we have learned so far. Step by step, these are:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;1.&lt;/span&gt; Separate the video per frame using other software.&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;2.&lt;/span&gt; White balance the images.&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;3.&lt;/span&gt; Normalize the color.&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;4.&lt;/span&gt; Do color segmentation on the object (in our case, the ruler that acted as a physical pendulum).&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;5.&lt;/span&gt; Convert to a B&amp;amp;W image with the proper threshold value.&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;6.&lt;/span&gt; Do morphological operations to close holes and enhance the image.&lt;br /&gt;&lt;br /&gt;After these, we can calculate for the centroid proceed in solving for the desired quantities numerically.&lt;br /&gt;____________________________________________________________________&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 153, 153);font-size:130%;" &gt;RESULTS&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;ORIGINAL, WHITE BALANCED, NORMALIZED, SEGMENTED, B&amp;amp;W, MORPHED IMAGES&lt;/span&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SMckWO8A_ZI/AAAAAAAAAi4/5bslLnGGwWU/s1600-h/images88.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SMckWO8A_ZI/AAAAAAAAAi4/5bslLnGGwWU/s400/images88.jpg" alt="" id="BLOGGER_PHOTO_ID_5244200255481773458" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SMckWQQe4eI/AAAAAAAAAjA/ao4XaaypnK8/s1600-h/whitebal88.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SMckWQQe4eI/AAAAAAAAAjA/ao4XaaypnK8/s400/whitebal88.jpg" alt="" id="BLOGGER_PHOTO_ID_5244200255836053986" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SMckWmUAQ1I/AAAAAAAAAjI/KiAh14Vx_I0/s1600-h/norm88.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SMckWmUAQ1I/AAAAAAAAAjI/KiAh14Vx_I0/s400/norm88.jpg" alt="" id="BLOGGER_PHOTO_ID_5244200261756404562" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SMckWliKU-I/AAAAAAAAAjQ/fhCCHWpZN-Q/s1600-h/seg88.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SMckWliKU-I/AAAAAAAAAjQ/fhCCHWpZN-Q/s400/seg88.jpg" alt="" id="BLOGGER_PHOTO_ID_5244200261547348962" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SMckW4tFqgI/AAAAAAAAAjY/fX2e_V5PBDc/s1600-h/bw88.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SMckW4tFqgI/AAAAAAAAAjY/fX2e_V5PBDc/s400/bw88.jpg" alt="" id="BLOGGER_PHOTO_ID_5244200266693454338" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SMclDO0kT3I/AAAAAAAAAjg/6lppwP7lJ-s/s1600-h/morph88.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SMclDO0kT3I/AAAAAAAAAjg/6lppwP7lJ-s/s400/morph88.jpg" alt="" id="BLOGGER_PHOTO_ID_5244201028544647026" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;measured quantities: m = 175 g, length = 0.63 m, width = 0.03 m&lt;br /&gt;&lt;br /&gt;Analytic solutions:&lt;br /&gt;Moment of inertia = 175g(0.63m*0.63m)/3 + 175g(0.03m*0.03m)/12 = &lt;span style="color: rgb(255, 204, 0);"&gt;23.165625 g m^2&lt;/span&gt;&lt;br /&gt;Center of oscillation = I/mL = 23.165625 m/(175*0.315) = &lt;span style="color: rgb(255, 204, 0);"&gt;0.4202381 m&lt;/span&gt;&lt;br /&gt;Period of oscillation = 2*pi*sqrt(23.165625/(175*9.8*0.315)) = &lt;span style="color: rgb(255, 204, 0);"&gt;1.3011116 s&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;We now proceed in solving these quantities numerically from the data.&lt;br /&gt;&lt;br /&gt;Length of ruler = &lt;span style="color: rgb(255, 204, 0);"&gt;105 pixels&lt;/span&gt; --&gt; 0.63 m&lt;br /&gt;Width of ruler = &lt;span style="color: rgb(255, 204, 0);"&gt;6 pixels&lt;/span&gt;&lt;br /&gt;Moment of inertia = 175g(0.63m*0.63m)/3 + 175g((6*0.63m/105)*(6*0.63m/105))/12&lt;br /&gt;= &lt;span style="color: rgb(255, 204, 0);"&gt;23.1714 g m^2&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;%error = 0.02493&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Center of oscillation = 23.1714 m/(175*(52.5*0.63/105)) = &lt;span style="color: rgb(255, 204, 0);"&gt;0.4203429 m&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;%error = 0.02494&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Period of oscillation:&lt;br /&gt;Our video was captured with a fps of 15. The graph of the position vs time of the centroid of the ruler is shown below.&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SMdLQPTf9xI/AAAAAAAAAjw/AJGiRO1Rd8c/s1600-h/period.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SMdLQPTf9xI/AAAAAAAAAjw/AJGiRO1Rd8c/s400/period.jpg" alt="" id="BLOGGER_PHOTO_ID_5244243033454540562" border="0" /&gt;&lt;/a&gt;The wave is not a perfect sinusoid due to some air resistance present. The peaks and troughs are relatively equally spaced between each other so the period can be calculated. Peak to peak, the heights for one frame is given from the data:&lt;br /&gt;94, 93, 90, 87, 83, 78, 73.5, 68.5, 65, 64.5, 64.5, 65, 68.5, 73, 77.5, 83.5, 87.5, 90, 92.5, 92.5&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;Thus, one period was captured in 20 frames&lt;/span&gt;. If 15 frames = 1 second, then using ratio and proportion, 20 frames = &lt;span style="color: rgb(255, 204, 0);"&gt;1.3333333 s&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;%error = 2.47647&lt;/span&gt;&lt;br /&gt;____________________________________________________________________&lt;br /&gt;&lt;br /&gt;chdir('act17images\');&lt;br /&gt;img = 216; &lt;span style="color: rgb(51, 204, 0);"&gt;//total no. of frames in video&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//open cropped image for color segmentation&lt;/span&gt;&lt;br /&gt;im2 = imread('act17crop1.jpg');&lt;br /&gt;wid = zeros(img,1); leng = zeros(1,1);&lt;br /&gt;&lt;br /&gt;for i = 1:img&lt;br /&gt;im = imread('images'+string(i)+'.jpg'); &lt;span style="color: rgb(51, 204, 0);"&gt;//open images&lt;/span&gt;&lt;br /&gt;white = im(1:120,120:160,:);&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//white balance&lt;/span&gt;&lt;br /&gt;r = mean(white(:,:,1));&lt;br /&gt;g = mean(white(:,:,2));&lt;br /&gt;b = mean(white(:,:,3));&lt;br /&gt;im(:,:,1) = im(:,:,1)/r;&lt;br /&gt;im(:,:,2) = im(:,:,2)/g;&lt;br /&gt;im(:,:,3) = im(:,:,3)/b;&lt;br /&gt;im = im/max(im);&lt;br /&gt;m = find(im&gt;1);&lt;br /&gt;im(m) = 1;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt; //color normalization&lt;/span&gt;&lt;br /&gt;I = im(:,:,1)+im(:,:,2)+im(:,:,3);&lt;br /&gt;im(:,:,1) = im(:,:,1)./I;&lt;br /&gt;im(:,:,2) = im(:,:,2)./I;&lt;br /&gt;im(:,:,3) = im(:,:,3)./I;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//histogram backprojection&lt;/span&gt;&lt;br /&gt;R = linspace(0,1,32); G = R;&lt;br /&gt;P = zeros(32,32);&lt;br /&gt;[x2,y2] = size(im2);&lt;br /&gt;for j = 1:x2&lt;br /&gt;for k = 1:y2&lt;br /&gt;  xr = find(R &lt;= im2(j,k,1));      &lt;br /&gt;xg = find(G &lt;= im2(j,k,2));      &lt;br /&gt;P(xr(length(xr)),xg(length(xg))) = P(xr(length(xr)),xg(length(xg))) + 1;    &lt;br /&gt;end &lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;P = P/sum(P);  &lt;br /&gt;[x1,y1] = size(im);&lt;br /&gt; bpj = zeros(x1,y1);&lt;br /&gt; for j = 1:x1&lt;br /&gt;  for k = 1:y1      &lt;br /&gt;xr = find(R &lt;= im(j,k,1));      &lt;br /&gt;xg = find(G &lt;= im(j,k,2));      &lt;br /&gt;bpj(j,k) = P(xr(length(xr)), xg(length(xg)));    &lt;br /&gt;end  &lt;br /&gt;end  &lt;br /&gt;bpj = bpj/max(bpj);         &lt;span style="color: rgb(51, 204, 0);"&gt;&lt;br /&gt;&lt;br /&gt;//convert to B&amp;amp;W&lt;/span&gt;&lt;br /&gt;bpj = im2bw(bpj, 0.02);&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//morphological operations&lt;/span&gt;&lt;br /&gt;strel = ones(4,1);&lt;br /&gt;bpj = erode(bpj,strel); &lt;span style="color: rgb(51, 204, 0);"&gt;//opening operation&lt;/span&gt;&lt;br /&gt;bpj = dilate(bpj,strel);&lt;br /&gt;bpj = dilate(bpj,strel); &lt;span style="color: rgb(51, 204, 0);"&gt;//closing operation&lt;/span&gt;&lt;br /&gt;bpj = erode(bpj,strel);&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//get centroid&lt;/span&gt;&lt;br /&gt;[p,q] = find(bpj == 1);&lt;br /&gt;wid(i) = (max(q)+min(q))/2;&lt;br /&gt;leng(i) = (max(p)+min(p))/2;&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//plot position vs time&lt;/span&gt;&lt;br /&gt;plot([1:img]/15,wid); &lt;span style="color: rgb(51, 204, 0);"&gt;//consider fps of video&lt;/span&gt;&lt;br /&gt;title('physical pendulum');&lt;br /&gt;xlabel('time (seconds)');&lt;br /&gt;ylabel('relative amplitude');&lt;br /&gt;____________________________________________________________________&lt;br /&gt;&lt;br /&gt;I give myself &lt;span style="color: rgb(255, 204, 0);"&gt;10 points&lt;/span&gt; for this activity since the calculated quantities were close to their analytic values. My collaborators were &lt;span style="color: rgb(255, 204, 0);"&gt;Jeric Tugaff and Mark Leo Bejemino&lt;/span&gt;.&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/223420158170109027-2367062873984412938?l=cole-ap186.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cole-ap186.blogspot.com/feeds/2367062873984412938/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=223420158170109027&amp;postID=2367062873984412938' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/223420158170109027/posts/default/2367062873984412938'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/223420158170109027/posts/default/2367062873984412938'/><link rel='alternate' type='text/html' href='http://cole-ap186.blogspot.com/2008/09/activity-17-basic-video-processing.html' title='Activity 17: Basic Video Processing'/><author><name>Cole</name><uri>http://www.blogger.com/profile/17840780106218077983</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://2.bp.blogspot.com/_6ZpN6X5LZPw/SeFgyvHYwpI/AAAAAAAAAmc/H76Ym0zH_Mw/S220/fabros05+-+Copy.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_6ZpN6X5LZPw/SMckWO8A_ZI/AAAAAAAAAi4/5bslLnGGwWU/s72-c/images88.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-223420158170109027.post-2751087596032246591</id><published>2008-09-02T18:14:00.000-07:00</published><updated>2009-04-11T20:59:48.456-07:00</updated><title type='text'>Activity 16: Color Image Segmentation</title><content type='html'>&lt;div style="text-align: justify;"&gt;In image segmentation, a region of interest (ROI) is picked out from the rest of the image such that further processing can be done on it. Selection rules are based on features unique to the ROI. One such feature is color. Color has been used to segment images of skin regions in face and hand recognition, land cover in remote sensing, and cells in microscopy.&lt;br /&gt;&lt;br /&gt;In this activity, we aim to do image segmentation using 2 different methods: &lt;span style="color: rgb(255, 204, 0);"&gt;parametric and non-parametric probability distribution estimation&lt;/span&gt;. First, we convert image RGB to normalized chromaticity coordinates (NCC) and then apply the 2 techniques.&lt;br /&gt;&lt;br /&gt;We can transform the image RGB values to NCC by,&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SL0FXYODUJI/AAAAAAAAAhw/pGj2mmL1yDk/s1600-h/ncc.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SL0FXYODUJI/AAAAAAAAAhw/pGj2mmL1yDk/s400/ncc.jpg" alt="" id="BLOGGER_PHOTO_ID_5241351440525643922" border="0" /&gt;&lt;/a&gt;Since r + b + g = 1, then b = 1 - r - g and it is enough to represent chromaticity by just two coordinates, r and g. When segmenting 3D objects it is better to first transform RGB into rgI. The figure below shows the r-g color space.&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SL0HAiF92HI/AAAAAAAAAh4/_TufRbVLtT4/s1600-h/rgcc.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SL0HAiF92HI/AAAAAAAAAh4/_TufRbVLtT4/s400/rgcc.jpg" alt="" id="BLOGGER_PHOTO_ID_5241353247062349938" border="0" /&gt;&lt;/a&gt;When r and g are both zero, b = 1. Therefore, the origin corresponds to blue while points corresponding to r=1 and g=1 are points of pure red and green, respectively. Any color therefore can be represented as a point in NCC space. Thus the pixel chromaticities of a red ball will only occupy a small blob in the red region regardless of its shading variation.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;source: &lt;span style="color: rgb(255, 204, 0);"&gt;M.Soriano, &lt;/span&gt;&lt;span style="font-style: italic; color: rgb(255, 204, 0);"&gt;A16 - Color Image Segmentation.pdf&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The histogram of a green chair is shown below.&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SL0Xt5FD4mI/AAAAAAAAAiw/l5IzAF4o5-s/s1600-h/hist.gif"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SL0Xt5FD4mI/AAAAAAAAAiw/l5IzAF4o5-s/s320/hist.gif" alt="" id="BLOGGER_PHOTO_ID_5241371618512724578" border="0" /&gt;&lt;/a&gt;____________________________________________________________________&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 153, 153);font-size:180%;" &gt;Parametric method:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;Original &amp;amp; Probability image&lt;/span&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SL0I9mIfLuI/AAAAAAAAAiA/Wt9NekjnWx8/s1600-h/graychair.gif"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 218px; height: 218px;" src="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SL0I9mIfLuI/AAAAAAAAAiA/Wt9NekjnWx8/s400/graychair.gif" alt="" id="BLOGGER_PHOTO_ID_5241355395630313186" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SL0I9htH1DI/AAAAAAAAAiI/3C4hSI_WX78/s1600-h/probchair.gif"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 217px; height: 219px;" src="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SL0I9htH1DI/AAAAAAAAAiI/3C4hSI_WX78/s400/probchair.gif" alt="" id="BLOGGER_PHOTO_ID_5241355394441794610" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;Here, the original object is a green chair. We cropped a region of interest &lt;span style="color: rgb(255, 204, 0);"&gt;(center part of the backrest)&lt;/span&gt; as our color model and tried to see where it matched that of the original image. The pixel values of the resulting image is the probability that a pixel will have the same color as the model. This method segmented the image well and we can infer that the bright parts of the seat are of the same color as that of the backrest.&lt;br /&gt;____________________________________________________________________&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 153, 153);font-size:180%;" &gt;Histogram backprojection (non-parametric) method:&lt;/span&gt;&lt;br /&gt;Original &amp;amp; Probability image&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SL0I9mIfLuI/AAAAAAAAAiA/Wt9NekjnWx8/s1600-h/graychair.gif"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 218px; height: 218px;" src="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SL0I9mIfLuI/AAAAAAAAAiA/Wt9NekjnWx8/s400/graychair.gif" alt="" id="BLOGGER_PHOTO_ID_5241355395630313186" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SL0N_KoYGPI/AAAAAAAAAig/jfG-G6DhWPo/s1600-h/histchair.gif"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 225px; height: 219px;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SL0N_KoYGPI/AAAAAAAAAig/jfG-G6DhWPo/s400/histchair.gif" alt="" id="BLOGGER_PHOTO_ID_5241360920165751026" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;Histogram backprojection is one technique where based on the color histogram, a pixel location is given a value equal to its histogram value in chromaticity space. We implemented this and the resulting image was generated. Upon comparison with the result from the parametric method, there are more white pixels that correspond to the cropped color model. We can really see where the similar colors lie. &lt;span style="color: rgb(255, 204, 0);"&gt;The segmentation is better using the 2nd method&lt;/span&gt;. This also has the advantage of faster processing because no more computations are needed, just a look-up of histogram values. In the parametric method, the mean and standard deviation of r and g must be found in order to calculate a Gaussian distribution that tests the probability of pixel membership to the ROI.&lt;br /&gt;____________________________________________________________________&lt;br /&gt;&lt;br /&gt;stacksize(4e7);&lt;br /&gt;&lt;br /&gt;im1 = imread('green chair.jpg');&lt;br /&gt;im2 = imread('green chair crop.jpg');&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//imshow(im1);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;R1 = im1(:,:,1); G1 = im1(:,:,2); B1 = im1(:,:,3);&lt;br /&gt;I1 = R1 + G1 + B1;&lt;br /&gt;R2 = im2(:,:,1); G2 = im2(:,:,2); B2 = im2(:,:,3);&lt;br /&gt;I2 = R2 + G2 + B2;&lt;br /&gt;&lt;br /&gt;r1 = R1./I1; g1 = G1./I1; b1 = B1./I1;&lt;br /&gt;r2 = R2./I2; g2 = G2./I2; b2 = B2./I2;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//parametric estimation&lt;/span&gt;&lt;br /&gt;ur = mean(r2); sr = stdev(r2);&lt;br /&gt;ug = mean(g2); sg = stdev(g2);&lt;br /&gt;&lt;br /&gt;pr = 1.0*exp(-((r1-ur).^2)/(2*sr^2))/(sr*sqrt(2*%pi));&lt;br /&gt;pg = 1.0*exp(-((g1-ug).^2)/(2*sg^2))/(sg*sqrt(2*%pi));&lt;br /&gt;&lt;br /&gt;prob = pr.*pg;&lt;br /&gt;prob = prob/max(prob);&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//imshow(prob,[]);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//2d histogram&lt;/span&gt;&lt;br /&gt;r = linspace(0,1,32); r = g;&lt;br /&gt;P = zeros(32,32);&lt;br /&gt;[x,y] = size(im2);&lt;br /&gt;for i = 1:x&lt;br /&gt;for j = 1:y&lt;br /&gt;xr = find(r &lt;= im2(i,j,1));   &lt;br /&gt;xg = find(g &lt;= im2(i,j,2));    &lt;br /&gt;P(xr(length(xr)), xg(length(xg))) = P(xr(length(xr)), xg(length(xg)))+1;  &lt;br /&gt;end&lt;br /&gt;end&lt;br /&gt;P = P/sum(P); &lt;span style="color: rgb(51, 204, 0);"&gt;&lt;br /&gt;//surf(P);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//backprojection&lt;/span&gt;&lt;br /&gt;[x,y] = size(im1);&lt;br /&gt;recons = zeros(x,y);&lt;br /&gt;for i = 1:x&lt;br /&gt;for j = 1:y&lt;br /&gt;xr = find(r &lt;= im1(i,j,1));    &lt;br /&gt;xg = find(g &lt;= im1(i,j,2));    &lt;br /&gt;recons(i,j) = P(xr(length(xr)), xg(length(xg))); &lt;br /&gt;end&lt;br /&gt;end&lt;br /&gt;imshow(recons, []);&lt;br /&gt;____________________________________________________________________&lt;br /&gt;&lt;br /&gt;I give myself &lt;span style="color: rgb(255, 204, 0);"&gt;10 points&lt;/span&gt; for this activity since the colored image was properly segmented using 2 different methods. Histogram backprojection is more efficient since less calculations are needed, only a look-up table. It also produced a better probability image. Thanks to &lt;span style="color: rgb(255, 204, 0);"&gt;Jeric Tugaff &lt;/span&gt;for his help in the histogram backprojection code.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/223420158170109027-2751087596032246591?l=cole-ap186.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cole-ap186.blogspot.com/feeds/2751087596032246591/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=223420158170109027&amp;postID=2751087596032246591' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/223420158170109027/posts/default/2751087596032246591'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/223420158170109027/posts/default/2751087596032246591'/><link rel='alternate' type='text/html' href='http://cole-ap186.blogspot.com/2008/09/activity-16-color-image-segmentation.html' title='Activity 16: Color Image Segmentation'/><author><name>Cole</name><uri>http://www.blogger.com/profile/17840780106218077983</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://2.bp.blogspot.com/_6ZpN6X5LZPw/SeFgyvHYwpI/AAAAAAAAAmc/H76Ym0zH_Mw/S220/fabros05+-+Copy.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_6ZpN6X5LZPw/SL0FXYODUJI/AAAAAAAAAhw/pGj2mmL1yDk/s72-c/ncc.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-223420158170109027.post-393253598021765094</id><published>2008-08-28T10:46:00.000-07:00</published><updated>2008-10-08T19:34:21.448-07:00</updated><title type='text'>Activity 15: Color Image Processing</title><content type='html'>&lt;div style="text-align: justify;"&gt;A colored digital image is an array of pixels each having red, green and blue light overlaid in various proportions. Per pixel, the color captured by a digital color camera is an integral of the product of the spectral power distribution of the incident light source S(l), the surface reflectance r(l), and the spectral sensitivity of the camera h(l). That is, if the color camera has spectral sensitivity hR(l), hG(l) , hB(l) for the red, green, and blue channels respectively, then the color of the pixel is given by&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SLXrSRokssI/AAAAAAAAAgA/r3Qcr8NhhBQ/s1600-h/rgb.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SLXrSRokssI/AAAAAAAAAgA/r3Qcr8NhhBQ/s400/rgb.jpg" alt="" id="BLOGGER_PHOTO_ID_5239352440719192770" border="0" /&gt;&lt;/a&gt;is a balancing constant equal to the inverse of the camera output when shown a white object (r(l) = 1.0). Equations (1) to (4) explain why sometimes the colors captured by a digital camera appear unsatisfactory.&lt;br /&gt;&lt;br /&gt;In this activity, we aim to observe the differences between images obtained using several white balancing settings in a camera and compare two white balancing algorithms: Reference White and Gray World. We capture an obviously wrongly white balanced image, apply the two algorithms, and comment on their white balancing quality.&lt;br /&gt;&lt;br /&gt;In the Reference White Algorithm, you capture an image using an unbalanced camera and use the RGB values of a known white object as the divisor. In the Gray World Algorithm, it is assumed that the average color of the world is gray. Gray is part of the family of white, as is black. Therefore, if you know the RGB of a gray object, it is essentially the RGB of white up to a constant factor. Thus, to get the balancing constants, you take the average red, green and blue value of the captured image and utilize them as the balancing constants.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;source: &lt;span style="color: rgb(255, 204, 0);"&gt;M. Soriano,&lt;/span&gt;&lt;span style="font-style: italic; color: rgb(255, 204, 0);"&gt; A15 - Color Image Processing.pdf&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;____________________________________________________________________&lt;br /&gt;&lt;br /&gt;The following images were taken using an Olympus Stylus 770SW digital camera with an exposure of -2 under a fluorescent light source. I utilized a Macbeth chart since the major hues were represented and white was also present.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;(order of images from left to right, top to bottom: auto WB, daylight, cloudy, tungsten, fluorescent1, fluorescent2, fluorescent3)&lt;/span&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SLX6MLMN00I/AAAAAAAAAgI/YxMVH1D3VpU/s1600-h/P8280703.JPG"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SLX6MLMN00I/AAAAAAAAAgI/YxMVH1D3VpU/s320/P8280703.JPG" alt="" id="BLOGGER_PHOTO_ID_5239368828584842050" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SLX6MMmM4SI/AAAAAAAAAgQ/LqAkQ18lHU8/s1600-h/P8280704.JPG"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SLX6MMmM4SI/AAAAAAAAAgQ/LqAkQ18lHU8/s320/P8280704.JPG" alt="" id="BLOGGER_PHOTO_ID_5239368828962267426" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SLX6Mfo0KFI/AAAAAAAAAgY/D4LRkrONwcg/s1600-h/P8280705.JPG"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SLX6Mfo0KFI/AAAAAAAAAgY/D4LRkrONwcg/s320/P8280705.JPG" alt="" id="BLOGGER_PHOTO_ID_5239368834073503826" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SLX6McNlvLI/AAAAAAAAAgg/AgCHhyFihds/s1600-h/P8280706.JPG"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SLX6McNlvLI/AAAAAAAAAgg/AgCHhyFihds/s320/P8280706.JPG" alt="" id="BLOGGER_PHOTO_ID_5239368833154006194" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SLX6MUBnlnI/AAAAAAAAAgo/7SyE5TvTeeM/s1600-h/P8280707.JPG"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SLX6MUBnlnI/AAAAAAAAAgo/7SyE5TvTeeM/s320/P8280707.JPG" alt="" id="BLOGGER_PHOTO_ID_5239368830956312178" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SLX7RSsEomI/AAAAAAAAAgw/zv9JEx-P6KY/s1600-h/P8280708.JPG"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SLX7RSsEomI/AAAAAAAAAgw/zv9JEx-P6KY/s320/P8280708.JPG" alt="" id="BLOGGER_PHOTO_ID_5239370016008479330" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SLX7RQC23yI/AAAAAAAAAg4/-bAhy-99kpc/s1600-h/P8280709.JPG"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SLX7RQC23yI/AAAAAAAAAg4/-bAhy-99kpc/s320/P8280709.JPG" alt="" id="BLOGGER_PHOTO_ID_5239370015298740002" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Upon comparison, we can observe that the colors are represented in high quality in &lt;span style="color: rgb(255, 204, 0);"&gt;image 1 and 5, which are the auto white balance and fluorescent1 settings, respectively&lt;/span&gt;. The sunlight and cloudy settings made the colors look dimmer, flourescent2 and 3 had a larger blue component, and the tungsten setting was just plain bad. What it did was since a tungsten light source has a low blue component upon looking at its spectra, the camera increased the blue to compensate. I will use this obviously wrongly white balanced image in the next part of the activity.&lt;br /&gt;____________________________________________________________________&lt;br /&gt;&lt;br /&gt;Results:&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;ORIGINAL, REFERENCE WHITE, GRAY WORLD&lt;/span&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SLYJyyz6GLI/AAAAAAAAAhA/fJgR5D6oltk/s1600-h/tungsten.JPG"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 204px; height: 152px;" src="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SLYJyyz6GLI/AAAAAAAAAhA/fJgR5D6oltk/s320/tungsten.JPG" alt="" id="BLOGGER_PHOTO_ID_5239385984729749682" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SLYJzKclErI/AAAAAAAAAhI/49dbnMaD1pU/s1600-h/refwhite_tungsten.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 203px; height: 152px;" src="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SLYJzKclErI/AAAAAAAAAhI/49dbnMaD1pU/s320/refwhite_tungsten.jpg" alt="" id="BLOGGER_PHOTO_ID_5239385991074353842" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SLYJzMlsx-I/AAAAAAAAAhQ/s3rCx5gvwb4/s1600-h/grayworld_tungsten.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 202px; height: 153px;" src="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SLYJzMlsx-I/AAAAAAAAAhQ/s3rCx5gvwb4/s320/grayworld_tungsten.jpg" alt="" id="BLOGGER_PHOTO_ID_5239385991649478626" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;We can see from the images that &lt;span style="color: rgb(255, 204, 0);"&gt;the Reference White Algorithm produced a better result&lt;/span&gt;. The colors are more vibrant. However, some patches became white, like yellow and light orange. But in comparison with the Gray World algorithm, this is still acceptable. Majority of the colors are now green or white in the last image, showing poor quality. Next, we investigate the effects of these two methods for objects with similar hues.&lt;br /&gt;&lt;br /&gt;Again, I use the tungsten white balance setting because it is really not suited for the illumination condition (fluorescent). We implement the two algorithms and the results are shown below.&lt;br /&gt;&lt;br /&gt;Results:&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;ORIGINAL, REFERENCE WHITE, GRAY WORLD&lt;/span&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SLYOsnBX3nI/AAAAAAAAAhY/3lMPsrblWTE/s1600-h/P8280713.JPG"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 205px; height: 154px;" src="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SLYOsnBX3nI/AAAAAAAAAhY/3lMPsrblWTE/s320/P8280713.JPG" alt="" id="BLOGGER_PHOTO_ID_5239391376043925106" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SLYOs2gT7wI/AAAAAAAAAhg/-SK4LdG0Lcw/s1600-h/refwhite.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 205px; height: 154px;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SLYOs2gT7wI/AAAAAAAAAhg/-SK4LdG0Lcw/s320/refwhite.jpg" alt="" id="BLOGGER_PHOTO_ID_5239391380200222466" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SLYOsyL0q8I/AAAAAAAAAho/tck0xntu_W8/s1600-h/grayworld.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 205px; height: 154px;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SLYOsyL0q8I/AAAAAAAAAho/tck0xntu_W8/s320/grayworld.jpg" alt="" id="BLOGGER_PHOTO_ID_5239391379040545730" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Again, the Reference White Algorithm produced the better result. This is because the red component of white is really red and we use this as the divisor in equations 1-3. In comparison with the Gray World algorithm, the red component of the whole image is not necessarily also red and thus the error is produced. From both the Macbeth chart and the blue objects, we observe that the blue parts become green and those with some red component turns white.&lt;br /&gt;____________________________________________________________________&lt;br /&gt;&lt;br /&gt;I give myself &lt;span style="color: rgb(255, 204, 0);"&gt;10 points&lt;/span&gt; for this activity since both algorithms were implemented and the results were very clear. Thanks to &lt;span style="color: rgb(255, 204, 0);"&gt;Marge Maallo &lt;/span&gt;for her help in this activity.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/223420158170109027-393253598021765094?l=cole-ap186.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cole-ap186.blogspot.com/feeds/393253598021765094/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=223420158170109027&amp;postID=393253598021765094' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/223420158170109027/posts/default/393253598021765094'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/223420158170109027/posts/default/393253598021765094'/><link rel='alternate' type='text/html' href='http://cole-ap186.blogspot.com/2008/08/activity-15-color-image-processing.html' title='Activity 15: Color Image Processing'/><author><name>Cole</name><uri>http://www.blogger.com/profile/17840780106218077983</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://2.bp.blogspot.com/_6ZpN6X5LZPw/SeFgyvHYwpI/AAAAAAAAAmc/H76Ym0zH_Mw/S220/fabros05+-+Copy.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_6ZpN6X5LZPw/SLXrSRokssI/AAAAAAAAAgA/r3Qcr8NhhBQ/s72-c/rgb.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-223420158170109027.post-6410001435117923595</id><published>2008-08-26T16:44:00.000-07:00</published><updated>2008-10-08T19:45:27.408-07:00</updated><title type='text'>Activity 14: Stereometry</title><content type='html'>&lt;div style="text-align: justify;"&gt;Multiple 2D views allow the computation of depth information. In this activity, we use two identical cameras to capture and reconstruct a 3D object. Images are essentially 3D objects projected onto a 2D frame. From object points at (x,y,z), an image is reduced to (x,y) with z projected as a function of x and y and camera object geometry. In applications such as microscopy or terrain imaging, it is sometimes more informative to preserve the depth information z. In this way, the 3D image may be inspected at different view angles. Stereo imaging is the technique we will use in this experiment and it is inspired by how our two eyes allow us to discriminate depth.&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SLNGQtlwRaI/AAAAAAAAAeg/2rE4kvh8hxY/s1600-h/fig1.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SLNGQtlwRaI/AAAAAAAAAeg/2rE4kvh8hxY/s400/fig1.jpg" alt="" id="BLOGGER_PHOTO_ID_5238608044491818402" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;From similar triangles, the following equations are generated.&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SLNGQushzQI/AAAAAAAAAeo/J2UYTRpCT-4/s1600-h/fig2.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SLNGQushzQI/AAAAAAAAAeo/J2UYTRpCT-4/s400/fig2.jpg" alt="" id="BLOGGER_PHOTO_ID_5238608044788665602" border="0" /&gt;&lt;/a&gt; If done on several points on the image, we can reconstruct the object's 3D shape using the z's calculated.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;source: &lt;span style="color: rgb(255, 204, 0);"&gt;M. Soriano, &lt;/span&gt;&lt;span style="color: rgb(255, 204, 0); font-style: italic;"&gt;A14 - Stereometry.pdf&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;Shown below are two images of a simple 3D object that I captured using an Olympus Stylus 770SW digital camera. The vertices of the Rubik's cube will serve as reference points. From figure 1, &lt;span style="color: rgb(255, 204, 0);"&gt;b&lt;/span&gt; was measured to be &lt;span style="color: rgb(255, 204, 0);"&gt;30mm&lt;/span&gt; using a ruler.&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SLOlyfByEwI/AAAAAAAAAfQ/ziOBGQMZdrU/s1600-h/act14_0cm_copy.JPG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SLOlyfByEwI/AAAAAAAAAfQ/ziOBGQMZdrU/s400/act14_0cm_copy.JPG" alt="" id="BLOGGER_PHOTO_ID_5238713078303036162" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SLOlyUFBNsI/AAAAAAAAAfY/2kF72J2OCZw/s1600-h/act14_3cm_copy.JPG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SLOlyUFBNsI/AAAAAAAAAfY/2kF72J2OCZw/s400/act14_3cm_copy.JPG" alt="" id="BLOGGER_PHOTO_ID_5238713075363821250" border="0" /&gt;&lt;/a&gt;____________________________________________________________________&lt;br /&gt;&lt;br /&gt;Next, we calibrate our camera using the algorithm in activity 11 to find the focal length f and the distances from the camera center, x1 and x2. The matrix A was calculated to be,&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;A = [&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;-12.892329      &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;8.19365       &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;-1.2825517&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;121.45776&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;-5.9037883&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;-6.0874536&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;12.008296&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;80.296042&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;-0.0214988&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;-0.0197136&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;-0.0140380&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;1]&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;We now get A(1:3,1:3) and factorize using RQ factorization in order to convert the matrix into the upper diagonal matrix K. We also need to ensure that the factorized A(3,3) element is 1 by dividing the whole matrix by K(3,3).&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SLOnCRoluiI/AAAAAAAAAfg/dntQTHqdrTc/s1600-h/K.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SLOnCRoluiI/AAAAAAAAAfg/dntQTHqdrTc/s400/K.jpg" alt="" id="BLOGGER_PHOTO_ID_5238714449097243170" border="0" /&gt;&lt;/a&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;RQ factorization code by Michael Overton&lt;/span&gt;&lt;br /&gt;(source:  &lt;a href="http://www.cs.nyu.edu/faculty/overton/software/uncontrol/rq.m"&gt;http://www.cs.nyu.edu/faculty/overton/software/uncontrol/rq.m&lt;/a&gt;)&lt;br /&gt;&lt;br /&gt;function [R,Q]= rq(A)&lt;br /&gt;&lt;br /&gt;m = size(A,1);&lt;br /&gt;n = size(A,2);&lt;br /&gt;if n &lt; m&lt;br /&gt;error('RQ requires m&lt;=n')&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;p = mtlb_fliplr(mtlb_eye(m));&lt;br /&gt;Atp = A’*P;&lt;br /&gt;[Q2,R2] = qr(Atp);&lt;br /&gt;bigperm = [P zeros(m,n-m; zeros(n-m,m) mtlb_eye(n-m)];&lt;br /&gt;q = (Q2*bigperm)’;&lt;br /&gt;r = (bigperm*R2*P)’;&lt;br /&gt;&lt;span style="font-family: monospace;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;K =&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;[-14.756525, 0.0554842, 121.46413;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;0, 14.493566, 80.290264;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;0, 0, 1]&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;We can see that the camera center is located at &lt;span style="color: rgb(255, 204, 0);"&gt;xo = 121.46413 and yo = 80.290264&lt;/span&gt;. The actual size of the image is 256x217. Thus, we can say that the camera center is relatively close to the image center (considering only x since we only need x1 and x2, i.e. 121.5*121.5 = 243, which is close to 256). From this value of xo, we can now solve for x1 and x2 for different points on the cube. Then the height z will follow from the formula. We plot our results in 3D. &lt;span style="color: rgb(153, 153, 153);"&gt;(see Scilab help on splin2d, example 2)&lt;/span&gt;&lt;br /&gt;____________________________________________________________________&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;Reconstructed images of the Rubik's cube:&lt;/span&gt;&lt;br /&gt;Here we have 3 views of the reconstructed image. Although the edges are curved, the shape of the cube is clearly observed. A better reconstruction may be possible by locating more points. For the resulting images, only the &lt;span style="color: rgb(255, 204, 0);"&gt;7 visible corner points&lt;/span&gt; in the cube were used in finding the correspondence between the 1st and 2nd images.&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SLT19MQhPUI/AAAAAAAAAfo/qtJo8IRf1gg/s1600-h/im1.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SLT19MQhPUI/AAAAAAAAAfo/qtJo8IRf1gg/s400/im1.jpg" alt="" id="BLOGGER_PHOTO_ID_5239082698150067522" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SLT19AQguaI/AAAAAAAAAfw/sG6YBfydg5Q/s1600-h/im2.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SLT19AQguaI/AAAAAAAAAfw/sG6YBfydg5Q/s400/im2.jpg" alt="" id="BLOGGER_PHOTO_ID_5239082694928808354" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SLT19Qwk1-I/AAAAAAAAAf4/cfLJfGv1ygI/s1600-h/im3.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SLT19Qwk1-I/AAAAAAAAAf4/cfLJfGv1ygI/s400/im3.jpg" alt="" id="BLOGGER_PHOTO_ID_5239082699358263266" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;____________________________________________________________________&lt;br /&gt;&lt;br /&gt;I give myself &lt;span style="color: rgb(255, 204, 0);"&gt;9 points&lt;/span&gt; for this activity since the reconstruction was properly done but the result was not very convincing. The result looked like a cube with smoothened corners. Thanks to &lt;span style="color: rgb(255, 204, 0);"&gt;JC Nadora, Julie Dado, and Jeric Tugaff&lt;/span&gt; for their help in the use of &lt;span style="font-style: italic; color: rgb(255, 204, 0);"&gt;splin2d&lt;/span&gt; and &lt;span style="font-style: italic; color: rgb(255, 204, 0);"&gt;interp2d&lt;/span&gt;.&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/223420158170109027-6410001435117923595?l=cole-ap186.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cole-ap186.blogspot.com/feeds/6410001435117923595/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=223420158170109027&amp;postID=6410001435117923595' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/223420158170109027/posts/default/6410001435117923595'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/223420158170109027/posts/default/6410001435117923595'/><link rel='alternate' type='text/html' href='http://cole-ap186.blogspot.com/2008/08/activity-14-stereometry.html' title='Activity 14: Stereometry'/><author><name>Cole</name><uri>http://www.blogger.com/profile/17840780106218077983</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://2.bp.blogspot.com/_6ZpN6X5LZPw/SeFgyvHYwpI/AAAAAAAAAmc/H76Ym0zH_Mw/S220/fabros05+-+Copy.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_6ZpN6X5LZPw/SLNGQtlwRaI/AAAAAAAAAeg/2rE4kvh8hxY/s72-c/fig1.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-223420158170109027.post-1631068110810023248</id><published>2008-08-07T11:13:00.000-07:00</published><updated>2008-09-15T17:12:24.145-07:00</updated><title type='text'>Activity 13: Photometric Stereo</title><content type='html'>&lt;div style="text-align: justify;"&gt;In this activity, we will use the concept of photometric stereo to reconstruct an object in 3D from image using shadow cues. The matlab file &lt;span style="font-style: italic; color: rgb(255, 204, 0);"&gt;Photos.mat&lt;/span&gt; contains the 4 images that we will work with and the elements of matrix V is also given. These are the locations in space of the light source illuminating the object.&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;We can estimate the shape of the surface by capturing multiple images of the surface with the sources at different locations. The information about the surface will be coded in the shadings obtained from the images. We can define a matrix V such that,&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SJqes65FrtI/AAAAAAAAAco/FW8pjohxIsU/s1600-h/matrixV.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SJqes65FrtI/AAAAAAAAAco/FW8pjohxIsU/s400/matrixV.jpg" alt="" id="BLOGGER_PHOTO_ID_5231668411704389330" border="0" /&gt;&lt;/a&gt;where each row is a source and each column corresponds to the x,y,z component of the source's location in space. If we take N images of the surface using each of these N sources, then for each point (x,y) on the surface we have,&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SJqesz-j9UI/AAAAAAAAAcw/SXHLN-3OutM/s1600-h/matrixI.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SJqesz-j9UI/AAAAAAAAAcw/SXHLN-3OutM/s400/matrixI.jpg" alt="" id="BLOGGER_PHOTO_ID_5231668409848296770" border="0" /&gt;&lt;/a&gt;We can now solve for g since I and V are known and we normalize g by its length in order to get the normal vector.&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SJqetDCWbnI/AAAAAAAAAc4/WnFbpv27BCQ/s1600-h/matrixG.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SJqetDCWbnI/AAAAAAAAAc4/WnFbpv27BCQ/s400/matrixG.jpg" alt="" id="BLOGGER_PHOTO_ID_5231668413890719346" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SJqetQ62FeI/AAAAAAAAAdA/1wfI8RGRISE/s1600-h/matrixN.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SJqetQ62FeI/AAAAAAAAAdA/1wfI8RGRISE/s400/matrixN.jpg" alt="" id="BLOGGER_PHOTO_ID_5231668417617335778" border="0" /&gt;&lt;/a&gt;After this, we calculate the object's shape from the normal vectors using the following equations.&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SJqetUY-MII/AAAAAAAAAdI/CfqP7DXq8DM/s1600-h/equations.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SJqetUY-MII/AAAAAAAAAdI/CfqP7DXq8DM/s400/equations.jpg" alt="" id="BLOGGER_PHOTO_ID_5231668418549002370" border="0" /&gt;&lt;/a&gt;&lt;span style="font-size:85%;"&gt;source: &lt;span style="color: rgb(255, 204, 0);"&gt;M. Soriano, &lt;span style="font-style: italic;"&gt;A13 - Photometric Stereo.pdf&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;____________________________________________________________________&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//load images&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;loadmatfile('Photos.mat');&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//enter V values&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;V1 = [0.085832 0.17365 0.98106];&lt;/span&gt; &lt;span style="font-style: italic;"&gt;&lt;br /&gt;V2 = [0.085832 -0.17365 0.98106];&lt;/span&gt; &lt;span style="font-style: italic;"&gt;&lt;br /&gt;V3 = [0.17365 0 0.98481];&lt;/span&gt; &lt;span style="font-style: italic;"&gt;&lt;br /&gt;V4 = [0.16318 -0.34202 0.92542];&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;V = [V1;V2;V3;V4];&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//make matrix I&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;I1 = I1(:)';&lt;/span&gt; &lt;span style="font-style: italic;"&gt;&lt;br /&gt;I2 = I2(:)';&lt;/span&gt; &lt;span style="font-style: italic;"&gt;&lt;br /&gt;I3 = I3(:)';&lt;/span&gt; &lt;span style="font-style: italic;"&gt;&lt;br /&gt;I4 = I4(:)';&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;I = [I1;I2;I3;I4];&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;a = 1e-6;&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;//additive factor&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;g = inv(V'*V)*V'*I; &lt;/span&gt; &lt;span style="font-style: italic;"&gt;&lt;br /&gt;mod = sqrt((g(1,:).*g(1,:))+(g(2,:).*g(2,:))+(g(3,:).*g(3,:)));&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;//length of g&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;mod = mod+a;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;for i = 1:3&lt;/span&gt; &lt;span style="font-style: italic;"&gt;&lt;br /&gt;n(i,:) = g(i,:)./mod;&lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt; //calculate normal vectors&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;end&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;nz = n(3,:)+a;&lt;/span&gt; &lt;span style="font-style: italic;"&gt;&lt;br /&gt;dfx = -n(1,:)./nz;&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;//partial differentiation&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;dfy = -n(2,:)./nz;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;z1 = matrix(dfx,128,128);&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;//reshape the matrix to 128x128&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;z2 = matrix(dfy,128,128);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;int1 = cumsum(z1,2); &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//a simpler way to integrate: cumulative sum&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;int2 = cumsum(z2,1);&lt;/span&gt; &lt;span style="font-style: italic;"&gt;&lt;br /&gt;z = int1+int2;&lt;/span&gt; &lt;span style="font-style: italic;"&gt;&lt;br /&gt;scf(0); plot3d(1:128, 1:128, z);&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;//show reconstruction&lt;/span&gt;&lt;br /&gt;____________________________________________________________________&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);font-size:130%;" &gt;RESULTS:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;4 sample images&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SJrBhpDcZeI/AAAAAAAAAd4/Lvlg1PkjNUg/s1600-h/circle1.gif"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SJrBhpDcZeI/AAAAAAAAAd4/Lvlg1PkjNUg/s400/circle1.gif" alt="" id="BLOGGER_PHOTO_ID_5231706700844393954" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SJrBhkJjFUI/AAAAAAAAAeA/Hr99oUdjK98/s1600-h/circle2.gif"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SJrBhkJjFUI/AAAAAAAAAeA/Hr99oUdjK98/s400/circle2.gif" alt="" id="BLOGGER_PHOTO_ID_5231706699527820610" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SJrBhoriULI/AAAAAAAAAeI/SXCd3LHYuLw/s1600-h/circle3.gif"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SJrBhoriULI/AAAAAAAAAeI/SXCd3LHYuLw/s400/circle3.gif" alt="" id="BLOGGER_PHOTO_ID_5231706700744118450" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SJrBhlXe4bI/AAAAAAAAAeQ/VTWXampfMdc/s1600-h/circle4.gif"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SJrBhlXe4bI/AAAAAAAAAeQ/VTWXampfMdc/s400/circle4.gif" alt="" id="BLOGGER_PHOTO_ID_5231706699854700978" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;reconstructed image&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SJq-PvxrieI/AAAAAAAAAdw/CDYtF_GLaXU/s1600-h/sphere2.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 354px; height: 187px;" src="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SJq-PvxrieI/AAAAAAAAAdw/CDYtF_GLaXU/s400/sphere2.jpg" alt="" id="BLOGGER_PHOTO_ID_5231703094876408290" border="0" /&gt;&lt;/a&gt;This 3D image clearly looks like a sphere. The cross mark at the center is also observed. Thus we can conclude that our image was properly reconstructed in 3d using the photometric stereo technique.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;____________________________________________________________________&lt;br /&gt;&lt;br /&gt;I give myself &lt;span style="color: rgb(255, 204, 0);"&gt;10 points&lt;/span&gt; for this activity since the sphere was properly reconstructed. Thanks to &lt;span style="color: rgb(255, 204, 0);"&gt;Jeric Tugaff, Benj Palmares, and Mark Bejemino&lt;/span&gt; for their help in this activity.&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/223420158170109027-1631068110810023248?l=cole-ap186.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cole-ap186.blogspot.com/feeds/1631068110810023248/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=223420158170109027&amp;postID=1631068110810023248' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/223420158170109027/posts/default/1631068110810023248'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/223420158170109027/posts/default/1631068110810023248'/><link rel='alternate' type='text/html' href='http://cole-ap186.blogspot.com/2008/08/activity-13-photometric-stereo.html' title='Activity 13: Photometric Stereo'/><author><name>Cole</name><uri>http://www.blogger.com/profile/17840780106218077983</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://2.bp.blogspot.com/_6ZpN6X5LZPw/SeFgyvHYwpI/AAAAAAAAAmc/H76Ym0zH_Mw/S220/fabros05+-+Copy.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_6ZpN6X5LZPw/SJqes65FrtI/AAAAAAAAAco/FW8pjohxIsU/s72-c/matrixV.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-223420158170109027.post-3544032923109186793</id><published>2008-08-03T12:20:00.000-07:00</published><updated>2008-09-15T17:18:06.197-07:00</updated><title type='text'>Activity 12: Correcting Geometric Distortions</title><content type='html'>&lt;div style="text-align: justify;"&gt;In this activity, we aim to correct geomertic distortions produced by the camera. A sample distorted image is given and is shown below. We need to make the straight lines look straight.&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SJVihK8C-xI/AAAAAAAAAcg/T99MCbOUQPg/s1600-h/distorted+capiz+window.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SJVihK8C-xI/AAAAAAAAAcg/T99MCbOUQPg/s400/distorted+capiz+window.jpg" alt="" id="BLOGGER_PHOTO_ID_5230194864272112402" border="0" /&gt;&lt;/a&gt;&lt;span style="color: rgb(153, 153, 153);font-size:130%;" &gt;Procedure:&lt;/span&gt;&lt;br /&gt;1. Using the given image, we count the number of pixels down and across one box where the grid is most undistorted. Or we can capture another image of a regular grid. Just make sure that the image plane is parallel to the grid plane.&lt;br /&gt;2. We generate the ideal grid vertex coordinates and compute coefficients c1 to c8.&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SJVhaeqkFAI/AAAAAAAAAcI/C7cDRN5ki_g/s1600-h/matrix.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SJVhaeqkFAI/AAAAAAAAAcI/C7cDRN5ki_g/s400/matrix.jpg" alt="" id="BLOGGER_PHOTO_ID_5230193649796781058" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;3. Pixel per pixel in the ideal image, use equations 8 and 9 to determine the location of a point in the distorted image.&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SJVhad1Z2rI/AAAAAAAAAcQ/uCTHj3JdYeM/s1600-h/xy.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SJVhad1Z2rI/AAAAAAAAAcQ/uCTHj3JdYeM/s400/xy.jpg" alt="" id="BLOGGER_PHOTO_ID_5230193649573812914" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;4. 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 equation 10. In pixel locations where there are no transferred pixels, interpolate the graylevel values from the neighboring filled pixels.&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SJVhavhAYoI/AAAAAAAAAcY/5jWsnojrVKY/s1600-h/nu.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SJVhavhAYoI/AAAAAAAAAcY/5jWsnojrVKY/s400/nu.jpg" alt="" id="BLOGGER_PHOTO_ID_5230193654320095874" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;source:&lt;span style="color: rgb(255, 204, 0);"&gt; M. Soriano,&lt;span style="font-style: italic;"&gt; A12 - Correcting Geometric Distortions.pdf&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;____________________________________________________________________&lt;br /&gt;&lt;br /&gt;The resulting enhanced image is shown below. There were still some pixels that were not replaced to the proper location but the distortions were corrected. I give myself &lt;span style="color: rgb(255, 204, 0);"&gt;9 points&lt;/span&gt; for this activity since the enhanced image was not perfectly done. My collaborators for this activity were &lt;span style="color: rgb(255, 204, 0);"&gt;Mark Leo Bejemino and Jeric Tugaff.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SJyDlppm_pI/AAAAAAAAAeY/scxZR4exwCg/s1600-h/enhanced.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SJyDlppm_pI/AAAAAAAAAeY/scxZR4exwCg/s400/enhanced.jpg" alt="" id="BLOGGER_PHOTO_ID_5232201549956447890" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/223420158170109027-3544032923109186793?l=cole-ap186.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cole-ap186.blogspot.com/feeds/3544032923109186793/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=223420158170109027&amp;postID=3544032923109186793' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/223420158170109027/posts/default/3544032923109186793'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/223420158170109027/posts/default/3544032923109186793'/><link rel='alternate' type='text/html' href='http://cole-ap186.blogspot.com/2008/08/activity-12-correcting-geometric.html' title='Activity 12: Correcting Geometric Distortions'/><author><name>Cole</name><uri>http://www.blogger.com/profile/17840780106218077983</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://2.bp.blogspot.com/_6ZpN6X5LZPw/SeFgyvHYwpI/AAAAAAAAAmc/H76Ym0zH_Mw/S220/fabros05+-+Copy.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_6ZpN6X5LZPw/SJVihK8C-xI/AAAAAAAAAcg/T99MCbOUQPg/s72-c/distorted+capiz+window.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-223420158170109027.post-2746016853531068114</id><published>2008-07-29T16:27:00.000-07:00</published><updated>2008-07-30T17:34:55.522-07:00</updated><title type='text'>Activity 11: Camera Calibration</title><content type='html'>&lt;div style="text-align: justify;"&gt;In this activity, we will try to model the physical processes involved in the geometric aspects of image formation. We will try to calibrate the camera by looking at corresponding world points and image points.&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;An image is a projection of brightness values from surfaces existing in 3D world space to 2D sensor space. One whole dimension is lost in the projection. Nevertheless, under certain constraints it is possible to recover the lost information. The process involves carefully calibrating the camera by taking several views of a scene.&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;First, we take a picture of a checkerboard pattern, also known as a Tsai grid, using an ordinary digital camera. We pick an origin and 20-25 more points in the image while taking note of its real world coordinates. The squares are 1x1 inches thick. Using the &lt;span style="font-style: italic; color: rgb(255, 204, 0);"&gt;locate&lt;/span&gt; function in Scilab, we get the image coordinates of the same 20-25 points we picked. Next, we set up the matrix &lt;span style="color: rgb(255, 204, 0);"&gt;Q&lt;/span&gt; shown by equation 13 for values of i from 1 to 25. We then solve for &lt;span style="color: rgb(255, 204, 0);"&gt;a&lt;/span&gt; using equation 15 and then plug its elements into equations 11 and 12. For the last two equations, we set a_34 to be equal to 1.&lt;br /&gt;&lt;br /&gt;&lt;img src="file:///C:/Users/Acer/AppData/Local/Temp/moz-screenshot.jpg" alt="" /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SI69LHkjmlI/AAAAAAAAAbY/43GOAj3J1_E/s1600-h/13.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 661px; height: 287px;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SI69LHkjmlI/AAAAAAAAAbY/43GOAj3J1_E/s400/13.jpg" alt="" id="BLOGGER_PHOTO_ID_5228324216132311634" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SI69LkAaS_I/AAAAAAAAAbg/Zyzj5b7dV7U/s1600-h/15.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SI69LkAaS_I/AAAAAAAAAbg/Zyzj5b7dV7U/s400/15.jpg" alt="" id="BLOGGER_PHOTO_ID_5228324223765335026" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SI69L2ZFmyI/AAAAAAAAAbo/LcOFzwh3mk4/s1600-h/11.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SI69L2ZFmyI/AAAAAAAAAbo/LcOFzwh3mk4/s400/11.jpg" alt="" id="BLOGGER_PHOTO_ID_5228324228700674850" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 153, 153);font-size:180%;" &gt;RESULTS:&lt;/span&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;Shown below is the Tsai grid together with the points &lt;span style="color: rgb(255, 0, 0);"&gt;(red)&lt;/span&gt; we wish to use in the calibration. The origin is set at (0,0,0). The left side of the board is x, the right side is y, and the vertical axis is z.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SI-zT3E3O9I/AAAAAAAAAb4/0e62lXqDauc/s1600-h/tsai+grid.JPG"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 566px; height: 517px;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SI-zT3E3O9I/AAAAAAAAAb4/0e62lXqDauc/s400/tsai+grid.JPG" alt="" id="BLOGGER_PHOTO_ID_5228594846183668690" border="0" /&gt;&lt;/a&gt;&lt;span style="font-style: italic; color: rgb(255, 204, 0);"&gt;(xo,yo,zo)&lt;/span&gt;&lt;br /&gt;1. (0,0,2)&lt;br /&gt;2. (0,0,5)&lt;br /&gt;3. (0,0,9)&lt;br /&gt;4. (0,0,12)      &lt;br /&gt;5. (2,0,1)&lt;br /&gt;6. (5,0,2)&lt;br /&gt;7. (3,0,4)&lt;br /&gt;8. (2,0,7)&lt;br /&gt;9. (7,0,6)&lt;br /&gt;10. (4,0,6) &lt;/div&gt;11. (6,0,9)&lt;br /&gt;12. (2,0,10)&lt;br /&gt;13. (8,0,11)&lt;br /&gt;14. (1,0,3)&lt;br /&gt;15. (0,0,0)&lt;br /&gt;16. (0,6,12)&lt;br /&gt;17. (0,8,10)&lt;br /&gt;18. (0,3,10)&lt;br /&gt;19. (0,2,1)&lt;br /&gt;20. (0,4,3)&lt;br /&gt;21. (0,7,6)&lt;br /&gt;22. (0,5,7)&lt;br /&gt;23. (0,6,2)&lt;br /&gt;24. (0,4,6)&lt;br /&gt;25. (0,2,8)&lt;br /&gt;&lt;br /&gt;Using &lt;span style="font-style: italic; color: rgb(255, 204, 0);"&gt;locate&lt;/span&gt;, their corresponding 2D image coordinates are as follows:&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(255, 204, 0);"&gt;(yi, zi)&lt;/span&gt;&lt;br /&gt;(130.53181, 67.545109)&lt;br /&gt;(130.53181, 114.07882)&lt;br /&gt;(131.00665, 178.18139)&lt;br /&gt;(130.53181, 229.46344)&lt;br /&gt;(106.31529, 45.702754)&lt;br /&gt;(65.954416, 51.40076)&lt;br /&gt;(92.545109, 90.811966)&lt;br /&gt;(105.36562, 143.04368)&lt;br /&gt;(33.665717, 115.50332)&lt;br /&gt;(78.300095, 122.151)&lt;br /&gt;(47.910731, 172.95821)&lt;br /&gt;(104.89079, 194.32574)&lt;br /&gt;(15.147198, 209.52042)&lt;br /&gt;(118.18613, 79.890788)&lt;br /&gt;(130.05698, 37.155745)&lt;br /&gt;(211.25356, 228.51377)&lt;br /&gt;(241.16809, 188.62773)&lt;br /&gt;(168.04368, 192.90123)&lt;br /&gt;(152.849, 45.702754)&lt;br /&gt;(178.96486, 70.868946)&lt;br /&gt;(223.12441, 115.50332)&lt;br /&gt;(194.63438, 136.87085)&lt;br /&gt;(206.03039, 47.127255)&lt;br /&gt;(179.91453, 122.151)&lt;br /&gt;(155.22317, 159.18803)&lt;br /&gt;&lt;br /&gt;We set up matrix Q given by equation 13 and solving for a using equation 15 will give us the elements of matrix a.&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;a  =&lt;/span&gt;&lt;br /&gt;- 13.945461&lt;br /&gt;8.8516947&lt;br /&gt;- 0.6362905&lt;br /&gt;130.1377&lt;br /&gt;- 4.0454015&lt;br /&gt;- 4.1159857&lt;br /&gt;14.796702&lt;br /&gt;37.040714&lt;br /&gt;- 0.0178636&lt;br /&gt;- 0.0176363&lt;br /&gt;- 0.0052799&lt;br /&gt;&lt;br /&gt;Using these values, we plug them into equations 11 and 12 and see whether these new yi's and zi's are close to the values previously obtained.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(255, 204, 0);"&gt;(new_yi, new_zi)&lt;/span&gt;&lt;br /&gt;(130.24043, 67.345268)&lt;br /&gt;(130.39869, 114.03467)&lt;br /&gt;(130.61791, 178.7028)&lt;br /&gt;(130.78881, 229.11771)&lt;br /&gt;(105.9554, 45.617241)&lt;br /&gt;(65.69975, 51.556447)&lt;br /&gt;(92.680325, 90.881065)&lt;br /&gt;(105.45811, 142.91477)&lt;br /&gt;(34.035999, 115.62425)&lt;br /&gt;(78.64952, 122.2471)&lt;br /&gt;(48.193941, 172.64721)&lt;br /&gt;(105.19649, 194.0998)&lt;br /&gt;(14.486398, 209.56016)&lt;br /&gt;(118.26943, 80.084525)&lt;br /&gt;(130.1377, 37.040714)&lt;br /&gt;(211.37148, 228.57471)&lt;br /&gt;(241.39165, 188.6588)&lt;br /&gt;(168.09928, 193.06864)&lt;br /&gt;(153.42664, 45.448497)&lt;br /&gt;(179.10783, 71.109685)&lt;br /&gt;(222.85396, 114.82174)&lt;br /&gt;(194.25085, 137.20802)&lt;br /&gt;(205.9424, 47.461688)&lt;br /&gt;(180.14164, 121.80884)&lt;br /&gt;(154.74534, 159.5493)&lt;br /&gt;&lt;br /&gt;We can compute for the accuracy of the values we obtained by finding the difference between the original and new coordinates.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;diff  =&lt;/span&gt;&lt;br /&gt;- 0.2913883,  - 0.1998413&lt;br /&gt;- 0.1331196,  - 0.0441513&lt;br /&gt;- 0.3887400,    0.5214104&lt;br /&gt;0.2569913,  - 0.3457294&lt;br /&gt;- 0.3598862,  - 0.0855131&lt;br /&gt;- 0.2546660,    0.1556874&lt;br /&gt;0.1352158,    0.0690990&lt;br /&gt;0.0924834,  - 0.1289110&lt;br /&gt;0.3702816,    0.1209236&lt;br /&gt;0.3494252,    0.0961056&lt;br /&gt;0.2832094,  - 0.3110003&lt;br /&gt;0.3057051,  - 0.2259333&lt;br /&gt;- 0.6608001,    0.0397375&lt;br /&gt;0.0832921,    0.1937365&lt;br /&gt;0.0807186,  - 0.1150312&lt;br /&gt;0.1179217,    0.0609362&lt;br /&gt;0.2235590,    0.0310715&lt;br /&gt;0.0556003,    0.1674038&lt;br /&gt;0.5776353,  - 0.2542572&lt;br /&gt;0.1429685,    0.2407392&lt;br /&gt;- 0.2704486,  - 0.6815880&lt;br /&gt;- 0.3835267,    0.3371792&lt;br /&gt;- 0.0879896,    0.3344329&lt;br /&gt;0.2271150,  - 0.3421524&lt;br /&gt;- 0.4778311,    0.3612629&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;We get a mean of &lt;span style="color: rgb(255, 204, 0);"&gt;0.26442074&lt;/span&gt; difference in yi and a mean of &lt;span style="color: rgb(255, 204, 0);"&gt;0.218553368&lt;/span&gt;       difference in zi. Thus, we can say that our calibration is very accurate since there is only a difference of less than a pixel in the values gathered.&lt;br /&gt;____________________________________________________________________&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;im = gray_imread('tsai grid.jpg');&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;imshow(im);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;x = locate(25,1);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;yi = x(1,:);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;zi = x(2,:);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;xo = [0 0 0 0 2 5 3 2 7 4 6 2 8 1 0 0 0 0 0 0 0 0 0 0 0];&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;yo = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 8 3 2 4 7 5 6 4 2];&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;zo = [2 5 9 12 1 2 4 7 6 6 9 10 11 3 0 12 10 10 1 3 6 7 2 6 8];&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;for i = 1:length(xo)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;  Q((2*i)-1,:) = [xo(i) yo(i) zo(i) 1 0 0 0 0 -(yi(i)*xo(i)) -(yi(i)*yo(i)) -(yi(i)*zo(i))]; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;  Q(2*i,:) = [0 0 0 0 xo(i) yo(i) zo(i) 1 -(zi(i)*xo(i)) -(zi(i)*yo(i)) -(zi(i)*zo(i))];&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;  d((2*i)-1,:) = yi(i);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;  d(2*i,:) = zi(i);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;end&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;a = inv(Q'*Q)*Q'*d;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;for j = 1:length(xo)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;  yi_new(j,:) = ((a(1)*xo(j))+(a(2)*yo(j))+(a(3)*zo(j))+a(4))/((a(9)*xo(j))+(a(10)*yo(j))+(a(11)*zo(j))+1);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;  zi_new(j,:) = ((a(5)*xo(j))+(a(6)*yo(j))+(a(7)*zo(j))+a(8))/((a(9)*xo(j))+(a(10)*yo(j))+(a(11)*zo(j))+1);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;end&lt;/span&gt;&lt;br /&gt;____________________________________________________________________&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;To verify if the calibration is correct, we predict the image coordinates of some cornerpoints of the checkerboard which were not used in the calibration &lt;span style="color: rgb(255, 255, 0);"&gt;(yellow)&lt;/span&gt;. The number of points should be greater than 11. These points are, in world coordinates:&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SI-1hyC6vEI/AAAAAAAAAcA/aP34pLH13j0/s1600-h/tsai+grid.JPG"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SI-1hyC6vEI/AAAAAAAAAcA/aP34pLH13j0/s400/tsai+grid.JPG" alt="" id="BLOGGER_PHOTO_ID_5228597284374756418" border="0" /&gt;&lt;/a&gt;(3,0,8)&lt;br /&gt;(0,1,5)&lt;br /&gt;(0,4,4)&lt;br /&gt;(0,6,5)&lt;br /&gt;(0,3,9)&lt;br /&gt;(0,7,11)&lt;br /&gt;(4,0,12)&lt;br /&gt;(6,0,1)&lt;br /&gt;(8,0,5)&lt;br /&gt;(2,0,3)&lt;br /&gt;(5,0,5)&lt;br /&gt;(7,0,2)&lt;br /&gt;&lt;br /&gt;We predict that &lt;span style="color: rgb(255, 204, 0);"&gt;&lt;/span&gt;these points will be transformed into the following by using equations 11 and 12.&lt;br /&gt;(92.030252, 158.4637)&lt;br /&gt;(142.06384, 111.83289)&lt;br /&gt;(179.44842, 87.812934)&lt;br /&gt;(207.50173, 99.481483)&lt;br /&gt;(167.82, 175.48687)&lt;br /&gt;(226.15495, 208.91806)&lt;br /&gt;(77.116722, 229.33722)&lt;br /&gt;(51.635668, 31.057816)&lt;br /&gt;(18.52981, 94.693389)&lt;br /&gt;(105.79334, 77.32756)&lt;br /&gt;(64.717941, 102.67897)&lt;br /&gt;(36.148858, 44.327313)&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//prediction code&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;xo = [3 0 0 0 0 0 4 6 8 2 5 7];&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;yo = [0 1 4 6 3 7 0 0 0 0 0 0];&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;zo = [8 5 4 5 9 11 12 1 5 3 5 2];&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;a = [-13.945461 8.8516947 -0.6362905 130.1377 -4.0454015 -4.1159857 14.796702 37.040714 -0.0178636 -0.0176363 -0.0052799];&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;for j = 1:length(xo)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;yi(j,:) = ((a(1)*xo(j))+(a(2)*yo(j))+(a(3)*zo(j))+a(4))/((a(9)*xo(j))+(a(10)*yo(j))+(a(11)*zo(j))+1);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;zi(j,:) = ((a(5)*xo(j))+(a(6)*yo(j))+(a(7)*zo(j))+a(8))/((a(9)*xo(j))+(a(10)*yo(j))+(a(11)*zo(j))+1);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;end&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;After running the original code, these points were converted into:&lt;br /&gt;(91.919444, 158.17825)&lt;br /&gt;(141.77925, 111.69473)&lt;br /&gt;(179.29545, 87.811292)&lt;br /&gt;(207.46461, 99.490062)&lt;br /&gt;(167.2938, 175.12682)&lt;br /&gt;(225.77969, 208.89718)&lt;br /&gt;(76.901337, 228.70553)&lt;br /&gt;(51.993604, 31.260393)&lt;br /&gt;(18.750844, 94.88024)&lt;br /&gt;(105.83348, 77.396374)&lt;br /&gt;(64.879166, 102.73954)&lt;br /&gt;(36.482614, 44.520168)&lt;br /&gt;&lt;br /&gt;Again, we get the difference between the two sets of values and find the mean difference for yi and zi.&lt;br /&gt;mean difference for yi = &lt;span style="color: rgb(255, 204, 0);"&gt;0.234702 &lt;/span&gt;&lt;br /&gt;mean difference for zi = &lt;span style="color: rgb(255, 204, 0);"&gt;0.179843167&lt;/span&gt;&lt;br /&gt;____________________________________________________________________&lt;br /&gt;&lt;br /&gt;I give myself &lt;span style="color: rgb(255, 204, 0);"&gt;10 points&lt;/span&gt; for this activity since the results of the camera calibration was good. The values differed by a value that is less than 1 pixel. Good predictions resulted because of this. My collaborators for this activity were&lt;span style="color: rgb(255, 204, 0);"&gt; Jeric Tugaff and Julie Dado&lt;/span&gt;.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/223420158170109027-2746016853531068114?l=cole-ap186.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cole-ap186.blogspot.com/feeds/2746016853531068114/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=223420158170109027&amp;postID=2746016853531068114' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/223420158170109027/posts/default/2746016853531068114'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/223420158170109027/posts/default/2746016853531068114'/><link rel='alternate' type='text/html' href='http://cole-ap186.blogspot.com/2008/07/activity-11-camera-calibration.html' title='Activity 11: Camera Calibration'/><author><name>Cole</name><uri>http://www.blogger.com/profile/17840780106218077983</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://2.bp.blogspot.com/_6ZpN6X5LZPw/SeFgyvHYwpI/AAAAAAAAAmc/H76Ym0zH_Mw/S220/fabros05+-+Copy.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_6ZpN6X5LZPw/SI69LHkjmlI/AAAAAAAAAbY/43GOAj3J1_E/s72-c/13.jpg' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-223420158170109027.post-9176703950908135654</id><published>2008-07-22T11:16:00.000-07:00</published><updated>2008-10-08T19:49:15.788-07:00</updated><title type='text'>Activity 10: Preprocessing Handritten Text</title><content type='html'>&lt;div style="text-align: justify;"&gt;In this activity, we will try to extract handwritten text from an imaged document with lines. In handwriting recognition, individual examples of letters must be extracted. This is another real-world problem like Activity 9 wherein we will need to use all the image processing techniques that we have learned so far.&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;We are given two images to choose from. Both have handwritten text within lines. I will be using the 2nd image. It is shown below together with a cropped portion that we will be processing.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SIUtfvEkJTI/AAAAAAAAAZQ/4VWKes4TQks/s1600-h/Untitled_0001.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SIUtfvEkJTI/AAAAAAAAAZQ/4VWKes4TQks/s320/Untitled_0001.jpg" alt="" id="BLOGGER_PHOTO_ID_5225632965868135730" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SIXKuJaIzII/AAAAAAAAAaQ/UdAWPvVaNAo/s1600-h/im.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SIXKuJaIzII/AAAAAAAAAaQ/UdAWPvVaNAo/s320/im.jpg" alt="" id="BLOGGER_PHOTO_ID_5225805836781669506" border="0" /&gt;&lt;/a&gt;&lt;-- middle left portion                                    First, we have to remove the horizontal lines and isolate the text. We can do this by looking at its FT and masking the vertical lines in Fourier space since these correspond to the horizontal lines in image space. After inversion, the text should be isolated from the lines.  &lt;span style="color: rgb(255, 204, 0);"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;FT image&lt;/span&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SIXKucTtg7I/AAAAAAAAAaY/gpAy22xEIgU/s1600-h/FT.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SIXKucTtg7I/AAAAAAAAAaY/gpAy22xEIgU/s320/FT.jpg" alt="" id="BLOGGER_PHOTO_ID_5225805841854989234" border="0" /&gt;&lt;/a&gt;From this FT image, we need to mask the prominent frequencies in the vertical direction in order to isolate the text from the horizontal lines.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;MASKED FT image and ENHANCED image&lt;/span&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SIXKua1c40I/AAAAAAAAAag/wDby2dZBX0M/s1600-h/FT2.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SIXKua1c40I/AAAAAAAAAag/wDby2dZBX0M/s320/FT2.jpg" alt="" id="BLOGGER_PHOTO_ID_5225805841459635010" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SIXKu0-TySI/AAAAAAAAAao/CztteyT-PYI/s1600-h/enhanced.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SIXKu0-TySI/AAAAAAAAAao/CztteyT-PYI/s320/enhanced.jpg" alt="" id="BLOGGER_PHOTO_ID_5225805848476109090" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;im = gray_imread('im.jpg');&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;//size of image is 89 rows x 125 columns&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;IM = fftshift(fft2(im));&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;IM(1:44,62:63) = 0;&lt;br /&gt;IM(46:89,63:64) = 0;&lt;/span&gt;&lt;span style="font-style: italic;"&gt;&lt;br /&gt;F = real((IM).*conj(IM));&lt;/span&gt; &lt;span style="font-style: italic;"&gt;&lt;br /&gt;scf(0); imshow(log(F+1),[]); xset('colormap',jetcolormap(256));&lt;/span&gt;  &lt;span style="font-style: italic;"&gt;&lt;br /&gt;newim = abs(fft2(IM));&lt;/span&gt; &lt;span style="font-style: italic;"&gt;&lt;br /&gt;scf(1); imshow(newim,[]);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The line removal is not perfect but the words are still comprehensible. Next, we binarize the image and clean it of stray pixels, holes, and the like. However, the text is in black, so we have to invert first and make the text white and the background black before binarizing.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;BINARIZED image and CLEANED image&lt;/span&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SIXavSB2WLI/AAAAAAAAAaw/-hiRhc3QOIU/s1600-h/binary.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SIXavSB2WLI/AAAAAAAAAaw/-hiRhc3QOIU/s320/binary.jpg" alt="" id="BLOGGER_PHOTO_ID_5225823448461629618" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SIXavdC4fWI/AAAAAAAAAa4/I6jB4FuJ53g/s1600-h/cleaned.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SIXavdC4fWI/AAAAAAAAAa4/I6jB4FuJ53g/s320/cleaned.jpg" alt="" id="BLOGGER_PHOTO_ID_5225823451418754402" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The thickness of most of the letters are already at 1 pixel after binarization. Thus, we only need to &lt;span style="color: rgb(255, 204, 0);"&gt;close&lt;/span&gt; the gaps made by the removal of the horizontal lines. We use the &lt;span style="color: rgb(255, 204, 0);"&gt;closing operation&lt;/span&gt; using a &lt;span style="color: rgb(255, 204, 0);"&gt;4x1 rectangle&lt;/span&gt; structuring element and the result is shown in the right image above. Unfortunately, this is the best we can do without making the words indistinguishable. The words, "remote", "cable", and a hint of "control" can still be recognized. By using the &lt;span style="color: rgb(255, 204, 0); font-style: italic;"&gt;bwlabel &lt;/span&gt;function, we assign a label to each letter (or in this case, to each cluster of white pixels).&lt;br /&gt;&lt;br /&gt;No. of clusters = &lt;span style="color: rgb(255, 204, 0);"&gt;84&lt;/span&gt;&lt;br /&gt;No. of actual letters in text = &lt;span style="color: rgb(255, 204, 0);"&gt;46&lt;/span&gt;&lt;br /&gt;Error = &lt;span style="color: rgb(255, 204, 0);"&gt;82.6%&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;im = gray_imread('enhanced.jpg');&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;im = 1 - im;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;im = im2bw(im,0.7);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;scf(0); imshow(im);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;SE = ones(4,1);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;im = dilate(im,SE);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;im = erode(im,SE);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;scf(1); imshow(im);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;[L,n] = bwlabel(im);&lt;/span&gt;&lt;br /&gt;____________________________________________________________________&lt;br /&gt;&lt;br /&gt;I give myself &lt;span style="color: rgb(255, 204, 0);"&gt;10 points&lt;/span&gt; for this activity even if the result of the cleaning part is not so nice. The horizontal lines were removed and the words are still comprehensible after doing the morphological operations. My collaborator for this activity is &lt;span style="color: rgb(255, 204, 0);"&gt;Julie Dado&lt;/span&gt;.&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/223420158170109027-9176703950908135654?l=cole-ap186.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cole-ap186.blogspot.com/feeds/9176703950908135654/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=223420158170109027&amp;postID=9176703950908135654' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/223420158170109027/posts/default/9176703950908135654'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/223420158170109027/posts/default/9176703950908135654'/><link rel='alternate' type='text/html' href='http://cole-ap186.blogspot.com/2008/07/activity-10-preprocessing-handritten.html' title='Activity 10: Preprocessing Handritten Text'/><author><name>Cole</name><uri>http://www.blogger.com/profile/17840780106218077983</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://2.bp.blogspot.com/_6ZpN6X5LZPw/SeFgyvHYwpI/AAAAAAAAAmc/H76Ym0zH_Mw/S220/fabros05+-+Copy.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_6ZpN6X5LZPw/SIUtfvEkJTI/AAAAAAAAAZQ/4VWKes4TQks/s72-c/Untitled_0001.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-223420158170109027.post-6228424254406105970</id><published>2008-07-17T20:50:00.000-07:00</published><updated>2008-10-08T19:50:58.297-07:00</updated><title type='text'>Activity 9: Binary operations</title><content type='html'>&lt;div style="text-align: justify;"&gt;In this activity, we aim to use what we have learned so far in finding the area of a piece of circular punched paper. This may seem easy but these many circles are scattered: some are touching or even on top of each other. We will therefore analyze several regions of interest in one image.&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;PROCEDURE:&lt;/span&gt;&lt;br /&gt;1. If the image is large, divide it into several &lt;span style="color: rgb(255, 204, 0);"&gt;256x256&lt;/span&gt; sub-images so that less memory space is used. Another way is to just resize the image. Open the image in grayscale using &lt;span style="font-style: italic; color: rgb(255, 204, 0);"&gt;im2gray&lt;/span&gt; or &lt;span style="font-style: italic; color: rgb(255, 204, 0);"&gt;gray_imread&lt;/span&gt;.&lt;br /&gt;2. Plot the histogram of the sub-image and determine its thresholding value. Binarize the image using &lt;span style="font-style: italic; color: rgb(255, 204, 0);"&gt;im2bw&lt;/span&gt;.&lt;br /&gt;3. Do morphological operations to remove isolated pixels, separate connected blobs or fill out holes. The &lt;span style="color: rgb(153, 153, 153);"&gt;opening&lt;/span&gt; and &lt;span style="color: rgb(153, 153, 153);"&gt;closing&lt;/span&gt; operations can do this "image cleaning." The opening operation is just an erosion followed by a dilation. On the other hand, the closing operation is a dilation followed by an erosion.&lt;br /&gt;4.  Use &lt;span style="font-style: italic; color: rgb(255, 204, 0);"&gt;bwlabel&lt;/span&gt; to label each blob on the image.&lt;br /&gt;5. Find the areas of each disk of punched paper. Repeat for the other sub-images and give the best estimate of the area.&lt;br /&gt;____________________________________________________________________&lt;br /&gt;&lt;br /&gt;The image used in this activity and one of its sub-images are shown below.&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SH80TtGsBlI/AAAAAAAAAYg/C2P0mQzvGWs/s1600-h/Circles002.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SH80TtGsBlI/AAAAAAAAAYg/C2P0mQzvGWs/s320/Circles002.jpg" alt="" id="BLOGGER_PHOTO_ID_5223951605902870098" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SH80T8Ih-1I/AAAAAAAAAYo/c8iGuEqJqw0/s1600-h/c2_01.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 321px; height: 321px;" src="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SH80T8Ih-1I/AAAAAAAAAYo/c8iGuEqJqw0/s320/c2_01.jpg" alt="" id="BLOGGER_PHOTO_ID_5223951609937132370" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;After binarization and morphology (closing first then opening operations),&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SH89oCsNzEI/AAAAAAAAAYw/LV5HRV6yDbM/s1600-h/1.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 255px; height: 252px;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SH89oCsNzEI/AAAAAAAAAYw/LV5HRV6yDbM/s320/1.jpg" alt="" id="BLOGGER_PHOTO_ID_5223961850899450946" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SH89oEXZPII/AAAAAAAAAY4/YTIBT40q1LU/s1600-h/2.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 254px; height: 252px;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SH89oEXZPII/AAAAAAAAAY4/YTIBT40q1LU/s320/2.jpg" alt="" id="BLOGGER_PHOTO_ID_5223961851348991106" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;HISTOGRAM OF AREAS&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SH89ocNIOzI/AAAAAAAAAZA/2eQ2ef_OUsk/s1600-h/hist.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 434px; height: 345px;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SH89ocNIOzI/AAAAAAAAAZA/2eQ2ef_OUsk/s320/hist.jpg" alt="" id="BLOGGER_PHOTO_ID_5223961857748384562" border="0" /&gt;&lt;/a&gt;From the histogram, it seems as if the correct value of the area lies &lt;span style="color: rgb(255, 204, 0);"&gt;between 500 and 600 pixels&lt;/span&gt; since the histogram bars are highest around these values. The values smaller than 500 are those disks that got cropped off when the sub-images were created or those that do not look like a circle anymore after the morphological operations. Values larger than 600 are those overlapping disks or those too close together that they got combined by the morphological operations. After removing these values, we get the mean and standard deviation. These tell us the best estimate for the area of an individual punched paper.&lt;br /&gt;&lt;br /&gt;Mean area = &lt;span style="color: rgb(255, 204, 0);"&gt;538 pixels&lt;/span&gt;&lt;br /&gt;Standard deviation = &lt;span style="color: rgb(255, 204, 0);"&gt;24.83&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;We need to verify if this value for the area is acceptable. We can do this by finding non-overlapping disks and then calculating the areas.&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SH9Bfv-a_OI/AAAAAAAAAZI/KxH4ESabL1c/s1600-h/c2_012.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SH9Bfv-a_OI/AAAAAAAAAZI/KxH4ESabL1c/s320/c2_012.jpg" alt="" id="BLOGGER_PHOTO_ID_5223966106483096802" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;Mean area = &lt;span style="color: rgb(255, 204, 0);"&gt;549 pixels&lt;/span&gt;&lt;br /&gt;Standard deviation = &lt;span style="color: rgb(255, 204, 0);"&gt;13.05&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;error for area = &lt;span style="color: rgb(255, 204, 0);"&gt;2%&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Also, the standard deviations are quite close. Smaller standard deviations indicate that the other areas are close to the mean value.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;____________________________________________________________________&lt;br /&gt;&lt;br /&gt;stacksize(4e7);&lt;br /&gt;&lt;br /&gt;subimg = 11; &lt;span style="color: rgb(51, 204, 0);"&gt;//no. of sub images&lt;/span&gt;&lt;br /&gt;c = 1;&lt;br /&gt;for i = 1:subimg&lt;br /&gt;im = gray_imread('c2_0'+string(i)+'.jpg');&lt;br /&gt;im = im2bw(im, 0.85); &lt;span style="color: rgb(51, 204, 0);"&gt;//convert to BW with corresponding threshold value&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//scf(0); imshow(im);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;image = ones(5,5);&lt;br /&gt;SE = mkfftfilter(image,'binary',2); &lt;span style="color: rgb(51, 204, 0);"&gt;//structuring element&lt;/span&gt;&lt;br /&gt;im = dilate(im,SE); &lt;span style="color: rgb(51, 204, 0);"&gt;//closing operation&lt;/span&gt;&lt;br /&gt;im = erode(im,SE);&lt;br /&gt;im = erode(im,SE); &lt;span style="color: rgb(51, 204, 0);"&gt;//opening operation&lt;/span&gt;&lt;br /&gt;im = dilate(im,SE);&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//scf(i); imshow(im);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;[L,n] = bwlabel(im); &lt;span style="color: rgb(51, 204, 0);"&gt;//label the individual blobs&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//area calculation of individual blobs&lt;/span&gt;&lt;br /&gt;for j = 1:n&lt;br /&gt;roi = (L==j);&lt;br /&gt;A(c) = sum(roi);&lt;br /&gt;c = c + 1;&lt;br /&gt;end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;scf(12); histplot(length(A),A);&lt;br /&gt;title('Histogram of disk areas');&lt;br /&gt;xlabel('bins'); ylabel('frequency');&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//remove too small and too large areas&lt;/span&gt;&lt;br /&gt;range_area = find(A&gt;500 &amp;amp; A&lt;600);&lt;br /&gt;mean_area = sum(A(range_area))/length(range_area); &lt;span style="color: rgb(51, 204, 0);"&gt;//mean area&lt;/span&gt;&lt;br /&gt;std_area = stdev(A(range_area)); &lt;span style="color: rgb(51, 204, 0);"&gt;//standard deviation&lt;/span&gt;&lt;br /&gt;____________________________________________________________________&lt;br /&gt;&lt;br /&gt;I give myself &lt;span style="color: rgb(255, 204, 0);"&gt;10 points&lt;/span&gt; for this activity since a good estimate of the area of the punched paper was given. Thanks to &lt;span style="color: rgb(255, 204, 0);"&gt;Jeric Tugaff&lt;/span&gt; for help in the histogram and in removing the unwanted small and big area values.&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/223420158170109027-6228424254406105970?l=cole-ap186.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cole-ap186.blogspot.com/feeds/6228424254406105970/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=223420158170109027&amp;postID=6228424254406105970' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/223420158170109027/posts/default/6228424254406105970'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/223420158170109027/posts/default/6228424254406105970'/><link rel='alternate' type='text/html' href='http://cole-ap186.blogspot.com/2008/07/activity-9-binary-operations.html' title='Activity 9: Binary operations'/><author><name>Cole</name><uri>http://www.blogger.com/profile/17840780106218077983</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://2.bp.blogspot.com/_6ZpN6X5LZPw/SeFgyvHYwpI/AAAAAAAAAmc/H76Ym0zH_Mw/S220/fabros05+-+Copy.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_6ZpN6X5LZPw/SH80TtGsBlI/AAAAAAAAAYg/C2P0mQzvGWs/s72-c/Circles002.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-223420158170109027.post-7407065389277551137</id><published>2008-07-15T16:05:00.000-07:00</published><updated>2008-09-15T17:20:36.688-07:00</updated><title type='text'>Activity 8: Morphological Operations</title><content type='html'>&lt;div style="text-align: justify;"&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;Morphology&lt;/span&gt; refers to shape or structure. In image processing, classical morphological operations are treatments done on &lt;span style="color: rgb(255, 204, 0);"&gt;binary images&lt;/span&gt;, particularly aggregates of 1's that form a particular shape, to improve the image for further processing or to extract information from it. All morphological operations affect the shape of the image in some way, for example, the shapes may be expanded, thinned, internal holes could be closed, disconnected blobs can be joined. In a binary image, all pixels which are “OFF” or have value equal to zero are considered background and all pixels which are “ON” or 1 are foreground.&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;Source: &lt;span style="color: rgb(255, 204, 0);"&gt;M. Soriano, &lt;span style="font-style: italic;"&gt;A8 - Morphological Operations.pdf&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;In this activity, we will investigate two kinds of morphological operations: &lt;span style="color: rgb(255, 204, 0);"&gt;dilation and erosion&lt;/span&gt;. These have functions in Scilab and we will apply them to simple geometric shapes for now.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:180%;"&gt;&lt;span style="color: rgb(153, 153, 153);"&gt;(1) Dilation&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;In set theory,&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SHxP9Li8VsI/AAAAAAAAAP4/L746kVmkr6w/s1600-h/dilation.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 586px; height: 337px;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SHxP9Li8VsI/AAAAAAAAAP4/L746kVmkr6w/s400/dilation.png" alt="" id="BLOGGER_PHOTO_ID_5223137580332897986" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 153, 153);font-size:180%;" &gt;(2) Erosion&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The erosion operator is defined by&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SH1TRyMnpsI/AAAAAAAAATo/CV--ptSp19o/s1600-h/erosion.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 585px; height: 410px;" src="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SH1TRyMnpsI/AAAAAAAAATo/CV--ptSp19o/s400/erosion.png" alt="" id="BLOGGER_PHOTO_ID_5223422707817227970" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;We apply this to 5 shapes: &lt;span style="color: rgb(255, 204, 0);"&gt;50x50 pixel square, triangle (50 pixel base, 30 pixel height), circle with radius 25, hollow square (60x60 pixels with 4 pixel wide edges), and plus sign&lt;/span&gt; &lt;span style="color: rgb(255, 204, 0);"&gt;(8 pixels wide and 50 pixels long)&lt;/span&gt; using 4 different structuring elements, namely, &lt;span style="color: rgb(255, 204, 0);"&gt;4x4 square, 2x4 rectangle, 4x2 rectangle, and a 5 pixel long, 1 pixel thick cross&lt;/span&gt;. We have already predicted the outcome of this operation on these images and we will now verify them using Scilab. The predictions are submitted separately on a sheet of yellow pad paper.&lt;br /&gt;&lt;br /&gt;ORIGINAL SHAPES&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SHxXyMkRNtI/AAAAAAAAAQQ/cBZDZC72824/s1600-h/s.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 101px; height: 101px;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SHxXyMkRNtI/AAAAAAAAAQQ/cBZDZC72824/s400/s.png" alt="" id="BLOGGER_PHOTO_ID_5223146187721357010" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SHxirZnWM9I/AAAAAAAAAQ4/9GmyouT4eKo/s1600-h/tri.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 133px; height: 102px;" src="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SHxirZnWM9I/AAAAAAAAAQ4/9GmyouT4eKo/s400/tri.png" alt="" id="BLOGGER_PHOTO_ID_5223158165592749010" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SHxshni-PnI/AAAAAAAAARo/aiOGGx9tk78/s1600-h/circle.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 102px; height: 102px;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SHxshni-PnI/AAAAAAAAARo/aiOGGx9tk78/s400/circle.png" alt="" id="BLOGGER_PHOTO_ID_5223168992650083954" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SHx00tLnVrI/AAAAAAAAASw/kUMK4Cf90E0/s1600-h/hollow.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 103px; height: 103px;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SHx00tLnVrI/AAAAAAAAASw/kUMK4Cf90E0/s400/hollow.png" alt="" id="BLOGGER_PHOTO_ID_5223178116673263282" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SH1TAeA1-KI/AAAAAAAAATg/ETfAkwZplFw/s1600-h/plus.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 103px; height: 103px;" src="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SH1TAeA1-KI/AAAAAAAAATg/ETfAkwZplFw/s400/plus.png" alt="" id="BLOGGER_PHOTO_ID_5223422410341349538" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:130%;" &gt;i) SE = 4x4 square&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;DILATE&lt;/span&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SHxXyDYiQiI/AAAAAAAAAQY/-XCe7pssmo4/s1600-h/S2.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 100px; height: 100px;" src="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SHxXyDYiQiI/AAAAAAAAAQY/-XCe7pssmo4/s400/S2.png" alt="" id="BLOGGER_PHOTO_ID_5223146185256223266" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SHxjk8pW4OI/AAAAAAAAARI/Sgt1x_gi4_I/s1600-h/t2.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 132px; height: 100px;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SHxjk8pW4OI/AAAAAAAAARI/Sgt1x_gi4_I/s400/t2.png" alt="" id="BLOGGER_PHOTO_ID_5223159154248966370" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SHxtnuFDObI/AAAAAAAAASQ/4MIBuAyYqTo/s1600-h/c2.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 100px; height: 100px;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SHxtnuFDObI/AAAAAAAAASQ/4MIBuAyYqTo/s400/c2.png" alt="" id="BLOGGER_PHOTO_ID_5223170196994472370" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SHx00-p_usI/AAAAAAAAAS4/8iqZdIj6fAs/s1600-h/h2.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 101px; height: 101px;" src="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SHx00-p_usI/AAAAAAAAAS4/8iqZdIj6fAs/s400/h2.png" alt="" id="BLOGGER_PHOTO_ID_5223178121364093634" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SH1dMbEugdI/AAAAAAAAAUQ/z05FK7_Vl0A/s1600-h/x2.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 101px; height: 101px;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SH1dMbEugdI/AAAAAAAAAUQ/z05FK7_Vl0A/s400/x2.png" alt="" id="BLOGGER_PHOTO_ID_5223433610827039186" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;ERODE&lt;/span&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SH1mJx6FNOI/AAAAAAAAAUw/uddaJpWCLVk/s1600-h/se1.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 101px; height: 100px;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SH1mJx6FNOI/AAAAAAAAAUw/uddaJpWCLVk/s400/se1.png" alt="" id="BLOGGER_PHOTO_ID_5223443461021447394" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SH1mJ1Em0LI/AAAAAAAAAU4/r4wnoW5gHw4/s1600-h/te1.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 130px; height: 101px;" src="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SH1mJ1Em0LI/AAAAAAAAAU4/r4wnoW5gHw4/s400/te1.png" alt="" id="BLOGGER_PHOTO_ID_5223443461870899378" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SH1mKBp7BcI/AAAAAAAAAVA/fIok9B-VTLU/s1600-h/ce1.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 102px; height: 102px;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SH1mKBp7BcI/AAAAAAAAAVA/fIok9B-VTLU/s400/ce1.png" alt="" id="BLOGGER_PHOTO_ID_5223443465248638402" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SH1mKZojnvI/AAAAAAAAAVI/C2RuK04oYoU/s1600-h/he1.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 102px; height: 102px;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SH1mKZojnvI/AAAAAAAAAVI/C2RuK04oYoU/s400/he1.png" alt="" id="BLOGGER_PHOTO_ID_5223443471685361394" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SH1mKQJNK8I/AAAAAAAAAVQ/VZCjP3_BvV0/s1600-h/pe1.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 103px; height: 103px;" src="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SH1mKQJNK8I/AAAAAAAAAVQ/VZCjP3_BvV0/s400/pe1.png" alt="" id="BLOGGER_PHOTO_ID_5223443469137947586" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:130%;" &gt;ii) SE = 2x4 rectangle&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;DILATE&lt;/span&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SHxaMjmLWaI/AAAAAAAAAQg/G0sb9ea_LJk/s1600-h/S3.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 101px; height: 101px;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SHxaMjmLWaI/AAAAAAAAAQg/G0sb9ea_LJk/s400/S3.png" alt="" id="BLOGGER_PHOTO_ID_5223148839603231138" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SHxmJw4jdcI/AAAAAAAAARQ/9KpdJ4bRBUM/s1600-h/t3.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 131px; height: 101px;" src="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SHxmJw4jdcI/AAAAAAAAARQ/9KpdJ4bRBUM/s400/t3.png" alt="" id="BLOGGER_PHOTO_ID_5223161985769895362" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SHxtnv3eF6I/AAAAAAAAASY/E1VW79mdGJA/s1600-h/c3.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 101px; height: 101px;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SHxtnv3eF6I/AAAAAAAAASY/E1VW79mdGJA/s400/c3.png" alt="" id="BLOGGER_PHOTO_ID_5223170197474383778" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SHx01GhKdGI/AAAAAAAAATA/5Iyu92kn2TY/s1600-h/h3.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 102px; height: 102px;" src="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SHx01GhKdGI/AAAAAAAAATA/5Iyu92kn2TY/s400/h3.png" alt="" id="BLOGGER_PHOTO_ID_5223178123474531426" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SH1dMkyTLvI/AAAAAAAAAUY/XdFfIcPMTe4/s1600-h/x3.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 103px; height: 103px;" src="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SH1dMkyTLvI/AAAAAAAAAUY/XdFfIcPMTe4/s400/x3.png" alt="" id="BLOGGER_PHOTO_ID_5223433613434105586" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;ERODE&lt;/span&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SH1oH4Arh3I/AAAAAAAAAVY/vQ7M1ofetQg/s1600-h/se2.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 99px; height: 99px;" src="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SH1oH4Arh3I/AAAAAAAAAVY/vQ7M1ofetQg/s400/se2.png" alt="" id="BLOGGER_PHOTO_ID_5223445627323254642" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SH1oH2KI_9I/AAAAAAAAAVg/FJ--gZcDwec/s1600-h/te2.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 129px; height: 100px;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SH1oH2KI_9I/AAAAAAAAAVg/FJ--gZcDwec/s400/te2.png" alt="" id="BLOGGER_PHOTO_ID_5223445626826063826" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SH1oIDXPRiI/AAAAAAAAAVo/h3vAJWPMU7Y/s1600-h/ce2.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 100px; height: 100px;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SH1oIDXPRiI/AAAAAAAAAVo/h3vAJWPMU7Y/s400/ce2.png" alt="" id="BLOGGER_PHOTO_ID_5223445630370661922" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SH1oIAeYXnI/AAAAAAAAAVw/PaecYwCffc4/s1600-h/he2.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 101px; height: 101px;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SH1oIAeYXnI/AAAAAAAAAVw/PaecYwCffc4/s400/he2.png" alt="" id="BLOGGER_PHOTO_ID_5223445629595311730" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SH1oIej3hrI/AAAAAAAAAV4/F90xfa9F51E/s1600-h/pe2.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 101px; height: 101px;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SH1oIej3hrI/AAAAAAAAAV4/F90xfa9F51E/s400/pe2.png" alt="" id="BLOGGER_PHOTO_ID_5223445637671388850" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:130%;" &gt;iii) SE = 4x2 rectangle&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;DILATE&lt;/span&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SHxaMgiTQUI/AAAAAAAAAQo/8NKV0XFWKyU/s1600-h/S4.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 101px; height: 101px;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SHxaMgiTQUI/AAAAAAAAAQo/8NKV0XFWKyU/s400/S4.png" alt="" id="BLOGGER_PHOTO_ID_5223148838781665602" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SHxmJ6rwKGI/AAAAAAAAARY/AUqOxjKchMA/s1600-h/t4.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 129px; height: 100px;" src="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SHxmJ6rwKGI/AAAAAAAAARY/AUqOxjKchMA/s400/t4.png" alt="" id="BLOGGER_PHOTO_ID_5223161988400556130" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SHxtn_GFKNI/AAAAAAAAASg/_HLJ08JqR28/s1600-h/c4.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 101px; height: 100px;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SHxtn_GFKNI/AAAAAAAAASg/_HLJ08JqR28/s400/c4.png" alt="" id="BLOGGER_PHOTO_ID_5223170201562196178" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SHx01Af1zVI/AAAAAAAAATI/MBaXPDVHW-4/s1600-h/h4.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 101px; height: 101px;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SHx01Af1zVI/AAAAAAAAATI/MBaXPDVHW-4/s400/h4.png" alt="" id="BLOGGER_PHOTO_ID_5223178121858370898" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SH1dMoNbA4I/AAAAAAAAAUg/0DE-aNmHNRc/s1600-h/x4.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 102px; height: 102px;" src="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SH1dMoNbA4I/AAAAAAAAAUg/0DE-aNmHNRc/s400/x4.png" alt="" id="BLOGGER_PHOTO_ID_5223433614353171330" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;ERODE&lt;/span&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SH1orsSCA5I/AAAAAAAAAWA/2Myto5Jb44Q/s1600-h/se3.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 102px; height: 101px;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SH1orsSCA5I/AAAAAAAAAWA/2Myto5Jb44Q/s400/se3.png" alt="" id="BLOGGER_PHOTO_ID_5223446242650096530" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SH1oric-4kI/AAAAAAAAAWI/k2CWq1fOkos/s1600-h/te3.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 130px; height: 101px;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SH1oric-4kI/AAAAAAAAAWI/k2CWq1fOkos/s400/te3.png" alt="" id="BLOGGER_PHOTO_ID_5223446240011674178" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SH1oryA0qXI/AAAAAAAAAWQ/31QNHWSqBPU/s1600-h/ce3.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 102px; height: 102px;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SH1oryA0qXI/AAAAAAAAAWQ/31QNHWSqBPU/s400/ce3.png" alt="" id="BLOGGER_PHOTO_ID_5223446244188531058" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SH1or4w9l2I/AAAAAAAAAWY/ggE8jXr3wkI/s1600-h/he3.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 102px; height: 102px;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SH1or4w9l2I/AAAAAAAAAWY/ggE8jXr3wkI/s400/he3.png" alt="" id="BLOGGER_PHOTO_ID_5223446246001055586" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SH1osFN70yI/AAAAAAAAAWg/KFMzm9cZI-I/s1600-h/pe3.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 102px; height: 102px;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SH1osFN70yI/AAAAAAAAAWg/KFMzm9cZI-I/s400/pe3.png" alt="" id="BLOGGER_PHOTO_ID_5223446249343800098" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:130%;" &gt;iv) SE = &lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold;"&gt;5 pixels long, 1 pixel wide cross&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;DILATE&lt;/span&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SHxdwto_zDI/AAAAAAAAAQw/EYWKdCGCgUM/s1600-h/S5.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 101px; height: 101px;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SHxdwto_zDI/AAAAAAAAAQw/EYWKdCGCgUM/s400/S5.png" alt="" id="BLOGGER_PHOTO_ID_5223152759309585458" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SHxmKMU0DhI/AAAAAAAAARg/kKSYDbyXAbo/s1600-h/t5.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 130px; height: 100px;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SHxmKMU0DhI/AAAAAAAAARg/kKSYDbyXAbo/s400/t5.png" alt="" id="BLOGGER_PHOTO_ID_5223161993136180754" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SHxtn9UcZ8I/AAAAAAAAASo/kv51r3a3PTA/s1600-h/c5.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 100px; height: 100px;" src="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SHxtn9UcZ8I/AAAAAAAAASo/kv51r3a3PTA/s400/c5.png" alt="" id="BLOGGER_PHOTO_ID_5223170201085568962" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SHx01mApzOI/AAAAAAAAATQ/T2AoAiz7rTs/s1600-h/h5.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 101px; height: 101px;" src="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SHx01mApzOI/AAAAAAAAATQ/T2AoAiz7rTs/s400/h5.png" alt="" id="BLOGGER_PHOTO_ID_5223178131928108258" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SH1dMxm6C2I/AAAAAAAAAUo/PjsaCKrBo_k/s1600-h/x5.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 101px; height: 101px;" src="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SH1dMxm6C2I/AAAAAAAAAUo/PjsaCKrBo_k/s400/x5.png" alt="" id="BLOGGER_PHOTO_ID_5223433616875981666" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;ERODE&lt;/span&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SH1pJ0blPZI/AAAAAAAAAWo/m0JhcXDA_Ns/s1600-h/se4.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 99px; height: 98px;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SH1pJ0blPZI/AAAAAAAAAWo/m0JhcXDA_Ns/s400/se4.png" alt="" id="BLOGGER_PHOTO_ID_5223446760233713042" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SH1pJ5fowhI/AAAAAAAAAWw/lmjJYasaUu8/s1600-h/te4.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 126px; height: 98px;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SH1pJ5fowhI/AAAAAAAAAWw/lmjJYasaUu8/s400/te4.png" alt="" id="BLOGGER_PHOTO_ID_5223446761592898066" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SH1pKNPiCUI/AAAAAAAAAW4/gDD_jGcqXgA/s1600-h/ce4.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 98px; height: 98px;" src="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SH1pKNPiCUI/AAAAAAAAAW4/gDD_jGcqXgA/s400/ce4.png" alt="" id="BLOGGER_PHOTO_ID_5223446766894057794" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SH1pKLzlIWI/AAAAAAAAAXA/KaYMeVOCdHY/s1600-h/he4.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 98px; height: 98px;" src="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SH1pKLzlIWI/AAAAAAAAAXA/KaYMeVOCdHY/s400/he4.png" alt="" id="BLOGGER_PHOTO_ID_5223446766508384610" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SH1pKfD-TTI/AAAAAAAAAXI/6WQK7cj0c8U/s1600-h/pe4.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 98px; height: 98px;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SH1pKfD-TTI/AAAAAAAAAXI/6WQK7cj0c8U/s400/pe4.png" alt="" id="BLOGGER_PHOTO_ID_5223446771677416754" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 153, 153);font-size:180%;" &gt;(3) THIN &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Function &lt;span style="font-style: italic; color: rgb(255, 204, 0);"&gt;thin&lt;/span&gt; performs thinning of binary objects. The resulting image, the skeleton, is not always connected and is very sensible to noise. It is also slower than a good skeletonization algorithm (see skel). For thin shapes, it should work faster and provide better quality.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SH1rDuqpRgI/AAAAAAAAAXQ/g2W3DwqW0ck/s1600-h/thins.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 102px; height: 101px;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SH1rDuqpRgI/AAAAAAAAAXQ/g2W3DwqW0ck/s320/thins.png" alt="" id="BLOGGER_PHOTO_ID_5223448854630319618" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SH1rD6jMoQI/AAAAAAAAAXY/TS_FL3eszcU/s1600-h/thint.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 131px; height: 102px;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SH1rD6jMoQI/AAAAAAAAAXY/TS_FL3eszcU/s320/thint.png" alt="" id="BLOGGER_PHOTO_ID_5223448857820307714" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SH1rEBAkxZI/AAAAAAAAAXg/BnzYjrw974g/s1600-h/thinc.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 102px; height: 103px;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SH1rEBAkxZI/AAAAAAAAAXg/BnzYjrw974g/s320/thinc.png" alt="" id="BLOGGER_PHOTO_ID_5223448859554137490" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SH1rEG97ZUI/AAAAAAAAAXo/lgrd7UDqLzs/s1600-h/thinh.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 104px; height: 104px;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SH1rEG97ZUI/AAAAAAAAAXo/lgrd7UDqLzs/s320/thinh.png" alt="" id="BLOGGER_PHOTO_ID_5223448861153649986" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SH1rEbAnrwI/AAAAAAAAAXw/aGNveyKuniY/s1600-h/thinp.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 104px; height: 104px;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SH1rEbAnrwI/AAAAAAAAAXw/aGNveyKuniY/s320/thinp.png" alt="" id="BLOGGER_PHOTO_ID_5223448866533650178" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 153, 153);font-size:180%;" &gt;(4) SKEL &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Function &lt;span style="font-style: italic; color: rgb(255, 204, 0);"&gt;skel&lt;/span&gt; performs skeletonization (thinning) of a binary object. The resulting medial axis is multi-scale, meaning that it can be progressively pruned to eliminate detail. This pruning is done by thresholding the output skeleton image.  The algorithm computes skeletons that are guaranteed to be connected over all scales of simplification. The skeletons are computed using the euclidean metric. This has the advantage to produce high-quality, isotropic and well-centered skeletons in the shape. However the exact algorithm is computationally intensive.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SH1rjdlvyJI/AAAAAAAAAX4/iO6KnNENF6M/s1600-h/skels.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 103px; height: 103px;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SH1rjdlvyJI/AAAAAAAAAX4/iO6KnNENF6M/s320/skels.png" alt="" id="BLOGGER_PHOTO_ID_5223449399802185874" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SH1rjZ6zx7I/AAAAAAAAAYA/bFj7rwMK4dw/s1600-h/skelt.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 131px; height: 103px;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SH1rjZ6zx7I/AAAAAAAAAYA/bFj7rwMK4dw/s320/skelt.png" alt="" id="BLOGGER_PHOTO_ID_5223449398816786354" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SH1rjrtSbPI/AAAAAAAAAYI/5f72Hwtuzu8/s1600-h/skelc.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 104px; height: 104px;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SH1rjrtSbPI/AAAAAAAAAYI/5f72Hwtuzu8/s320/skelc.png" alt="" id="BLOGGER_PHOTO_ID_5223449403591912690" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SH1rjiroDbI/AAAAAAAAAYQ/ZP8UZkd3IQk/s1600-h/skelh.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 104px; height: 104px;" src="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SH1rjiroDbI/AAAAAAAAAYQ/ZP8UZkd3IQk/s320/skelh.png" alt="" id="BLOGGER_PHOTO_ID_5223449401169022386" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SH1rj7Zu8mI/AAAAAAAAAYY/0iDy_zdRLR0/s1600-h/skelp.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 104px; height: 105px;" src="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SH1rj7Zu8mI/AAAAAAAAAYY/0iDy_zdRLR0/s320/skelp.png" alt="" id="BLOGGER_PHOTO_ID_5223449407804863074" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;____________________________________________________________________&lt;br /&gt;&lt;br /&gt;I give myself &lt;span style="color: rgb(255, 204, 0);"&gt;9 points &lt;/span&gt;for this activity because some of the predictions were wrong especially in the erosion part. Thanks to &lt;span style="color: rgb(255, 204, 0);"&gt;Julie Dado, Angel Lim, Lei Uy, JC Nadora, Jeric Tugaff, and Mark Leo Bejemino&lt;/span&gt; for their help in the predictions in this activity.&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/223420158170109027-7407065389277551137?l=cole-ap186.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cole-ap186.blogspot.com/feeds/7407065389277551137/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=223420158170109027&amp;postID=7407065389277551137' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/223420158170109027/posts/default/7407065389277551137'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/223420158170109027/posts/default/7407065389277551137'/><link rel='alternate' type='text/html' href='http://cole-ap186.blogspot.com/2008/07/activity-8-morphological-operations.html' title='Activity 8: Morphological Operations'/><author><name>Cole</name><uri>http://www.blogger.com/profile/17840780106218077983</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://2.bp.blogspot.com/_6ZpN6X5LZPw/SeFgyvHYwpI/AAAAAAAAAmc/H76Ym0zH_Mw/S220/fabros05+-+Copy.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_6ZpN6X5LZPw/SHxP9Li8VsI/AAAAAAAAAP4/L746kVmkr6w/s72-c/dilation.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-223420158170109027.post-8461203086381235259</id><published>2008-07-12T18:07:00.000-07:00</published><updated>2008-10-08T19:54:59.104-07:00</updated><title type='text'>Activity 7: Enhancement in the Frequency Domain</title><content type='html'>&lt;div style="text-align: justify;"&gt;This activity aims to investigate on 3 things, namely: &lt;span style="color: rgb(255, 204, 0);"&gt;(1)&lt;/span&gt; Anamorphic property of the FT, &lt;span style="color: rgb(255, 204, 0);"&gt;(2)&lt;/span&gt; Fingerprints: Ridge enhancement, and &lt;span style="color: rgb(255, 204, 0);"&gt;(3)&lt;/span&gt; Lunar landing scanned pictures: Line removal.&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 153, 153);font-size:180%;" &gt;(1) Anamorphic property of the FT&lt;/span&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;The Fourier Transform (FT) of a signal gives the spatial frequency distribution of that signal. Essentially, the Fourier Theorem states that any image or signal can be expressed as a superposition of sinusoids. Unique to the 2D FT (as compared to the 1D FT) is the fact that rotation of the sinusoids result to the rotation of their FT's.&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;Here, we look into what the FT of a sinusoid looks like and see what happens when its frequency is changed, when it is rotated, and when it is superimposed with another sinusoid. We create a sinusoid using Scilab, take its FT, and expect that the rotation of the sinusoid results into the rotation of its FT.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;nx = 100; ny = 100;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;x = linspace(-1,1,nx);&lt;/span&gt; &lt;span style="font-style: italic;"&gt;&lt;br /&gt;y = linspace(-1,1,ny);&lt;/span&gt; &lt;span style="font-style: italic;"&gt;&lt;br /&gt;[X,Y] = ndgrid(x,y);&lt;/span&gt; &lt;span style="font-style: italic;"&gt;&lt;br /&gt;f = 4;&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;//frequency&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;theta = 30;&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;//angle of rotation&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;z = sin(2*%pi*f*X);&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;//sinusoid&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;z1 = sin(2*%pi*f*(Y*sin(theta) + X*cos(theta)));&lt;/span&gt; &lt;span style="font-style: italic;"&gt;&lt;br /&gt;scf(1);&lt;br /&gt;imshow(z,[]);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;Fz = fft2(z);&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;//or change to z1 for rotated sinusoid&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;scf(2); imshow(abs(fftshift(Fz)),[]);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;SINUSOID (f=4) and FT&lt;/span&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SHVU_ZQ1gLI/AAAAAAAAALQ/BGGgOXKOrbQ/s1600-h/sin.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 159px; height: 157px;" src="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SHVU_ZQ1gLI/AAAAAAAAALQ/BGGgOXKOrbQ/s400/sin.png" alt="" id="BLOGGER_PHOTO_ID_5221172791095951538" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SHVU_RSZkaI/AAAAAAAAALY/NdhieJYnJI4/s1600-h/ft.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 157px; height: 157px;" src="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SHVU_RSZkaI/AAAAAAAAALY/NdhieJYnJI4/s400/ft.png" alt="" id="BLOGGER_PHOTO_ID_5221172788955025826" border="0" /&gt;&lt;/a&gt;Here we observe the FT of the sine wave. The  sinusoid is horizontal while the two dots are oriented vertically. This is because doing a Fourier transform &lt;span style="color: rgb(255, 204, 0);"&gt;maps an object into the Fourier space&lt;/span&gt; (or k-space or inverse space). We can say that the frequency axis in the FT image is the vertical one and the frequency value corresponds to how far apart a dot is from the origin. We only need to consider one dot since the other is just a mirror image. Thus, we expect that increasing the frequency of the sinusoid will result in making the dots in the FT image farther apart.&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;SINUSOID (f=20) and FT&lt;/span&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SHVX-ned0gI/AAAAAAAAALw/6rJel0Oah6g/s1600-h/freq.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 159px; height: 159px;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SHVX-ned0gI/AAAAAAAAALw/6rJel0Oah6g/s400/freq.png" alt="" id="BLOGGER_PHOTO_ID_5221176076266230274" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SHVX-tTO2QI/AAAAAAAAAL4/CGIMqITBy34/s1600-h/ftfreq.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 159px; height: 159px;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SHVX-tTO2QI/AAAAAAAAAL4/CGIMqITBy34/s400/ftfreq.png" alt="" id="BLOGGER_PHOTO_ID_5221176077829724418" border="0" /&gt;&lt;/a&gt;Now that the frequency is increased, the dots are farther away as expected. Next, we have a rotated sinusoid which is oriented &lt;span style="color: rgb(255, 204, 0);"&gt;30 degrees  to the left with respect to the vertical axis&lt;/span&gt;. Since the FT maps this wave into inverse space, we expect that the resulting image will have dots &lt;span style="color: rgb(255, 204, 0);"&gt;also rotated 30 degrees but now with respect to the horizontal axis&lt;/span&gt;. Indeed, this is what happens. Finally, we use a combination of 2 sine waves and look at its resulting FT image. The form is of &lt;span style="font-style: italic;"&gt;z = sin(2*%pi*4*X).*sin(2*%pi*4*Y);&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;ROTATED SINUSOID (f =4) and FT&lt;/span&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;; COMBINATION and FT&lt;/span&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SHVU_Yqn8xI/AAAAAAAAALg/V0r6uw8ivEY/s1600-h/rot.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 158px; height: 150px;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SHVU_Yqn8xI/AAAAAAAAALg/V0r6uw8ivEY/s400/rot.png" alt="" id="BLOGGER_PHOTO_ID_5221172790935679762" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SHVU_hIr85I/AAAAAAAAALo/k7XbkB-qxfA/s1600-h/ftrot.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 150px; height: 150px;" src="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SHVU_hIr85I/AAAAAAAAALo/k7XbkB-qxfA/s400/ftrot.png" alt="" id="BLOGGER_PHOTO_ID_5221172793209254802" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SHVdu1YMJ6I/AAAAAAAAAMA/dkV5HiMnce4/s1600-h/super.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 150px; height: 150px;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SHVdu1YMJ6I/AAAAAAAAAMA/dkV5HiMnce4/s400/super.png" alt="" id="BLOGGER_PHOTO_ID_5221182402189862818" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SHVdu6VP08I/AAAAAAAAAMI/bTmKy13LAqA/s1600-h/ftsuper.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 150px; height: 150px;" src="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SHVdu6VP08I/AAAAAAAAAMI/bTmKy13LAqA/s400/ftsuper.png" alt="" id="BLOGGER_PHOTO_ID_5221182403519697858" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The product of the 2 sinusoids generates the 3rd figure above. A checkerboard pattern results and the FT image consists of 4 dots forming the corners of a square. We can think of this as the product of 2 horizontal dots and 2 vertical dots. The axes being inverted are not evident here since the pattern is square. One can also show that when we add the two sinusoids, its FT looks like a cross rather than a square. We can conclude that the FT of the combination of two signals, whether you add, subtract, multiply, or divide them, will result in the combination of the FT's of the individual signals.&lt;br /&gt;____________________________________________________________________&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 153, 153);font-size:180%;" &gt;(2) Fingerprints: Ridge Enhancement&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;We obtained a scanned image of a fingerprint for this part of the activity. If it is not yet in grayscale, it should be converted. After this, we must subtract the mean from the image in order to &lt;span style="color: rgb(255, 204, 0);"&gt;remove the dark current (DC)&lt;/span&gt;. Doing this will make all the other spatial frequencies present in the image visible. &lt;span style="font-style: italic; color: rgb(255, 204, 0);"&gt;(source of fingerprint image: A7 - Enhancement in the Frequency Domain.pdf&lt;/span&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;ORIGINAL &amp;amp; MEAN-CENTERED IMAGE&lt;/span&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;S&lt;/span&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SHWyuUYBRZI/AAAAAAAAAMw/m_kr2S8-ODc/s1600-h/print.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 224px; height: 224px;" src="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SHWyuUYBRZI/AAAAAAAAAMw/m_kr2S8-ODc/s400/print.png" alt="" id="BLOGGER_PHOTO_ID_5221275851819140498" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SHYNYSDp3II/AAAAAAAAAN4/Kd4rijonofg/s1600-h/finger.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 225px; height: 225px;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SHYNYSDp3II/AAAAAAAAAN4/Kd4rijonofg/s400/finger.png" alt="" id="BLOGGER_PHOTO_ID_5221375528797854850" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SHYJllXA7bI/AAAAAAAAANI/FunD2FTy43w/s1600-h/ftfinger.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 223px; height: 223px;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SHYJllXA7bI/AAAAAAAAANI/FunD2FTy43w/s400/ftfinger.png" alt="" id="BLOGGER_PHOTO_ID_5221371359271120306" border="0" /&gt;&lt;/a&gt;We generate the FT image for the fingerprint and is shown at the left.&lt;br /&gt;&lt;br /&gt;We want to enchance the appearance of the ridges while removing the blotches. We can do this by applying a filter using the &lt;span style="font-style: italic; color: rgb(255, 204, 0);"&gt;mkfftfilter&lt;/span&gt; function in Scilab. We will use this instead of &lt;span style="color: rgb(255, 204, 0); font-style: italic;"&gt;mkfilter&lt;/span&gt; because it is easier to work in the Fourier domain than in the image domain. We then apply the filter to the image in Fourier space in order to enhance certain features. To select the appropriate filter, we need to take a look at the image's FT first.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Our objective is to enhance &lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SHYeCFxysuI/AAAAAAAAAOo/8vEV6Eo4Ifk/s1600-h/filter.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 224px; height: 165px;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SHYeCFxysuI/AAAAAAAAAOo/8vEV6Eo4Ifk/s400/filter.png" alt="" id="BLOGGER_PHOTO_ID_5221393839242261218" border="0" /&gt;&lt;/a&gt;the ridges or make the image sharper. There are two types of image enhancement in the Fourier domain in general, &lt;span style="color: rgb(255, 204, 0);"&gt;low-pass filtering and high-pass filtering&lt;/span&gt;. Applying a &lt;span style="color: rgb(255, 204, 0);"&gt;low-pass filter&lt;/span&gt; corresponds to reducing the high frequency content, which in turn results into &lt;span style="color: rgb(255, 204, 0);"&gt;blurring or smoothing&lt;/span&gt;. &lt;span style="color: rgb(255, 204, 0);"&gt;High-pass filtering&lt;/span&gt;, on the other hand, increases the magnitude of the high-frequency components relative to the low-frequency components. This results in &lt;span style="color: rgb(255, 204, 0);"&gt;sharpening&lt;/span&gt;. Thus, we need to apply a high-pass filter to the FT image in order to enhance the fingerprint ridges. Such a filter is shown at the left.&lt;br /&gt;&lt;br /&gt;What this does is that only those frequencies in the FT image that fall in the white parts of the filter is allowed to pass and all others are filtered out. Note that the frequencies near the center are low frequencies. This way, we block out the low frequencies and the image obtained after doing an inverse FT is sharpened (and of course, also inverted). The code for generating these images is as follows.&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;&lt;br /&gt;//Original code c/o Scilab Help - mkfftfilter&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//Increase the stack size because images are memory consuming&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;stacksize(4e7); &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;image=gray_imread('fingerprint.png');&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;image2=image-mean(image);&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;//removes DC&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;scf(1); imshow(image2);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;IM=fft2(image2);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;F=real((IM).*conj(IM));&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;scf(2); imshow(fftshift(log(F+1)),[]);&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;//the use of log(F+1) allows to observe great amplitude variations&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;xset('colormap',jetcolormap(256));&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//Transfer function&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;h=mkfftfilter(image2,'exp',20);&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;//exponential with "radius" = 20&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;scf(3); imshow(h);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//High-pass filter&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;IM2=IM.*fftshift(1-h);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;im=real(fft2(IM2));&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;scf(4); imshow(im);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;ORIGINAL &amp;amp; ENHANCED IMAGES&lt;/span&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SHWyuUYBRZI/AAAAAAAAAMw/m_kr2S8-ODc/s1600-h/print.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 224px; height: 224px;" src="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SHWyuUYBRZI/AAAAAAAAAMw/m_kr2S8-ODc/s400/print.png" alt="" id="BLOGGER_PHOTO_ID_5221275851819140498" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SHYKYTfB6NI/AAAAAAAAANw/wql1r6RVpCI/s1600-h/final.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 222px; height: 222px;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SHYKYTfB6NI/AAAAAAAAANw/wql1r6RVpCI/s400/final.png" alt="" id="BLOGGER_PHOTO_ID_5221372230646229202" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;Clearly, the fingerprint ridges are enhanced.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;____________________________________________________________________&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:180%;"&gt;&lt;span style="color: rgb(153, 153, 153);"&gt;(3) Lunar Landing scanned pictures: Line Removal&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;Here we aim to remove the vertical lines from the given picture by filtering in the Fourier domain. We should make sure that the image is in grayscale first. Its FT is also shown below.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;ORIGINAL &amp;amp; FT IMAGE&lt;/span&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;S&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SHWAXE2T42I/AAAAAAAAAMg/jLwbz9MaCB8/s1600-h/graymoon.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 277px; height: 205px;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SHWAXE2T42I/AAAAAAAAAMg/jLwbz9MaCB8/s400/graymoon.png" alt="" id="BLOGGER_PHOTO_ID_5221220476932842338" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SHh7N9BZG_I/AAAAAAAAAPQ/aEZPzEP48cM/s1600-h/ft.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 274px; height: 205px;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SHh7N9BZG_I/AAAAAAAAAPQ/aEZPzEP48cM/s400/ft.png" alt="" id="BLOGGER_PHOTO_ID_5222059247585008626" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SHiBCOBWTyI/AAAAAAAAAPw/-rHGOXEdnGg/s1600-h/mask.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 277px; height: 205px;" src="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SHiBCOBWTyI/AAAAAAAAAPw/-rHGOXEdnGg/s400/mask.png" alt="" id="BLOGGER_PHOTO_ID_5222065643059564322" border="0" /&gt;&lt;/a&gt;From part 1 of this activity, we saw that the spatial frequencies of an image are mapped into the Fourier plane at perpendicular directions. Hence, &lt;span style="color: rgb(255, 204, 0);"&gt;v&lt;/span&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;ertical lines in the image will correspond to dots in the horizontal axis of the FT image&lt;/span&gt;. To remove the vertical lines from the satellite moon image, we need to mask those prominent dots at the horizontal axis while still retaining the center spot so that no information is lost. The mask that was used is shown here.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;&lt;br /&gt;&lt;br /&gt;ORIGINAL &amp;amp; SMOOTHENED IMAGE&lt;/span&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SHWAXE2T42I/AAAAAAAAAMg/jLwbz9MaCB8/s1600-h/graymoon.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 277px; height: 205px;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SHWAXE2T42I/AAAAAAAAAMg/jLwbz9MaCB8/s400/graymoon.png" alt="" id="BLOGGER_PHOTO_ID_5221220476932842338" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SHh7OJtaGCI/AAAAAAAAAPY/-WYM3klaEfM/s1600-h/newim.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 283px; height: 205px;" src="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SHh7OJtaGCI/AAAAAAAAAPY/-WYM3klaEfM/s400/newim.png" alt="" id="BLOGGER_PHOTO_ID_5222059250990848034" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The vertical lines are now removed and the resulting image still retains its information, meaning it still looks like a photograph of the moon.&lt;br /&gt;____________________________________________________________________&lt;br /&gt;&lt;br /&gt;I give myself &lt;span style="color: rgb(255, 204, 0);"&gt;10 points&lt;/span&gt; for this activity since the objectives were met and the images were enhanced. Special thanks to &lt;span style="color: rgb(255, 204, 0);"&gt;Julie Dado and Jeric Tugaff&lt;/span&gt; for their help in this activity.&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/223420158170109027-8461203086381235259?l=cole-ap186.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cole-ap186.blogspot.com/feeds/8461203086381235259/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=223420158170109027&amp;postID=8461203086381235259' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/223420158170109027/posts/default/8461203086381235259'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/223420158170109027/posts/default/8461203086381235259'/><link rel='alternate' type='text/html' href='http://cole-ap186.blogspot.com/2008/07/activity-7-enhancement-in-frequency.html' title='Activity 7: Enhancement in the Frequency Domain'/><author><name>Cole</name><uri>http://www.blogger.com/profile/17840780106218077983</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://2.bp.blogspot.com/_6ZpN6X5LZPw/SeFgyvHYwpI/AAAAAAAAAmc/H76Ym0zH_Mw/S220/fabros05+-+Copy.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_6ZpN6X5LZPw/SHVU_ZQ1gLI/AAAAAAAAALQ/BGGgOXKOrbQ/s72-c/sin.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-223420158170109027.post-6053873557889769518</id><published>2008-07-08T11:28:00.000-07:00</published><updated>2008-07-09T20:10:35.520-07:00</updated><title type='text'>Activity 6: Fourier Transform Model of Image Formation</title><content type='html'>&lt;div style="text-align: justify;"&gt;This activity is divided into 4 parts namely: &lt;span style="color: rgb(255, 204, 0);"&gt;(1)&lt;/span&gt; Familiarization with the discrete Fast Fourier Transform (FFT), &lt;span style="color: rgb(255, 204, 0);"&gt;(2)&lt;/span&gt; Simulation of an imaging device, &lt;span style="color: rgb(255, 204, 0);"&gt;(3)&lt;/span&gt; Template matching using correlation,  and &lt;span style="color: rgb(255, 204, 0);"&gt;(4)&lt;/span&gt; Edge detection using the convolution integral.&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 153, 153);font-size:180%;" &gt;(1) Familiarization with the discrete FFT&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;This part is straightforward in the sense that we try to understand the properties of the FFT and see what happens to an image after doing the operation. As a start, we generate a 128x128 image of a circle in MSPaint and apply the FFT.&lt;/div&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;I = imread('circle.bmp');&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;Igray = im2gray(I);&lt;/span&gt; &lt;span style="font-style: italic;"&gt;&lt;br /&gt;FIgray = fft2(Igray);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;imshow(abs(FIgray),[]);&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;//intensity image&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;//imshow(abs(fftshift(FIgray)),[]);&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;//fft shifted image&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;//imshow(abs(fft2(FIgray)));&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;//fft twice&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;xset("colormap",hotcolormap(32));&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;//add color to your images&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;CIRCLE: ORIGINAL image, FFT INTENSITY image, FFT SHIFTED&lt;/span&gt;&lt;span style="color: rgb(255, 204, 0);"&gt; image&lt;/span&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;, DOING FFT TWICE&lt;/span&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SHK-Sns1tOI/AAAAAAAAAHQ/82oePAkKEO8/s1600-h/circle.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 129px; height: 129px;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SHK-Sns1tOI/AAAAAAAAAHQ/82oePAkKEO8/s400/circle.png" alt="" id="BLOGGER_PHOTO_ID_5220444145179800802" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SHLCldfJ0KI/AAAAAAAAAII/Y-fZ6Mjx2pE/s1600-h/abs.gif"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 129px; height: 129px;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SHLCldfJ0KI/AAAAAAAAAII/Y-fZ6Mjx2pE/s400/abs.gif" alt="" id="BLOGGER_PHOTO_ID_5220448866902069410" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SHLCldSbwoI/AAAAAAAAAIQ/I-2BRCuo-SA/s1600-h/fft1.gif"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 130px; height: 130px;" src="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SHLCldSbwoI/AAAAAAAAAIQ/I-2BRCuo-SA/s400/fft1.gif" alt="" id="BLOGGER_PHOTO_ID_5220448866848719490" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SHK-Sns1tOI/AAAAAAAAAHQ/82oePAkKEO8/s1600-h/circle.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 129px; height: 129px;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SHK-Sns1tOI/AAAAAAAAAHQ/82oePAkKEO8/s400/circle.png" alt="" id="BLOGGER_PHOTO_ID_5220444145179800802" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;For the 1st FFT image (2nd from left), we observe spots at the corners of the image. These are actually the 4 quarters of a circle and we predict that once this image is FFT shifted, we will observe the correct analytical Fourier Transform of a circle, which is an &lt;span style="color: rgb(255, 204, 0);"&gt;Airy disk&lt;/span&gt;: a bright spot centered about concentric rings outside of it. Indeed, this is what we observe in our image (3rd from left). Upon applying the FFT twice on our original image, what we observe is that we return to our original image. However, this is actually an &lt;span style="color: rgb(255, 204, 0);"&gt;inverted image of the original &lt;/span&gt;and it is just not obvious. We can verify this by using an "A" as our image.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;"A": ORIGINAL image, FFT INTENSITY image, FFT SHIFTED&lt;/span&gt;&lt;span style="color: rgb(255, 204, 0);"&gt; image&lt;/span&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;, DOING FFT TWICE&lt;/span&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SHLIJOLH1dI/AAAAAAAAAIY/BLdIDCWj4mo/s1600-h/a.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SHLIJOLH1dI/AAAAAAAAAIY/BLdIDCWj4mo/s400/a.png" alt="" id="BLOGGER_PHOTO_ID_5220454978824951250" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SHLJAI5-f4I/AAAAAAAAAI4/r69kaLhLEbA/s1600-h/abs.gif"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 128px; height: 128px;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SHLJAI5-f4I/AAAAAAAAAI4/r69kaLhLEbA/s400/abs.gif" alt="" id="BLOGGER_PHOTO_ID_5220455922303664002" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SHLJAbcf0wI/AAAAAAAAAJA/SCvsnUbA0C8/s1600-h/fft1.gif"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 129px; height: 129px;" src="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SHLJAbcf0wI/AAAAAAAAAJA/SCvsnUbA0C8/s400/fft1.gif" alt="" id="BLOGGER_PHOTO_ID_5220455927280292610" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SHLJAYnvPiI/AAAAAAAAAJI/pxoP1ghWvGs/s1600-h/reverse.gif"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 130px; height: 130px;" src="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SHLJAYnvPiI/AAAAAAAAAJI/pxoP1ghWvGs/s400/reverse.gif" alt="" id="BLOGGER_PHOTO_ID_5220455926522134050" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;The "A" is flipped with respect to the horizontal and is now inverted with respect to the original image. Thus, doing FFT twice will result in an inverted image.&lt;br /&gt;&lt;/div&gt;____________________________________________________________________&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:180%;"&gt;&lt;span style="color: rgb(153, 153, 153);"&gt;(2) Simulation of an imaging device&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;Here we try to simulate what happens in a camera. We vary the camera lens radii and see what the FFT images look like.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;c = gray_imread('circle.png'); &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//medium aperture&lt;/span&gt;&lt;span style="font-style: italic;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic;"&gt;//c = gray_imread('bigcircle.png');&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;//big aperture&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;//c = gray_imread('smallcircle.png'); &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//small aperture&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;vip = gray_imread('vip.png');&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;Fc = fftshift(c);&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;//aperture is already in the Fourier Plane and need not be FFT'ed&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;Fvip = fft2(vip);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;Fcvip = Fc.*(Fvip);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;Icvip = fft2(Fcvip);&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;//inverse FFT&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;FImage = abs(Icvip);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;imshow(FImage, []);&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;ORIGINAL, SMALL APERTURE, MEDIUM APERTURE, BIG APERTURE&lt;/span&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SHLQ21FBeXI/AAAAAAAAAJQ/wzitFpffWBA/s1600-h/vip.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SHLQ21FBeXI/AAAAAAAAAJQ/wzitFpffWBA/s400/vip.png" alt="" id="BLOGGER_PHOTO_ID_5220464558455486834" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SHLRakj3TWI/AAAAAAAAAJw/lw0VwS4KDMs/s1600-h/vipsmall.gif"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 128px; height: 128px;" src="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SHLRakj3TWI/AAAAAAAAAJw/lw0VwS4KDMs/s400/vipsmall.gif" alt="" id="BLOGGER_PHOTO_ID_5220465172496731490" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SHLRay-OxvI/AAAAAAAAAJ4/ZoTFl-wvkOM/s1600-h/vipmed.gif"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 128px; height: 128px;" src="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SHLRay-OxvI/AAAAAAAAAJ4/ZoTFl-wvkOM/s400/vipmed.gif" alt="" id="BLOGGER_PHOTO_ID_5220465176365418226" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SHLRa4ZX5rI/AAAAAAAAAKA/tXXG5T0dal8/s1600-h/vipbig.gif"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 129px; height: 129px;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SHLRa4ZX5rI/AAAAAAAAAKA/tXXG5T0dal8/s400/vipbig.gif" alt="" id="BLOGGER_PHOTO_ID_5220465177821439666" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;A finite lens radius in a camera means that the lens can only gather a limited number of rays reflected off an object, therefore reconstruction of the object is never perfect. A &lt;span style="color: rgb(255, 204, 0);"&gt;smaller lens aperture&lt;/span&gt; will gather fewer rays reflected off an object and this results in a &lt;span style="color: rgb(255, 204, 0);"&gt;b&lt;/span&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;lurred image&lt;/span&gt;. Comparing this with the &lt;span style="color: rgb(255, 204, 0);"&gt;bigger aperture&lt;/span&gt;, the image is &lt;span style="color: rgb(255, 204, 0);"&gt;sharper&lt;/span&gt; and most closely resembles the original.&lt;br /&gt;____________________________________________________________________&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 153, 153);font-size:130%;" &gt;&lt;span style="font-size:130%;"&gt;(3) Template matching using correlation&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;Template Matching is a pattern recognition technique suitable for finding exactly identical patterns in a scene such as in the case of finding a certain word in a document. Here, we apply this technique in finding where the letter A's are in a sample text.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;rain = gray_imread('rain.png');&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;//image of the text&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;a = gray_imread('a2.png');&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;//image of the letter to correlate with text, same font type and size&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;Frain = fft2(rain);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;Fa = fft2(a);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;p = Fa.*conj(Frain);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;im = ifft(p);&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;//inverse FFT&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;imshow(abs(fftshift(im)),[]);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;ORIGINAL &amp;amp; RESULTING IMAGE&lt;/span&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SHLYGTiE5iI/AAAAAAAAAKI/eszW5IhTgVI/s1600-h/rain.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SHLYGTiE5iI/AAAAAAAAAKI/eszW5IhTgVI/s400/rain.png" alt="" id="BLOGGER_PHOTO_ID_5220472520909841954" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SHLYGvnS89I/AAAAAAAAAKQ/ZETFkTlP0CM/s1600-h/rain2.gif"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 224px; height: 224px;" src="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SHLYGvnS89I/AAAAAAAAAKQ/ZETFkTlP0CM/s400/rain2.gif" alt="" id="BLOGGER_PHOTO_ID_5220472528447927250" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;In the resulting image, we see that bright dots are located where there are letter A's in the text. These words are "rain", "Spain", "stays", "mainly", and "plain." &lt;span style="color: rgb(255, 204, 0);"&gt;There are 5 bright dots that correspond with 5 A's in the text.&lt;/span&gt; We have demonstrated here how the shape of the letter A was matched with the text using correlation.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 153, 153);font-size:180%;" &gt;&lt;br /&gt;&lt;br /&gt;(4) Edge detection using the convolution integral&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;Edge detection can be seen as template matching of an edge pattern with an image. We can detect the edges of the previous "VIP" image, for example, by applying a pattern oriented in a particular detection. The code and resulting images are shown below.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;hor = [-1 -1 -1; 2 2 2; -1 -1 -1];&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;//horizontal pattern&lt;/span&gt; &lt;span style="font-style: italic;"&gt;&lt;br /&gt;vert = [-1 2 -1; -1 2 -1; -1 2 -1];&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;//vertical pattern&lt;/span&gt; &lt;span style="font-style: italic;"&gt;&lt;br /&gt;spot = [-1 -1 -1; -1 8 -1; -1 -1 -1]; &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//spot pattern&lt;/span&gt; &lt;span style="font-style: italic;"&gt;&lt;br /&gt;pattern = hor;&lt;/span&gt; &lt;span style="font-style: italic;"&gt;&lt;br /&gt;vip = gray_imread('vip.png');&lt;/span&gt; &lt;span style="font-style: italic;"&gt;&lt;br /&gt;im = imcorrcoef(vip, pattern);&lt;/span&gt; &lt;span style="font-style: italic;"&gt;&lt;br /&gt;imshow(im);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;ORIGINAL, HORIZONTAL EDGE, VERTICAL EDGE, SPOTS&lt;/span&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SHLQ21FBeXI/AAAAAAAAAJQ/wzitFpffWBA/s1600-h/vip.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SHLQ21FBeXI/AAAAAAAAAJQ/wzitFpffWBA/s400/vip.png" alt="" id="BLOGGER_PHOTO_ID_5220464558455486834" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SHLeV13QoXI/AAAAAAAAAKY/P_riV2MtCGA/s1600-h/hor.gif"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 128px; height: 128px;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SHLeV13QoXI/AAAAAAAAAKY/P_riV2MtCGA/s400/hor.gif" alt="" id="BLOGGER_PHOTO_ID_5220479384893301106" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SHLeWJ1_OOI/AAAAAAAAAKg/5FIKUi3kA8Q/s1600-h/vert.gif"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 127px; height: 127px;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SHLeWJ1_OOI/AAAAAAAAAKg/5FIKUi3kA8Q/s400/vert.gif" alt="" id="BLOGGER_PHOTO_ID_5220479390256675042" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SHLeWLnVeUI/AAAAAAAAAKo/RURAm16FEeI/s1600-h/spot.gif"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 127px; height: 127px;" src="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SHLeWLnVeUI/AAAAAAAAAKo/RURAm16FEeI/s400/spot.gif" alt="" id="BLOGGER_PHOTO_ID_5220479390732089666" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;As we can see, &lt;span style="color: rgb(255, 204, 0);"&gt;the edges are more prominent depending on what kind of pattern the image was convolved with&lt;/span&gt;. If a horizontal pattern was used, only the horizontal portions of the "VIP" image is shown (2nd to the left). The same is true for the vertical pattern. The spot pattern only shows portions containing 1 white pixel and the other pixels are merged with the background. That is why there are some holes in the letter V and P in particular upon close inspection.&lt;br /&gt;____________________________________________________________________&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;I give myself &lt;span style="color: rgb(255, 204, 0);"&gt;10 points&lt;/span&gt; for this activity since the all of the 4 objectives were met. I found this activity to be interesting and the techniques discussed here useful either for research and even for leisure. Thanks to &lt;span style="color: rgb(255, 204, 0);"&gt;Jeric Tugaff &lt;/span&gt;for help in the code for parts 3 and 4.&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/223420158170109027-6053873557889769518?l=cole-ap186.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cole-ap186.blogspot.com/feeds/6053873557889769518/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=223420158170109027&amp;postID=6053873557889769518' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/223420158170109027/posts/default/6053873557889769518'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/223420158170109027/posts/default/6053873557889769518'/><link rel='alternate' type='text/html' href='http://cole-ap186.blogspot.com/2008/07/activity-6-fourier-transform-model-of.html' title='Activity 6: Fourier Transform Model of Image Formation'/><author><name>Cole</name><uri>http://www.blogger.com/profile/17840780106218077983</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://2.bp.blogspot.com/_6ZpN6X5LZPw/SeFgyvHYwpI/AAAAAAAAAmc/H76Ym0zH_Mw/S220/fabros05+-+Copy.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_6ZpN6X5LZPw/SHK-Sns1tOI/AAAAAAAAAHQ/82oePAkKEO8/s72-c/circle.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-223420158170109027.post-180300491588363485</id><published>2008-07-03T11:20:00.000-07:00</published><updated>2008-07-02T20:23:18.206-07:00</updated><title type='text'>Activity 5: Physical Measurements from Discrete Fourier Transforms</title><content type='html'>&lt;div style="text-align: justify;"&gt;In this activity, we will be applying the &lt;span style="color: rgb(255, 204, 0);"&gt;Discrete Fourier Transform (DFT)&lt;/span&gt; in image processing. First, we will try to understand what the DFT is, how it works, what it does to signals/images, and what information we can get out of it. Scilab already has a built-in &lt;span style="color: rgb(255, 204, 0); font-style: italic;"&gt;fft&lt;/span&gt; function and we will use this so that we no longer have to implement the math involved and make another code for it.&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;As an example, we generate a 1-D sinusoid of the form &lt;span style="font-style: italic;"&gt;sin (2*pi*f*t&lt;/span&gt;), compute its Fourier Transform (FT) and display it.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//Original code c/o Dr. Soriano&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;&lt;br /&gt;//Generate 1-D sinusoid specifying dt, N, and f&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;T = 2;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;N = 256;&lt;/span&gt; &lt;span style="font-style: italic;"&gt;&lt;br /&gt;dt = T/N;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;t = [0:dt:(N-1)*dt];&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;f = 5;&lt;/span&gt; &lt;span style="font-style: italic;"&gt;&lt;br /&gt;y = sin(2*%pi*f*t);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;subplot(1,2,1);&lt;br /&gt;plot(t,y);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;title('1-D sinusoid: f=5');&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;xlabel('time (seconds)');&lt;/span&gt; &lt;span style="font-style: italic;"&gt;&lt;br /&gt;ylabel('amplitude');&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//Get FT of signal and compute the frequency scale&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;FY = fft(y);&lt;/span&gt; &lt;span style="font-style: italic;"&gt;&lt;br /&gt;Fmax = 1/(2*dt);&lt;/span&gt; &lt;span style="font-style: italic;"&gt;&lt;br /&gt;df = 2*Fmax/N;&lt;/span&gt; &lt;span style="font-style: italic;"&gt;&lt;br /&gt;f = [-Fmax:df:df*(N/2-1)];&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//Display the fftshifted output with frequency axis&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;subplot(1,2,2);&lt;br /&gt;plot(f,fftshift(abs(FY)));&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;title('Fourier transform of signal');&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;xlabel('frequency (Hz)');&lt;/span&gt; &lt;span style="font-style: italic;"&gt;&lt;br /&gt;ylabel('amplitude');&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SGwtP5D8iYI/AAAAAAAAAGA/_QvLmF8Vd9s/s1600-h/sig.gif"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 323px; height: 244px;" src="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SGwtP5D8iYI/AAAAAAAAAGA/_QvLmF8Vd9s/s400/sig.gif" alt="" id="BLOGGER_PHOTO_ID_5218595819254221186" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SGwtP5ZiyOI/AAAAAAAAAGI/jYwuX1AXMs0/s1600-h/fft.gif"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 321px; height: 242px;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SGwtP5ZiyOI/AAAAAAAAAGI/jYwuX1AXMs0/s400/fft.gif" alt="" id="BLOGGER_PHOTO_ID_5218595819344808162" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;____________________________________________________________________&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;The Fourier Transform is an important image processing tool which is used to decompose an image into its sine and cosine components. The output of the transformation represents the image in the &lt;/span&gt;&lt;em style="font-style: italic;"&gt;Fourier&lt;/em&gt;&lt;span style="font-style: italic;"&gt; or &lt;span style="color: rgb(255, 204, 0);"&gt;frequency domain&lt;/span&gt;, while the &lt;span style="color: rgb(255, 204, 0);"&gt;input image is in the spatial domain&lt;/span&gt; equivalent. In the Fourier domain image, each point represents a particular frequency contained in the spatial domain image.  &lt;/span&gt;&lt;p&gt;&lt;span style="font-style: italic;"&gt;The Fourier Transform is used in a wide range of applications, such as image analysis, image filtering, image reconstruction and image compression.&lt;/span&gt; &lt;span style="color: rgb(153, 153, 153);"&gt;(Source: http://homepages.inf.ed.ac.uk/rbf/HIPR2/fourier.htm)&lt;/span&gt;&lt;/p&gt;&lt;p&gt;So for images, we work in the spatial and not the temporal domain. We first find the FT 1-D at a time, i.e. rows first then columns or vice versa. From there we can manipulate the FT depending on the particular application.&lt;/p&gt;&lt;p&gt;Answers to questions:&lt;/p&gt;&lt;p style="color: rgb(153, 153, 153); font-style: italic;"&gt;&lt;span style="font-size:130%;"&gt;1. Light from a fluorescent lamp is known to flicker at 120Hz. What should be the threshold sampling interval for accurate FT analysis?&lt;/span&gt;&lt;/p&gt;&lt;p&gt;From the Nyquist Theorem, &lt;span style="color: rgb(255, 204, 0);"&gt;Fmax = 1/2Δt&lt;/span&gt;. One can show that the value of Δt&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;/span&gt; is equal to &lt;span style="color: rgb(255, 204, 0);"&gt;0.004167 seconds&lt;/span&gt;.&lt;/p&gt;&lt;p style="color: rgb(153, 153, 153);"&gt;&lt;span style="font-size:130%;"&gt;2. What is the effect of increasing the number of samples N in the FT?&lt;/span&gt;&lt;/p&gt;&lt;p style="text-align: justify;"&gt;&lt;span style="color: rgb(255, 204, 0);font-size:130%;" &gt;Working equations: &lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;Δt = T/N,&lt;/span&gt; &lt;/span&gt;&lt;span style="color: rgb(255, 204, 0);font-size:130%;" &gt;Fmax = 1/2Δt, Δf = 2Fmax/N&lt;/span&gt;&lt;/p&gt;&lt;p style="text-align: justify;"&gt;Increasing N will mean that for the same Δt, T has to increase as well. When this happens, you have the same Fmax but Δf, or the discrete frequency steps in the Fourier domain, will decrease since it has an inverse relation with N as seen from the 3rd equation. The frequency measurement is more precise due this decrease in Δf, thus the lines become sharper (better resolution). We verify this by graphing.&lt;/p&gt;&lt;p&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SGw-eOmS4pI/AAAAAAAAAGw/90wOqubh8FU/s1600-h/1.gif"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 322px; height: 244px;" src="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SGw-eOmS4pI/AAAAAAAAAGw/90wOqubh8FU/s400/1.gif" alt="" id="BLOGGER_PHOTO_ID_5218614757251277458" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SGxBR7yHt9I/AAAAAAAAAHA/SOS1qPK8Vag/s1600-h/3.gif"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 322px; height: 244px;" src="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SGxBR7yHt9I/AAAAAAAAAHA/SOS1qPK8Vag/s400/3.gif" alt="" id="BLOGGER_PHOTO_ID_5218617844577056722" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 153, 153);font-size:130%;" &gt;&lt;br /&gt;3. What is the effect of decreasing the sampling interval Δt in the FT?&lt;/span&gt;&lt;p&gt;Decreasing  Δt will mean that for the same N, T has to decrease as well. Fmax will increase, N stays the same, so Δf will also increase. Δf increasing will result in not so precise frequency measurement and frequency lines that are not sharp (poor resolution). We verify this by graphing.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SGw-eOmS4pI/AAAAAAAAAGw/90wOqubh8FU/s1600-h/1.gif"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 322px; height: 244px;" src="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SGw-eOmS4pI/AAAAAAAAAGw/90wOqubh8FU/s400/1.gif" alt="" id="BLOGGER_PHOTO_ID_5218614757251277458" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SGxDCTe-vyI/AAAAAAAAAHI/-fz7Ih9ECgQ/s1600-h/4.gif"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 321px; height: 243px;" src="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SGxDCTe-vyI/AAAAAAAAAHI/-fz7Ih9ECgQ/s400/4.gif" alt="" id="BLOGGER_PHOTO_ID_5218619775084576546" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color: rgb(153, 153, 153);font-size:130%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color: rgb(153, 153, 153);font-size:130%;" &gt;4. What is the effect of fixing the total time interval T but increasing the number of samples N?&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Fixing T but increasing N will mean that Δt decreases accordingly. When this happens, Fmax increases since it has an inverse relation with Δt. Also, Fmax has a coefficient of 2, thus it increases faster than N and from the 3rd equation, Δf also increases. We verify this by graphing. The distinction between sharp frequency lines and those that are not sharp are not so evident here.&lt;/p&gt;&lt;p&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SGw-eOmS4pI/AAAAAAAAAGw/90wOqubh8FU/s1600-h/1.gif"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 322px; height: 244px;" src="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SGw-eOmS4pI/AAAAAAAAAGw/90wOqubh8FU/s400/1.gif" alt="" id="BLOGGER_PHOTO_ID_5218614757251277458" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SGw-eLlp1OI/AAAAAAAAAG4/aqtNxmE01Vk/s1600-h/2.gif"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 324px; height: 245px;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SGw-eLlp1OI/AAAAAAAAAG4/aqtNxmE01Vk/s400/2.gif" alt="" id="BLOGGER_PHOTO_ID_5218614756443280610" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;I give myself &lt;span style="color: rgb(255, 204, 0);"&gt;10 points&lt;/span&gt; for this activity since the answers to the questions were verified to be correct by observing the graphs produced in Scilab. Acknowledgment goes to &lt;span style="color: rgb(255, 204, 0);"&gt;Jeric Tugaff and Julie Dado&lt;/span&gt; for help in the Fourier Transform concepts.&lt;br /&gt;&lt;/p&gt; &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/223420158170109027-180300491588363485?l=cole-ap186.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cole-ap186.blogspot.com/feeds/180300491588363485/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=223420158170109027&amp;postID=180300491588363485' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/223420158170109027/posts/default/180300491588363485'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/223420158170109027/posts/default/180300491588363485'/><link rel='alternate' type='text/html' href='http://cole-ap186.blogspot.com/2008/07/activity-5-physical-measurements-from.html' title='Activity 5: Physical Measurements from Discrete Fourier Transforms'/><author><name>Cole</name><uri>http://www.blogger.com/profile/17840780106218077983</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://2.bp.blogspot.com/_6ZpN6X5LZPw/SeFgyvHYwpI/AAAAAAAAAmc/H76Ym0zH_Mw/S220/fabros05+-+Copy.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_6ZpN6X5LZPw/SGwtP5D8iYI/AAAAAAAAAGA/_QvLmF8Vd9s/s72-c/sig.gif' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-223420158170109027.post-318754301552739736</id><published>2008-07-01T11:20:00.000-07:00</published><updated>2008-10-08T19:56:59.899-07:00</updated><title type='text'>Activity 4: Enhancement by Histogram Manipulation</title><content type='html'>&lt;div style="text-align: justify;"&gt;In this activity, we are asked to enhance a poor contrast image by histogram manipulation and backprojection. First, a poor contrast image was obtained from the internet and its &lt;span style="color: rgb(255, 204, 0);"&gt;histogram or probability distribution function (PDF)&lt;/span&gt; was calculated using Scilab. These are shown below. An image is considered to be of poor contrast if its histogram is not well spread out across the gray level range.&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: left;"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SGMDASWUY3I/AAAAAAAAADU/i5aAV3bNsoE/s1600-h/hist.gif"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SGMDASWUY3I/AAAAAAAAADU/i5aAV3bNsoE/s400/hist.gif" alt="" id="BLOGGER_PHOTO_ID_5216016096885498738" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SGL5rT2megI/AAAAAAAAAC8/OtSIi6I12Fw/s1600-h/gray.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SGL5rT2megI/AAAAAAAAAC8/OtSIi6I12Fw/s400/gray.jpg" alt="" id="BLOGGER_PHOTO_ID_5216005840907434498" border="0" /&gt;&lt;/a&gt;source:&lt;span style="font-style: italic;"&gt;http://homepages.i&lt;/span&gt;&lt;span style="font-style: italic;"&gt;nf.ed.ac.uk/rbf/HIPR2crimmins.htm&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Next, we solve for the image's &lt;span style="color: rgb(255, 204, 0);"&gt;cumulative distribution function (CDF)&lt;/span&gt; by using the &lt;span style="font-style: italic; color: rgb(255, 204, 0);"&gt;cumsum&lt;/span&gt; function in Scilab. For example, if the area of the image is 256x256 and H is the histogram function, then &lt;span style="font-style: italic;"&gt;cdf = cumsum([H/(256*256)]); &lt;/span&gt;and we plot it.&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SGM_wLqEiaI/AAAAAAAAAEU/-4mcNZ0UNt0/s1600-h/cdf.gif"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SGM_wLqEiaI/AAAAAAAAAEU/-4mcNZ0UNt0/s400/cdf.gif" alt="" id="BLOGGER_PHOTO_ID_5216082890420685218" border="0" /&gt;&lt;/a&gt; The CDF is just the sum of the histogram values as the gray level increases. In essence, the PDF and CDF   give a complete description of the probability distribution of a random   variable. The original image's CDF here is crooked but the minimum and maximum values are at the same gray levels as the PDF.&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;We now proceed in &lt;span style="color: rgb(255, 204, 0);"&gt;backprojecting &lt;/span&gt;the image pixel values, pixel per pixel, by finding its corresponding y-value in the CDF and assigning these values to the enhanced image.&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: left;"&gt;&lt;span style="font-style: italic;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;im = imread('gray.jpg');&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//Plot histogram&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;val = [];&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;num = [];&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;c = 1;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;for i = 0:1:255&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;  [x,y] = find(im == i); &lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;  val(c) = i;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;  num(c) = length(x); &lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;c = c + 1;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;end&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(51, 204, 0);"&gt;//plot(val,num/(length(im))); &lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(51, 204, 0);"&gt;//title('Normalized histogram of image');&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(51, 204, 0);"&gt;//xlabel('grayscale values');&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//Plot CDF&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;cdf = cumsum([num/(length(im))]);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(51, 204, 0);"&gt;//plot(cdf);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(51, 204, 0);"&gt;//title('Normalized CDF');&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; color: rgb(51, 204, 0);"&gt;//xlabel('grayscale values');&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//Backprojection&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;newim = [];&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;for ii = 1:1:size(im,1)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;  for jj = 1:1:size(im,2)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;     newim(ii,jj) = cdf(im(ii,jj));&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;  end&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;end&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;imwrite(newim, 'newim.jpg');&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Here is the resulting enhanced image.&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;ORIGINAL &amp;amp; ENHANCED&lt;/span&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SGL5rT2megI/AAAAAAAAAC8/OtSIi6I12Fw/s1600-h/gray.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SGL5rT2megI/AAAAAAAAAC8/OtSIi6I12Fw/s400/gray.jpg" alt="" id="BLOGGER_PHOTO_ID_5216005840907434498" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SGM2cFJtkdI/AAAAAAAAADk/JYO2tVFyiAY/s1600-h/newim.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SGM2cFJtkdI/AAAAAAAAADk/JYO2tVFyiAY/s320/newim.jpg" alt="" id="BLOGGER_PHOTO_ID_5216072649472315858" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;In theory, the histogram of the enhanced image should be more spread out across the gray levels, indicating good contrast. Due to this, the resulting CDF of the enhanced image should resemble a line with increasing slope. These graphs are shown below.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SGM7KDL9V-I/AAAAAAAAAEE/Pc7BOcVmb28/s1600-h/enhist.gif"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 322px; height: 247px;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SGM7KDL9V-I/AAAAAAAAAEE/Pc7BOcVmb28/s400/enhist.gif" alt="" id="BLOGGER_PHOTO_ID_5216077837265360866" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SGM7KGyofUI/AAAAAAAAAEM/Eczfg42Ks_Q/s1600-h/encdf.gif"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 325px; height: 246px;" src="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SGM7KGyofUI/AAAAAAAAAEM/Eczfg42Ks_Q/s400/encdf.gif" alt="" id="BLOGGER_PHOTO_ID_5216077838232878402" border="0" /&gt;&lt;/a&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;As expected, the histogram is well spread and the CDF looks fairly like a line.&lt;/span&gt; However, the image is observed to be highly pixelated and this is due to low resolution of the images (111 x 111). More computational power will be required for images with higher resolution.&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;div style="text-align: left;"&gt;&lt;div style="text-align: justify;"&gt;____________________________________________________________________&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Another method of image enhancement using histogram manipulation is by &lt;span style="color: rgb(255, 204, 0);"&gt;mapping the original image's gray levels into a new set of gray levels such that a desired CDF is obtained&lt;/span&gt;. We can do this by &lt;span style="color: rgb(255, 204, 0);"&gt;(1)&lt;/span&gt; finding the CDF value from pixel grayscale, &lt;span style="color: rgb(255, 204, 0);"&gt;(2)&lt;/span&gt; trace this value in desired CDF, &lt;span style="color: rgb(255, 204, 0);"&gt;(3)&lt;/span&gt;  replace pixel value by grayscale value having this CDF value in desired CDF.&lt;img src="file:///C:/Users/Acer/AppData/Local/Temp/moz-screenshot.jpg" alt="" /&gt;&lt;br /&gt;&lt;img src="file:///C:/Users/Acer/AppData/Local/Temp/moz-screenshot-1.jpg" alt="" /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SGmGEcV2u0I/AAAAAAAAAEw/I1MihVkIFJY/s1600-h/Untitled.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SGmGEcV2u0I/AAAAAAAAAEw/I1MihVkIFJY/s400/Untitled.jpg" alt="" id="BLOGGER_PHOTO_ID_5217849054170889026" border="0" /&gt;&lt;/a&gt;The desired CDF can be any function so long as the y-values are from 0 to 1. I will use the function &lt;span style="color: rgb(255, 204, 0);"&gt;G(z) = &lt;/span&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;z^2&lt;/span&gt; where z ranges from 0 to 255. The code for enhancing the image is also shown below.&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SGM_wLqEiaI/AAAAAAAAAEU/-4mcNZ0UNt0/s1600-h/cdf.gif"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 322px; height: 243px;" src="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SGM_wLqEiaI/AAAAAAAAAEU/-4mcNZ0UNt0/s400/cdf.gif" alt="" id="BLOGGER_PHOTO_ID_5216082890420685218" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SGmbOsFzjNI/AAAAAAAAAFA/aGWiIeRowO4/s1600-h/cdf.gif"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 321px; height: 244px;" src="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SGmbOsFzjNI/AAAAAAAAAFA/aGWiIeRowO4/s400/cdf.gif" alt="" id="BLOGGER_PHOTO_ID_5217872319941414098" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//function of desired CDF&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;z = [0:255];&lt;/span&gt; &lt;span style="font-style: italic;"&gt;&lt;br /&gt;G = z^2;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;G = G./max(G);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//method implementation&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;newim = [];&lt;/span&gt; &lt;span style="font-style: italic;"&gt;&lt;br /&gt;for ii = 1:1:size(im,1)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;  for jj = 1:1:size(im,2)&lt;/span&gt; &lt;span style="font-style: italic;"&gt;&lt;br /&gt;E(ii,jj) = cdf(im(ii,jj));&lt;/span&gt; &lt;span style="font-style: italic;"&gt;&lt;br /&gt;end&lt;/span&gt; &lt;span style="font-style: italic;"&gt;&lt;br /&gt;end&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//interpolation&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;newim = interp1(G,z,E);&lt;/span&gt; &lt;span style="font-style: italic;"&gt;&lt;br /&gt;imshow(newim, [0 255]);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;newim = round(newim);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//plot histogram&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;value = [];&lt;/span&gt; &lt;span style="font-style: italic;"&gt;&lt;br /&gt;number = [];&lt;/span&gt; &lt;span style="font-style: italic;"&gt;&lt;br /&gt;c1 = 1;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;for i = 0:1:255&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;  [x,y] = find(newim == i);&lt;/span&gt; &lt;span style="font-style: italic;"&gt;&lt;br /&gt;value(c1) = i;&lt;/span&gt; &lt;span style="font-style: italic;"&gt;&lt;br /&gt;number(c1) = length(x);&lt;/span&gt; &lt;span style="font-style: italic;"&gt;&lt;br /&gt;c1 = c1 + 1;&lt;/span&gt; &lt;span style="font-style: italic;"&gt;&lt;br /&gt;end&lt;/span&gt; &lt;span style="font-style: italic;"&gt;&lt;br /&gt;//plot(value, number/(length(newim)));&lt;/span&gt; &lt;span style="font-style: italic;"&gt;&lt;br /&gt;//title('Histogram of enhanced image');&lt;/span&gt; &lt;span style="font-style: italic;"&gt;&lt;br /&gt;//xlabel('grayscale values');&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//plot CDF&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;cdf = cumsum([number/(length(newim))]);&lt;/span&gt; &lt;span style="font-style: italic;"&gt;&lt;br /&gt;plot(cdf);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;title('Enhanced CDF');&lt;/span&gt; &lt;span style="font-style: italic;"&gt;&lt;br /&gt;xlabel('grayscale values');&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;And here is the result:&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;ORIGINAL, 1ST METHOD ENHANCEMENT, 2ND METHOD ENHANCEMENT&lt;/span&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SGL5rT2megI/AAAAAAAAAC8/OtSIi6I12Fw/s1600-h/gray.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SGL5rT2megI/AAAAAAAAAC8/OtSIi6I12Fw/s400/gray.jpg" alt="" id="BLOGGER_PHOTO_ID_5216005840907434498" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SGM2cFJtkdI/AAAAAAAAADk/JYO2tVFyiAY/s1600-h/newim.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SGM2cFJtkdI/AAAAAAAAADk/JYO2tVFyiAY/s320/newim.jpg" alt="" id="BLOGGER_PHOTO_ID_5216072649472315858" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SGmiOI1Kp8I/AAAAAAAAAFQ/y-21GmSzXc4/s1600-h/new.gif"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 111px; height: 111px;" src="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SGmiOI1Kp8I/AAAAAAAAAFQ/y-21GmSzXc4/s400/new.gif" alt="" id="BLOGGER_PHOTO_ID_5217880007057778626" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;Shown below are the histogram and CDF of the enhanced image in the 2nd method. The PDF is also well spread across the graylevel range while the CDF followed the desired CDF, which is a parabola (G(z) = z^2).&lt;br /&gt;&lt;br /&gt;The enhanced image from the 1st method is darker than in the 2nd method. &lt;span style="color: rgb(255, 204, 0);"&gt;I&lt;/span&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;n terms of contrast, the 1st method is better&lt;/span&gt;. Any of the 2 methods can be used for any other poor contrast image in attempting to enhance it. I cannot decide as of the moment which of the 2 is "better" per se.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SGnYEfU_nrI/AAAAAAAAAFY/Cwq6DMzCCAU/s1600-h/hist.gif"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 321px; height: 244px;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SGnYEfU_nrI/AAAAAAAAAFY/Cwq6DMzCCAU/s400/hist.gif" alt="" id="BLOGGER_PHOTO_ID_5217939214926061234" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SGnYEm2jeAI/AAAAAAAAAFg/_Q3lH1oFg4E/s1600-h/des.gif"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 321px; height: 244px;" src="http://1.bp.blogspot.com/_6ZpN6X5LZPw/SGnYEm2jeAI/AAAAAAAAAFg/_Q3lH1oFg4E/s400/des.gif" alt="" id="BLOGGER_PHOTO_ID_5217939216945870850" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;I give myself &lt;span style="color: rgb(255, 204, 0);"&gt;10 points&lt;/span&gt; for this activity since the images were enhanced significantly compared to the original image. This can be shown not only in the images themselves but also from the PDF and CDF of the enhanced images. Thanks to &lt;span style="color: rgb(255, 204, 0);"&gt;Jeric Tugaff&lt;/span&gt; for help in implementing the 2nd method in this activity.&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/223420158170109027-318754301552739736?l=cole-ap186.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cole-ap186.blogspot.com/feeds/318754301552739736/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=223420158170109027&amp;postID=318754301552739736' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/223420158170109027/posts/default/318754301552739736'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/223420158170109027/posts/default/318754301552739736'/><link rel='alternate' type='text/html' href='http://cole-ap186.blogspot.com/2008/06/activity-4-enhancement-by-histogram.html' title='Activity 4: Enhancement by Histogram Manipulation'/><author><name>Cole</name><uri>http://www.blogger.com/profile/17840780106218077983</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://2.bp.blogspot.com/_6ZpN6X5LZPw/SeFgyvHYwpI/AAAAAAAAAmc/H76Ym0zH_Mw/S220/fabros05+-+Copy.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_6ZpN6X5LZPw/SGMDASWUY3I/AAAAAAAAADU/i5aAV3bNsoE/s72-c/hist.gif' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-223420158170109027.post-6415815117114110861</id><published>2008-06-24T11:18:00.000-07:00</published><updated>2008-06-30T17:00:53.441-07:00</updated><title type='text'>Activity 3: Image Types and Basic Image Enhancement</title><content type='html'>In this activity, we are asked to:&lt;div style="text-align: justify;"&gt;1. Collect images of different types and show their properties using the&lt;span style="color: rgb(255, 204, 0);"&gt; &lt;/span&gt;&lt;span style="font-style: italic; color: rgb(255, 204, 0);"&gt;imfinfo&lt;/span&gt; function of Scilab.&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;2. Open the previously acquired scanned image (I will be using a leaf) and convert it into grayscale if it is still colored.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;3. Examine the histogram of the images. Convert them into black and white using &lt;span style="font-style: italic; color: rgb(255, 204, 0);"&gt;im2bw&lt;/span&gt;. Choose the best threshold from the histogram.&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;4. Finally, apply the area calculation from last week to determine the area of the image.&lt;br /&gt;&lt;/div&gt;____________________________________________________________________&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="font-size:130%;"&gt;1. Binary Image&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SGBUsUFGL5I/AAAAAAAAABU/m8VOwfmH-LE/s1600-h/smith.gif"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 120px; height: 76px;" src="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SGBUsUFGL5I/AAAAAAAAABU/m8VOwfmH-LE/s320/smith.gif" alt="" id="BLOGGER_PHOTO_ID_5215261488776097682" border="0" /&gt;&lt;/a&gt;FileName: smith.gif&lt;br /&gt;&lt;div style="text-align: left;"&gt;FileSize: 1104&lt;br /&gt;Format: GIF&lt;br /&gt;Width: 244&lt;br /&gt;Height: 153&lt;br /&gt;Depth: 8&lt;br /&gt;StorageType: indexed&lt;br /&gt;NumberOfColors: 2&lt;br /&gt;ResolutionUnit: centimeter&lt;br /&gt;                                  XResolution: 72.000000&lt;br /&gt;                                  YResolution: 72.000000&lt;br /&gt;&lt;/div&gt;source: &lt;span style="font-style: italic;"&gt;http://www.sharewareplaza.com/Signature-Creator-download_31667.html&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold;font-size:130%;" &gt;2. Grayscale Image&lt;/span&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SGBgY0pKQ9I/AAAAAAAAABk/28RirKwf9KQ/s1600-h/xray2.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 88px; height: 93px;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SGBgY0pKQ9I/AAAAAAAAABk/28RirKwf9KQ/s320/xray2.jpg" alt="" id="BLOGGER_PHOTO_ID_5215274348059444178" border="0" /&gt;&lt;/a&gt; FileName: xray.jpg&lt;br /&gt;FileSize: 4424&lt;br /&gt;Format: JPEG&lt;br /&gt;Width: 183&lt;br /&gt;Height: 193&lt;br /&gt;Depth: 8&lt;br /&gt;StorageType: indexed&lt;br /&gt;NumberOfColors: 256&lt;br /&gt;ResolutionUnit: inch&lt;br /&gt;XResolution: 72.000000&lt;br /&gt;YResolution: 72.000000&lt;br /&gt;source: &lt;span style="font-style: italic;"&gt;http://www.answers.com/topic/x-ray?cat=health&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:130%;" &gt;3. Truecolor Image&lt;br /&gt;&lt;/span&gt;&lt;div style="text-align: left;"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SGBd4MYApLI/AAAAAAAAABc/LC1Oaw3wSsU/s1600-h/butterfly.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 131px; height: 99px;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SGBd4MYApLI/AAAAAAAAABc/LC1Oaw3wSsU/s320/butterfly.jpg" alt="" id="BLOGGER_PHOTO_ID_5215271588471022770" border="0" /&gt;&lt;/a&gt; FileName: butterfly.jpg&lt;br /&gt;FileSize: 14300&lt;br /&gt;Format: JPEG&lt;br /&gt;Width: 267&lt;br /&gt;Height: 200&lt;br /&gt;Depth: 8&lt;br /&gt;StorageType: truecolor&lt;br /&gt;NumberOfColors: 0&lt;br /&gt;ResolutionUnit: centimeter&lt;br /&gt;XResolution: 72.000000&lt;br /&gt;YResolution: 72.000000&lt;br /&gt;source: &lt;span style="font-style: italic;"&gt;http://monarch-butterfly.info&lt;/span&gt;&lt;/div&gt;&lt;span style="font-weight: bold;"&gt;______________________________________________________________&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div style="text-align: justify;"&gt;Here is the scanned image of a leaf I mentioned in last week's report and its properties.&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SGBlTySuaSI/AAAAAAAAAB0/U1NdDbWAMTk/s1600-h/leaf2.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 125px; height: 134px;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SGBlTySuaSI/AAAAAAAAAB0/U1NdDbWAMTk/s320/leaf2.jpg" alt="" id="BLOGGER_PHOTO_ID_5215279759087266082" border="0" /&gt;&lt;/a&gt; FileName: leaf2.jpg&lt;br /&gt;FileSize: 2851&lt;br /&gt;Format: JPEG&lt;br /&gt;Width: 170&lt;br /&gt;Height: 181&lt;br /&gt;Depth: 8&lt;br /&gt;StorageType: indexed&lt;br /&gt;NumberOfColors: 256&lt;br /&gt;ResolutionUnit: inch&lt;br /&gt;XResolution: 72.000000&lt;br /&gt;                    YResolution: 72.000000&lt;br /&gt;&lt;br /&gt;It was converted into grayscale by using the following lines of code.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;image = imread('leaf.jpg');&lt;br /&gt;grayimage = im2gray(image);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;imwrite(grayimage, 'leaf2.jpg');&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;span&gt;N&lt;/span&gt;&lt;span&gt;ext&lt;/span&gt;&lt;span&gt;, we create a histogram plot of the number of pixels falling under a specific grayscale value. &lt;span style="color: rgb(255, 204, 0);"&gt;A value of 0 corresponds to black while&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style="color: rgb(255, 204, 0);"&gt; 255 is for white.&lt;/span&gt; &lt;/span&gt;&lt;span&gt;The code for plotting the histogram and the resulting graph are shown below.&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;span style="font-style: italic;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;//original code c/o Jeric Tugaff&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0);"&gt; &lt;/span&gt;&lt;span style="font-style: italic;"&gt;image = imread('&lt;/span&gt;&lt;span style="font-style: italic;"&gt;leaf2.jpg');&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;val=[];&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;num=[];&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;counter=1;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;for i=0:1:255&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;[x,y]=find(image==i);&lt;/span&gt;    &lt;span style="color: rgb(51, 204, 0);"&gt;//finds where image==i&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;val(counter)=i;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;num(counter)=length(x);&lt;/span&gt; &lt;span style="color: rgb(51, 204, 0);"&gt;//find how many pixels of leaf have a value of i&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;counter=counter+1;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;end&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;plot(val, num);&lt;/span&gt;   &lt;span style="color: rgb(51, 204, 0);"&gt;//plot&lt;/span&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;div style="text-align: justify;"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SGCrgSWHheI/AAAAAAAAACM/e-kRb9tVVeI/s1600-h/hist.gif"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SGCrgSWHheI/AAAAAAAAACM/e-kRb9tVVeI/s400/hist.gif" alt="" id="BLOGGER_PHOTO_ID_5215356939663803874" border="0" /&gt;&lt;/a&gt;From this histogram, we can see that there is a dip in the 100-180 region. We can now convert our grayscaled leaf image into black and white by using &lt;span style="font-style: italic; color: rgb(255, 204, 0);"&gt;im2bw&lt;/span&gt;. Our threshold value can range from 0.4 to 0.7. I used &lt;span style="color: rgb(255, 204, 0);"&gt;0.5&lt;/span&gt; in this case. However, note that the parameters for the &lt;span style="font-style: italic; color: rgb(255, 204, 0);"&gt;follow&lt;/span&gt; function (the function that follows the contour of the image) require that the object has a value of 1(white) and the background has a value of 0(black). &lt;span style="color: rgb(255, 204, 0);"&gt;This means that the colors of our current B&amp;amp;W image have to be inverted before we can calculate for its area.&lt;/span&gt; We can do this in Scilab by simple matrix manipulation: &lt;span style="font-style: italic;"&gt;BWleaf&lt;/span&gt;&lt;span style="font-style: italic;"&gt; = 1 - BWleaf;&lt;/span&gt; and again we write the resulting image into a file.&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;       BEFORE, AFTER&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;, &amp;amp; AFTER STILL...&lt;/span&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SGBlTySuaSI/AAAAAAAAAB0/U1NdDbWAMTk/s1600-h/leaf2.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 110px; height: 117px;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SGBlTySuaSI/AAAAAAAAAB0/U1NdDbWAMTk/s320/leaf2.jpg" alt="" id="BLOGGER_PHOTO_ID_5215279759087266082" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SGDIqtNd4jI/AAAAAAAAACs/KmoRHcHN200/s1600-h/leafbw.bmp"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 110px; height: 118px;" src="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SGDIqtNd4jI/AAAAAAAAACs/KmoRHcHN200/s320/leafbw.bmp" alt="" id="BLOGGER_PHOTO_ID_5215389004511175218" border="0" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SGDUBuSmmwI/AAAAAAAAAC0/f3gPGOiBXVg/s1600-h/bwleaf.bmp"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 110px; height: 118px;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SGDUBuSmmwI/AAAAAAAAAC0/f3gPGOiBXVg/s320/bwleaf.bmp" alt="" id="BLOGGER_PHOTO_ID_5215401494566050562" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;We can do the same for any other image. The procedure would be as follows:&lt;br /&gt;&lt;ul style="color: rgb(255, 204, 0);"&gt;&lt;li&gt;open the image&lt;br /&gt;&lt;/li&gt;&lt;li&gt;convert to grayscale&lt;/li&gt;&lt;li&gt;plot histogram&lt;/li&gt;&lt;li&gt;convert to B&amp;amp;W using a suitable threshold value&lt;/li&gt;&lt;li&gt;invert colors &lt;/li&gt;&lt;/ul&gt;&lt;div style="text-align: justify;"&gt;Whew! After all of that, we are now ready to calculate for the area of the leaf using Green's theorem.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;[x,y] = follow(BWleaf);&lt;/span&gt;                 &lt;span style="color: rgb(51, 204, 0);"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;x_1(1) = x(length(x)); &lt;/span&gt;             &lt;span style="color: rgb(51, 204, 0);"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;x_1(2:length(x)) = x(1:(length(x) - 1));&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;y_1(1) = y(length(y));&lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;&lt;span style="font-style: italic;"&gt; &lt;/span&gt;            &lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;y_1(2:length(y)) = y(1:(length(y) - 1));&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;A = abs(1/2*(sum((x.*y_1) - (y.*x_1))));&lt;br /&gt;theo = sum(BWleaf);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span&gt;Upon&lt;/span&gt;&lt;span style="font-style: italic;"&gt; &lt;/span&gt;&lt;span&gt;comparing&lt;/span&gt;&lt;span&gt; the values, we get &lt;span style="color: rgb(255, 204, 0);"&gt;theo = 7202&lt;/span&gt; and &lt;span style="color: rgb(255, 204, 0);"&gt;A = 7000.5&lt;/span&gt;.&lt;/span&gt;&lt;span style="font-style: italic;"&gt; &lt;/span&gt;&lt;span&gt;This yields an error of only &lt;span style="color: rgb(255, 204, 0);"&gt;2.8%&lt;/span&gt;. This error comes from the image of the leaf having some &lt;span style="color: rgb(255, 204, 0);"&gt;concavities&lt;/span&gt;. According to the other proof of Green's theorem (from A2 - Area estimation of images with defined edges.pdf),&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div style="text-align: center; font-style: italic; color: rgb(255, 204, 0);"&gt;&lt;span style="font-size:85%;"&gt;so long as a closed curve is convex (no concavities) its area may be computed by&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: center;"&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-style: italic;"&gt;summing the area of its “pie slices.”&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-style: italic;"&gt;&lt;/span&gt;&lt;/span&gt;Thus, Green's theorem for estimating areas will not work all of the time. This may be why the error between calculated and theoretical area is large compared to the regular polygons' areas from last time.&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;span&gt;____________________________________________________________________&lt;br /&gt;&lt;br /&gt;I give myself &lt;span style="color: rgb(255, 204, 0);"&gt;10 points &lt;/span&gt;for this activity since like last week, the error between the theoretical and calculated areas are &lt;span style="color: rgb(255, 204, 0);"&gt;less than 5%&lt;/span&gt;. Special thanks goes to &lt;span style="color: rgb(255, 204, 0);"&gt;Jeric Tugaff and Jorge Presto&lt;/span&gt; for the help in plotting the histogram of the grayscaled image.&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;&lt;span style="font-style: italic;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/223420158170109027-6415815117114110861?l=cole-ap186.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cole-ap186.blogspot.com/feeds/6415815117114110861/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=223420158170109027&amp;postID=6415815117114110861' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/223420158170109027/posts/default/6415815117114110861'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/223420158170109027/posts/default/6415815117114110861'/><link rel='alternate' type='text/html' href='http://cole-ap186.blogspot.com/2008/06/activity-3-image-types-and-basic-image.html' title='Activity 3: Image Types and Basic Image Enhancement'/><author><name>Cole</name><uri>http://www.blogger.com/profile/17840780106218077983</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://2.bp.blogspot.com/_6ZpN6X5LZPw/SeFgyvHYwpI/AAAAAAAAAmc/H76Ym0zH_Mw/S220/fabros05+-+Copy.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_6ZpN6X5LZPw/SGBUsUFGL5I/AAAAAAAAABU/m8VOwfmH-LE/s72-c/smith.gif' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-223420158170109027.post-5124658386501006651</id><published>2008-06-17T11:20:00.000-07:00</published><updated>2008-06-26T06:39:59.677-07:00</updated><title type='text'>Activity 2: Area Estimation of Images with Defined Edges</title><content type='html'>&lt;div style="text-align: justify;"&gt;In this activity, we are asked to estimate areas of different images using Scilab. First, I created several simple images using MS Paint. My first image was a rectangle. &lt;span style="color: rgb(255, 204, 0);"&gt;It is important that the background is black while the shape is white.&lt;/span&gt; The image can be saved under any extension (.jpg, .bmp, etc). &lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SFnEByVAITI/AAAAAAAAAAc/kqfA6pq-pyk/s1600-h/rect.JPG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SFnEByVAITI/AAAAAAAAAAc/kqfA6pq-pyk/s320/rect.JPG" alt="" id="BLOGGER_PHOTO_ID_5213413578626834738" border="0" /&gt;&lt;/a&gt;Here is the Scilab code that generates the area of this white rectangle.&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;rect = imread('rect.jpg');  &lt;/span&gt;   &lt;span style="color: rgb(51, 204, 0);"&gt;//load image&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;rect = im2bw(rect,0.5);&lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;&lt;span style="font-style: italic;"&gt;&lt;/span&gt;          //convert to binary&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;[x,y] = follow(rect);&lt;/span&gt;                 &lt;span style="color: rgb(51, 204, 0);"&gt;//function that follows the contour&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;x_1(1) = x(length(x)); &lt;/span&gt;             &lt;span style="color: rgb(51, 204, 0);"&gt;//create x_i+1 array&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;x_1(2:length(x)) = x(1:(length(x) - 1));&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;y_1(1) = y(length(y));&lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;&lt;span style="font-style: italic;"&gt; &lt;/span&gt;            //create y_i+1 array&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;y_1(2:length(y)) = y(1:(length(y) - 1));&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;theo = (max(y)-min(y))*(max(x)-min(y));&lt;/span&gt;     &lt;span style="color: rgb(51, 204, 0);"&gt;//Theoretical Area of rectangle&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;A = abs(1/2*(sum((x.*y_1) - (y.*x_1))));&lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;&lt;span style="font-style: italic;"&gt; &lt;/span&gt;      //Gre&lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);"&gt;en's function for area estimation&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;After running the code, the theoretical area for the rectangle is &lt;span style="color: rgb(255, 204, 0);"&gt;theo = 13152&lt;/span&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;,&lt;/span&gt; while the area calculated from Green's theorem is &lt;span style="color: rgb(255, 204, 0);"&gt;A = 13056&lt;/span&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;.&lt;/span&gt; There is an error of&lt;span style="color: rgb(255, 204, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;0.73%&lt;/span&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;.&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;We can also try this method out using various shapes. For a circle, the code is similar. Just replace the &lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SFnJlBXY4cI/AAAAAAAAAAs/oq_u-zOUaX0/s1600-h/circle.JPG"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://4.bp.blogspot.com/_6ZpN6X5LZPw/SFnJlBXY4cI/AAAAAAAAAAs/oq_u-zOUaX0/s320/circle.JPG" alt="" id="BLOGGER_PHOTO_ID_5213419681516937666" border="0" /&gt;&lt;/a&gt;image, image name, and the theoretical formula of its area.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;theo = 4536&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;A = 4532&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;error = 0.09%&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Again, for another circle with a smaller radius:&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SFnKwg6p07I/AAAAAAAAAA0/5gk1kMqYE_8/s1600-h/smcircle.JPG"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://3.bp.blogspot.com/_6ZpN6X5LZPw/SFnKwg6p07I/AAAAAAAAAA0/5gk1kMqYE_8/s320/smcircle.JPG" alt="" id="BLOGGER_PHOTO_ID_5213420978476536754" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;theo = 346&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;A = 341&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 0);"&gt;error = 1.45%&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;It can be observed that there is a higher error for a smaller circle than a bigger one. This may be because a smaller circle generated in MS Paint looks less like a "real circle" due to the pixels being square. A bigger circle will look more like a circle since more pixels are being used to smoothen the circle's boundary.&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;In summary, the Green's method for calculating areas of images with definite edges is nice and efficient since the computed areas are within 5% error of their theoretical values.&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;I give myself &lt;span style="color: rgb(255, 204, 0);"&gt;10 points&lt;/span&gt;&lt;span style="font-weight: bold;"&gt; &lt;/span&gt;for this activity since the computed areas were &lt;span style="color: rgb(255, 204, 0);"&gt;within 5%&lt;/span&gt; of their theoretical values. Thanks to &lt;span style="color: rgb(255, 204, 0);"&gt;Jeric Tugaff, Julie Dado, and Rica Mercado&lt;/span&gt; for their help in the Scilab code syntax and in loading the SIP toolbox.&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="font-style: italic;"&gt;Next time, I will try to see if this method works on a scanned image of a relatively flat object (i.e. leaf, ID, cards, etc...).&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/223420158170109027-5124658386501006651?l=cole-ap186.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cole-ap186.blogspot.com/feeds/5124658386501006651/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=223420158170109027&amp;postID=5124658386501006651' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/223420158170109027/posts/default/5124658386501006651'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/223420158170109027/posts/default/5124658386501006651'/><link rel='alternate' type='text/html' href='http://cole-ap186.blogspot.com/2008/06/activity-21-area-estimation-of-images.html' title='Activity 2: Area Estimation of Images with Defined Edges'/><author><name>Cole</name><uri>http://www.blogger.com/profile/17840780106218077983</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://2.bp.blogspot.com/_6ZpN6X5LZPw/SeFgyvHYwpI/AAAAAAAAAmc/H76Ym0zH_Mw/S220/fabros05+-+Copy.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_6ZpN6X5LZPw/SFnEByVAITI/AAAAAAAAAAc/kqfA6pq-pyk/s72-c/rect.JPG' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-223420158170109027.post-6954648668439861108</id><published>2008-06-12T10:40:00.000-07:00</published><updated>2008-06-24T03:23:24.971-07:00</updated><title type='text'>Activity 1: Digital Scanning</title><content type='html'>We obtained a scanned graph from the&lt;span style="color: rgb(153, 255, 153);"&gt; &lt;/span&gt;&lt;span style="font-style: italic; color: rgb(255, 204, 0);"&gt;Canadian Journal of Physics (1951)&lt;/span&gt;&lt;span style="color: rgb(0, 102, 0);"&gt; &lt;/span&gt;and tried to reproduce it in MS Excel using some basic image processing. Here are the steps I used in doing this activity:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;1. Get pixel location of the graph's origin, points in the graph and pixel distances of axes tick marks.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;2. Subtract the offset due to orientation of the graph's origin and MS Paint's origin.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;3. Use ratio and proportion to find corresponding pixels and points on the graph.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;4. Graph the data using MS Excel and overlay the original graph for comparison.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;And here is the result:&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SFCIZau6ReI/AAAAAAAAAAM/PQ5M7vC1YJs/s1600-h/Picture1.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://2.bp.blogspot.com/_6ZpN6X5LZPw/SFCIZau6ReI/AAAAAAAAAAM/PQ5M7vC1YJs/s320/Picture1.jpg" alt="" id="BLOGGER_PHOTO_ID_5210814739121849826" border="0" /&gt;&lt;/a&gt;The red points are the reconstructed data. The original points on the graph are in black.&lt;br /&gt;&lt;br /&gt;I give myself &lt;span style="font-weight: bold; color: rgb(255, 204, 0);"&gt;10 points&lt;/span&gt; for this activity since there is a good correspondence between the original and reconstructed data. (The black points were overlapped by the red points, which show good correspondence.)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/223420158170109027-6954648668439861108?l=cole-ap186.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cole-ap186.blogspot.com/feeds/6954648668439861108/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=223420158170109027&amp;postID=6954648668439861108' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/223420158170109027/posts/default/6954648668439861108'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/223420158170109027/posts/default/6954648668439861108'/><link rel='alternate' type='text/html' href='http://cole-ap186.blogspot.com/2008/06/activity-1-digital-scanning.html' title='Activity 1: Digital Scanning'/><author><name>Cole</name><uri>http://www.blogger.com/profile/17840780106218077983</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://2.bp.blogspot.com/_6ZpN6X5LZPw/SeFgyvHYwpI/AAAAAAAAAmc/H76Ym0zH_Mw/S220/fabros05+-+Copy.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_6ZpN6X5LZPw/SFCIZau6ReI/AAAAAAAAAAM/PQ5M7vC1YJs/s72-c/Picture1.jpg' height='72' width='72'/><thr:total>1</thr:total></entry></feed>
