tag:blogger.com,1999:blog-73457638715858171172024-02-19T18:18:16.125-08:00Dennis' Blog for AP186dennisivan89http://www.blogger.com/profile/04476991777095665795noreply@blogger.comBlogger14125tag:blogger.com,1999:blog-7345763871585817117.post-60099668184096819022010-09-22T21:45:00.000-07:002010-09-23T08:53:26.591-07:00AP 186 Act14 - Image CompressionNowadays storage capacities get bigger and grow faster so there's not much problem comparing it in the past where storage was an issue. Images were compressed to save storage space. In this activity, we'll explore about image compression using PCA or Principal Components Analysis.<br /><br />In Fourier Transform, any signal can be represented by a sum of sinusoids (your basis functions) multiplied by coefficients. This concept of representing a signal with basis functions and proper coefficients is similar to PCA. In this case we will be doing it for images.<br /><br />First I choose an image:<br /><br /><div style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgCKmjPIFic6JVYLxVXHUXSe6UKYNxbZ-06EZgsAGTJk5KCo5u568GODSo63WFaOohaulnszYmKR8BIn4mv3ClM1ZZYLrIQHLYSlkmQONX_t1NcgDpfOxNATpY3OkfBuGHDLjlcbsdjPng/s1600/pic.jpg"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 240px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgCKmjPIFic6JVYLxVXHUXSe6UKYNxbZ-06EZgsAGTJk5KCo5u568GODSo63WFaOohaulnszYmKR8BIn4mv3ClM1ZZYLrIQHLYSlkmQONX_t1NcgDpfOxNATpY3OkfBuGHDLjlcbsdjPng/s320/pic.jpg" alt="" id="BLOGGER_PHOTO_ID_5520101118753169186" border="0" /></a>chosen image for this activity<br /></div><br />and convert it to grayscale:<br /><br /><div style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgK_wsyoUyQX7ytk0acsaevDmufNRDHwc7zibGxuzVhd5ZVYEjjZjgFmZO3-Lm_Ju2hdUOAdrRipeQ1SKjKfHZEENhwcp9UQmEPFo2NIe5YvzrYRN_t0NrgSiKOuR3baqxtAQnmmkfSiNs/s1600/pic_gray.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 240px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgK_wsyoUyQX7ytk0acsaevDmufNRDHwc7zibGxuzVhd5ZVYEjjZjgFmZO3-Lm_Ju2hdUOAdrRipeQ1SKjKfHZEENhwcp9UQmEPFo2NIe5YvzrYRN_t0NrgSiKOuR3baqxtAQnmmkfSiNs/s320/pic_gray.PNG" alt="" id="BLOGGER_PHOTO_ID_5520101123447348610" border="0" /></a>grayscale of the image<br /></div><br />Then we cut up the image into 10 x 10 blocks and reshape this block into a 1-D array. We do this for the rest of the image and we'll have an n x p matrix where n is the number of 10 x 10 blocks and p is the number of elements per block (100 in this case). Next we apply PCA using the "pca" function in scilab.<br /><br /><div style="text-align: left;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDUzId5a5GnnkyE2yZRYkmgj0Dm_OEPEJN8k1SZ4IP_w52wKhEtWBx1ftmJYSFTZjifriIRfQqbRfo1dwTtFEf3Q7NBlB4Pf-8NLO9cHlTqsUiAulmi4F5adWdJXDoXbRKiWGgV_-oR5Q/s1600/corrcirc.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 234px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDUzId5a5GnnkyE2yZRYkmgj0Dm_OEPEJN8k1SZ4IP_w52wKhEtWBx1ftmJYSFTZjifriIRfQqbRfo1dwTtFEf3Q7NBlB4Pf-8NLO9cHlTqsUiAulmi4F5adWdJXDoXbRKiWGgV_-oR5Q/s320/corrcirc.PNG" alt="" id="BLOGGER_PHOTO_ID_5520131316270802162" border="0" /></a></div><div style="text-align: center;">correlation circle<br /></div><br /><br /><div style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdomU4fLXDdLu1fo1CHO0MPCEiJ_jk01uoo8GubWm9SW5O-0ytfBWpt4Pc0jB-pFV8zyrcyVaXUFoBJKarptrhul84GyKwZNt_HXSMeW_3V4sfE-8_vCnL5VpZrxHay8NEOCB3qtBovmQ/s1600/eigenvalues.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 257px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdomU4fLXDdLu1fo1CHO0MPCEiJ_jk01uoo8GubWm9SW5O-0ytfBWpt4Pc0jB-pFV8zyrcyVaXUFoBJKarptrhul84GyKwZNt_HXSMeW_3V4sfE-8_vCnL5VpZrxHay8NEOCB3qtBovmQ/s320/eigenvalues.PNG" alt="" id="BLOGGER_PHOTO_ID_5520131319738998642" border="0" /></a>Eigenvalues<br /></div><br /><br /><div style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6rXV881cvn-RL3SugU3qP5OybtphE8C5uqy3RCzwPk2spYDHgVnZyQ_x1fj6mXFL0t2AWI3N8HQstvdTr_QCRV3qRj5hEjgg-AEyy5xn8WYJkU1PmtC2IHmgXNJYfP3m-UFq9Flcnu8o/s1600/eigenvectors.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 288px; height: 287px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6rXV881cvn-RL3SugU3qP5OybtphE8C5uqy3RCzwPk2spYDHgVnZyQ_x1fj6mXFL0t2AWI3N8HQstvdTr_QCRV3qRj5hEjgg-AEyy5xn8WYJkU1PmtC2IHmgXNJYfP3m-UFq9Flcnu8o/s320/eigenvectors.PNG" alt="" id="BLOGGER_PHOTO_ID_5520131325561804642" border="0" /></a>Eigenvectors<br /><br /></div><br />The "pca" function gives 3 output - the eigenvalues, the eigenvectors, and the coefficients. The image can be reconstructed from these and its quality depends on the number of eigenvectors used (i.e. the amount of compression).<br /><br />And the reconstructions are:<br /><br /><div style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjyfASHfJiEd23zyMLQ9lWsftLUn7MnO-2w9t5HuIYP0LdrC6CRnlv_VbOvKvQrT0-Q2YiSIt7R-tP8vge6o2R4hnbvekdj7yqRuWySjYbckF_ScJOtsDQZUMZg-UkCzyP1MhQj_6YxjXQ/s1600/pic_80.5_1.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 240px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjyfASHfJiEd23zyMLQ9lWsftLUn7MnO-2w9t5HuIYP0LdrC6CRnlv_VbOvKvQrT0-Q2YiSIt7R-tP8vge6o2R4hnbvekdj7yqRuWySjYbckF_ScJOtsDQZUMZg-UkCzyP1MhQj_6YxjXQ/s320/pic_80.5_1.PNG" alt="" id="BLOGGER_PHOTO_ID_5520101129636905410" border="0" /></a>using 1 out of 100 eigenvectors (cumsum of 80.5% for eigenvalues) (1.23 MB)<br /><br /></div><br /><div style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLtUKgz5DYT8ASLKmpuboX7RmO59olq0mVTw4ZG9i-YAZuEFw3v5rvx-TTtRmlYgtK_x5nQLXw3JnrHJ41q7nYMKb4omt64ropmpn0I62bagsbyuaeaeDvV9kfLHDxl8EbBW-mxa66D5E/s1600/pic_85.5_2.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 240px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLtUKgz5DYT8ASLKmpuboX7RmO59olq0mVTw4ZG9i-YAZuEFw3v5rvx-TTtRmlYgtK_x5nQLXw3JnrHJ41q7nYMKb4omt64ropmpn0I62bagsbyuaeaeDvV9kfLHDxl8EbBW-mxa66D5E/s320/pic_85.5_2.PNG" alt="" id="BLOGGER_PHOTO_ID_5520101134328740850" border="0" /></a>using 2 out of 100 eigenvectors. (cumsum of 85.5% for eigenvalues)Here the faces of the people are unrecognizable. (1.36 MB)<br /><br /></div><br /><div style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6A8ST0CTrmv7toTtvycU4cSnbff8GxD9kfAZNK2Z_KYdQtwZZ59BFE2kGjdkJv5Cafl3DxehHs6U01xOYYlwJkIbfAFYhO-2XtBbkdrxeRD5uOXNak9BdvsJ6PdYhgkd4l2GEE6fhJOs/s1600/pic_91_4.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 240px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6A8ST0CTrmv7toTtvycU4cSnbff8GxD9kfAZNK2Z_KYdQtwZZ59BFE2kGjdkJv5Cafl3DxehHs6U01xOYYlwJkIbfAFYhO-2XtBbkdrxeRD5uOXNak9BdvsJ6PdYhgkd4l2GEE6fhJOs/s320/pic_91_4.PNG" alt="" id="BLOGGER_PHOTO_ID_5520101146206030450" border="0" /></a>using 4 out of 100 eigenvectors. (cumsum of 91% for eigenvalues)Some faces begin to be a little recognizable (1.44 MB)<br /><br /></div><br /><div style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEialWLZrP4C-2_3IdYlEryAKz7K2_xH1RSOnbxKnn1vWHxS3NDNIiAS2cpXeKZtgSPhbb2OMsiMpIPGtAzlcdxNvczcjxTTKXaX4PRGqRJJ9EsoqfI0wUphD6-fd1Mmcd5nQtqOA3e4jGU/s1600/pic_95.2_10.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 240px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEialWLZrP4C-2_3IdYlEryAKz7K2_xH1RSOnbxKnn1vWHxS3NDNIiAS2cpXeKZtgSPhbb2OMsiMpIPGtAzlcdxNvczcjxTTKXaX4PRGqRJJ9EsoqfI0wUphD6-fd1Mmcd5nQtqOA3e4jGU/s320/pic_95.2_10.PNG" alt="" id="BLOGGER_PHOTO_ID_5520115643534590930" border="0" /></a>using 10 out of 100 eigenvectors (cumsum of 95.2% for eigenvalues) (1.46 MB)<br /></div><br /><br /><div style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjF0Y9Taq8Qv_2Y0ylm-_ITinRDx-fM-Hq-tP9Rj0Hmpst0P3a-Wh8zBz9_dSVdUltlLpMPSAeHaMbQ-cgkT1V1X0RwlA1LqmZadkkdrdwErrjCZt7r7lBDd48dor4gIuNA9bbMkPxl3j8/s1600/pic_99_48.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 240px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjF0Y9Taq8Qv_2Y0ylm-_ITinRDx-fM-Hq-tP9Rj0Hmpst0P3a-Wh8zBz9_dSVdUltlLpMPSAeHaMbQ-cgkT1V1X0RwlA1LqmZadkkdrdwErrjCZt7r7lBDd48dor4gIuNA9bbMkPxl3j8/s320/pic_99_48.PNG" alt="" id="BLOGGER_PHOTO_ID_5520115652641074370" border="0" /></a>using 48 out of 100 eigenvectors (cumsum of 99% for eigenvalues) (1.63 MB)<br /></div><br /><br /><div style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgkzTX_GCKGSmjkdEFwWfLV0WDxtgQYKzhYhL9hLbFsUAGAor2SeLiO7paH2WPJYZRbJ4YxrC5WMyJYDiS3Q5PWPs2DZJ8Sah6uWsg-WD1kxW_ywDucqTtAFnjg1hRXPIf3G2Aqk5mGQqg/s1600/pic_100_100.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 240px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgkzTX_GCKGSmjkdEFwWfLV0WDxtgQYKzhYhL9hLbFsUAGAor2SeLiO7paH2WPJYZRbJ4YxrC5WMyJYDiS3Q5PWPs2DZJ8Sah6uWsg-WD1kxW_ywDucqTtAFnjg1hRXPIf3G2Aqk5mGQqg/s320/pic_100_100.PNG" alt="" id="BLOGGER_PHOTO_ID_5520115661242462066" border="0" /></a>using all 100 eigenvectors (100%) (1.10 MB)<br /><br /></div><br />We can see that using only a few basis to reconstruct will result in a very poor and lossy quality of the image. The images using only 1, 2 and 4 eigenvectors look blocky and the high frequency features such as the faces are missing or blurred. As we increase the number of eigenvectors used, the quality becomes better and better and the minute features are showing up. At 10 eigenvectors the faces are quite recognizable and the image begins to look "ok". At 48 out of 100 eigenvectors the reconstructed image is decent and losses are not noticeable. Using all the eigenvectors, we get the same as the grayscale image. Also I should mention that when I used imwrite to save the images, the file size increases as i use more eigenvectors which is intuitive, however the file sizes are even bigger than the original image. And when all the the eigenvectors are used, the file size is the same as that of the original image.<br /><br />What we did here was to use PCA on a grayscale image. True color images consists of 3 planes (RGB) and we tried applying PCA on each of the individual planes, and then adding them up in the end:<br /><br /><div style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbLIXJSFtZokHdwjX1YyzoNdLw0mDH_gXkZASz3gkxOpA9w5Kg4Xm-ZfHn-lZ31ZFGfvRKizT1vXT6mhWf1N9ZraxnuZIGdodxfh1InNVTlr97PjwBzMHK0S_suF_vz-Fjl2DEFjRuc50/s1600/pic_95_colored.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 240px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbLIXJSFtZokHdwjX1YyzoNdLw0mDH_gXkZASz3gkxOpA9w5Kg4Xm-ZfHn-lZ31ZFGfvRKizT1vXT6mhWf1N9ZraxnuZIGdodxfh1InNVTlr97PjwBzMHK0S_suF_vz-Fjl2DEFjRuc50/s320/pic_95_colored.PNG" alt="" id="BLOGGER_PHOTO_ID_5520130719717876882" border="0" /></a>(cumsum of 95% for eigenvalues)<br /><br /></div><br /><div style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsEzd3mJD0Lx__yLVp875oVRLHFMEfA_SjWg7tf42NqwtwjsFs-lKUTwfl8dmuoXU5SrP0xqXzxkTZ7tbvwFGNLvrRT-vXor3wuW7KoPEa42eLNnwiZWsIztIvD0I9SiD6YVTvJLrYVOA/s1600/pic_99_colored.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 240px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsEzd3mJD0Lx__yLVp875oVRLHFMEfA_SjWg7tf42NqwtwjsFs-lKUTwfl8dmuoXU5SrP0xqXzxkTZ7tbvwFGNLvrRT-vXor3wuW7KoPEa42eLNnwiZWsIztIvD0I9SiD6YVTvJLrYVOA/s320/pic_99_colored.PNG" alt="" id="BLOGGER_PHOTO_ID_5520115680871247586" border="0" /></a>(cumsum of 99% for eigenvalues)<br /><br /></div><div style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj17fGUBrRvDC4LAwOZg1zR0eEQoiPkwOURNHJ6nwL4cl1ytBXLATD2MY_0OfUxZzqC9qzWcNRGziUHu1lzEsj3zjm6nYLvL9ixDdmF5S_XiUFlpOmRmOaVpfILN07AsB1f_b4dcwVJB9Y/s1600/pic_100_colored.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 240px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj17fGUBrRvDC4LAwOZg1zR0eEQoiPkwOURNHJ6nwL4cl1ytBXLATD2MY_0OfUxZzqC9qzWcNRGziUHu1lzEsj3zjm6nYLvL9ixDdmF5S_XiUFlpOmRmOaVpfILN07AsB1f_b4dcwVJB9Y/s320/pic_100_colored.PNG" alt="" id="BLOGGER_PHOTO_ID_5520116305013412290" border="0" /></a></div><div style="text-align: center;">using all the eigenvectors for each plane (RGB)<br /><br /></div><div style="text-align: center;"><br /><div style="text-align: left;">As fewer eigenvectors are used, the image blurs and the colors also fade. However, there's a slight difference between the blue colors of the jacket in the reconstruction using all eigenvectors and the original image...maybe because of the scaling when using imwrite?<br /><br /></div><br /></div>To grade myself I give a 10/10 for producing the required outputs as well as understanding the lesson about PCA and image compression.<br /><br /><span style="font-weight: bold;">Score: 10/10</span><br /><br />Lastly I would like to acknowledge Dr Soriano, Arvin Mabilangan, Joseph Bunao, Andy Polinar, Brian Aganggan and BA Racoma for the helpful and insightful discussions. :D<br /><br /><br />- Dennis<br /><br />References:<br />1. M. Soriano, "Image Compression"dennisivan89http://www.blogger.com/profile/04476991777095665795noreply@blogger.com0tag:blogger.com,1999:blog-7345763871585817117.post-15043921292466170282010-09-16T06:51:00.000-07:002010-09-23T08:52:24.824-07:00AP 186 Act12 - Color Camera ProcessingIn this activity we will be playing around with the “white balance” setting of cameras and learn the concept behind it <p class="MsoNormal">Sometimes when we take pictures of colored objects, the color we see in the picture is different from the actual color of the object as we perceive it. The RGB values of an image is determined from the integral of the product of surface reflectance of the object, the spectral power distribution of the light source and the camera sensitivities and this is divided by the white balancing constant. It is due to this constant that white objects should appear white in the image.</p> <p class="MsoNormal">Most cameras have white balancing options such as: daylight, cloudy, tungsten, fluorescent and incandescent and the names pertain to the type of light source illuminating the object. We are first asked to take images of an ensemble of objects with colors representing major hues under a fixed light source and using different white balancing settings. I used BA Racoma’s Canon Powershot A480 camera with white balancing settings: daylight, cloudy, tungsten, fluorescent, and fluorescent_H. The objects used include: red USB, orange highlighter, yellow piece of paper, green fan sleeve, blue baller, indigo ipod, violet fan sleeve, purplish blue umbrella and a black USB. They were taken with a white background and under a fluorescent lamp.</p> <p class="MsoNormal"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3hfhDDb9jYszaNxZE3NSNbG42xkPCD8JEEt61P2fEY3oy-WIhwcsceKh45PbDpfidjfxoBwpbWH1HgBr-zQkZzXi_MAHh3NmrU6tUV-wQ11tc8RJscc51Xj-mbj7KWmscduTWUozd1a4/s1600/daylight.JPG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 240px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3hfhDDb9jYszaNxZE3NSNbG42xkPCD8JEEt61P2fEY3oy-WIhwcsceKh45PbDpfidjfxoBwpbWH1HgBr-zQkZzXi_MAHh3NmrU6tUV-wQ11tc8RJscc51Xj-mbj7KWmscduTWUozd1a4/s320/daylight.JPG" alt="" id="BLOGGER_PHOTO_ID_5518254212306328930" border="0" /></a></p><p style="text-align: center;" class="MsoNormal">Image taken under "daylight" white-balancing setting</p><p style="text-align: center;" class="MsoNormal"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2N2-m15Jfv0uz0_ZR9ubFzskYnBkVZIZKPefHHDno8mb4DmlmUV5SOzpCywWt_f6eq8bLZh_OF8rmVVzINY3d1nvzX8DBG11S-CfF4n6wX0nhPT7t5chmbCGXytHTXNloTWFZmd9UjNU/s1600/cloudy.JPG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 240px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2N2-m15Jfv0uz0_ZR9ubFzskYnBkVZIZKPefHHDno8mb4DmlmUV5SOzpCywWt_f6eq8bLZh_OF8rmVVzINY3d1nvzX8DBG11S-CfF4n6wX0nhPT7t5chmbCGXytHTXNloTWFZmd9UjNU/s320/cloudy.JPG" alt="" id="BLOGGER_PHOTO_ID_5518254224548601570" border="0" /></a></p><p style="text-align: center;" class="MsoNormal">Image taken under "cloudy" white-balancing setting</p><p style="text-align: center;" class="MsoNormal"><br /></p><div style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjBLIMvgjYkmEbFYJLIzJ290ilL647KYFuPkmOhy-deCAn-qcTg0RmE9hlqdVoz3WNB4HDxvQuPM_ndIHfeEVukRacpYl6au7F-6dEWygc8M4cTmVaT1rJPt_IjdBLkl_nwMSvkOE_E1qk/s1600/tungsten.JPG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 240px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjBLIMvgjYkmEbFYJLIzJ290ilL647KYFuPkmOhy-deCAn-qcTg0RmE9hlqdVoz3WNB4HDxvQuPM_ndIHfeEVukRacpYl6au7F-6dEWygc8M4cTmVaT1rJPt_IjdBLkl_nwMSvkOE_E1qk/s320/tungsten.JPG" alt="" id="BLOGGER_PHOTO_ID_5518254228788426898" border="0" /></a>Image taken under "tungsten" white-balancing setting<br /></div><br /><br /><div style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhe_fGVVZaq2pjJbyBaYIbtBgnK_P0Ot8wm3UT4S0jk-qE0iUAQHz9SNU5C8e9x1yzc0sziIY7lxswDpbbhuxsabnnhuvK1ka01o0mA586uOX6BejLd1vmQbzQZMIXsVVGg7IEot5-yGf0/s1600/fluorescent.JPG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 240px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhe_fGVVZaq2pjJbyBaYIbtBgnK_P0Ot8wm3UT4S0jk-qE0iUAQHz9SNU5C8e9x1yzc0sziIY7lxswDpbbhuxsabnnhuvK1ka01o0mA586uOX6BejLd1vmQbzQZMIXsVVGg7IEot5-yGf0/s320/fluorescent.JPG" alt="" id="BLOGGER_PHOTO_ID_5518254230825004354" border="0" /></a>Image taken under "fluorescent" white-balancing setting<br /><br /></div><br /><div style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhVcgxglrKfWI1H-tQT93uLbnGnCY7Sv0gTcioH-JSk19f88l_ob0Gdl8zjRVtcyvwIhbpsphmwgKFGWSZ4wrvJwv5JhzzlHbc79BBSTXhNz7O2SMHQ0ebQg46vJeQHsjkPtlgZoYleQbg/s1600/fluorescent_H.JPG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 240px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhVcgxglrKfWI1H-tQT93uLbnGnCY7Sv0gTcioH-JSk19f88l_ob0Gdl8zjRVtcyvwIhbpsphmwgKFGWSZ4wrvJwv5JhzzlHbc79BBSTXhNz7O2SMHQ0ebQg46vJeQHsjkPtlgZoYleQbg/s320/fluorescent_H.JPG" alt="" id="BLOGGER_PHOTO_ID_5518254240663294098" border="0" /></a>Image taken under "fluorescent_H" white-balancing setting<br /></div><br /><p class="MsoNormal">Shown above are the images taken with daylight, cloudy, tungsten, fluorescent and fluorescent_H white balancing setting. Under daylight, the image looks a bit more bluish while under cloudy, the image looks a bit… brownish. Fluorescent_H is almost like cloudy except that it looks more brownish or reddish. The image under the tungsten setting looks bluish since light from tungsten is very orange compared to daylight; the bluish white-balancing balances the orange tinge due to the tungsten bulb. The image looks best in fluorescent setting since the white background looks the whitest there. </p> <p class="MsoNormal">We’ll try to white balance the wrongly balanced images. There are two methods of doing this: White Patch algorithm and Gray World algorithm. In White Patch algorithm we divide the RGB values of the image by the RGB values of a pixel from the image that we know is white respectively. Pixel values greater than 1 are clipped to 1. In Gray World algorithm, we take the averages of the R, G and B of the image and then use it as the divisor for RGB respectively. The white-balanced images are now:</p><p class="MsoNormal"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhx00zXkWoQgSB7miFRPGXTnXynpyKeyOVbl0U8matOahiXJSLxjwU3Lb-yLy9EKjILB6B0CMtm8f5HO9Ph1MNkEYSRontkWH9Pm7iPhrrgDUGJji-gLCEGiGEFnJXbco_BVDf_0QxCdnI/s1600/daylight_white_patch.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 240px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhx00zXkWoQgSB7miFRPGXTnXynpyKeyOVbl0U8matOahiXJSLxjwU3Lb-yLy9EKjILB6B0CMtm8f5HO9Ph1MNkEYSRontkWH9Pm7iPhrrgDUGJji-gLCEGiGEFnJXbco_BVDf_0QxCdnI/s320/daylight_white_patch.PNG" alt="" id="BLOGGER_PHOTO_ID_5518274926208114306" border="0" /></a></p><p style="text-align: center;" class="MsoNormal">white-balanced (daylight) using White Patch algorithm</p><p style="text-align: center;" class="MsoNormal"><br /></p><p style="text-align: center;" class="MsoNormal"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQ1Da05lQ1idTGBue066XeS6rPnHWEvMPzOjY8NJH_7_1wx3bFFyKDJK9VNS3lO3hi_zlvg14GUjThIKJqTN5vgcWdhonmrpTFBgCp6al3b-yMYX9zk2T68f3-VqxkK6HOVdzt_136Tu0/s1600/daylight_gray_world.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 240px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQ1Da05lQ1idTGBue066XeS6rPnHWEvMPzOjY8NJH_7_1wx3bFFyKDJK9VNS3lO3hi_zlvg14GUjThIKJqTN5vgcWdhonmrpTFBgCp6al3b-yMYX9zk2T68f3-VqxkK6HOVdzt_136Tu0/s320/daylight_gray_world.PNG" alt="" id="BLOGGER_PHOTO_ID_5518459549671540370" border="0" /></a></p> <p style="text-align: center;" class="MsoNormal">white-balanced (daylight) using Gray World algorithm</p><p style="text-align: center;" class="MsoNormal"><br /></p> <p class="MsoNormal"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhXP7UAWZm0hJGk4Jk_QKuAcHZ68pZQXoM7aqG3-VyPBMd92gtW-9oi6JNS6f1LLwidekumI2YOPmmNWOLzZcrB4s3iUbrtHggZyH0mxMPytBxqajtCLyqVz8fqYJ7NgCH0KugKcaVaA04/s1600/cloudy_white_patch.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 240px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhXP7UAWZm0hJGk4Jk_QKuAcHZ68pZQXoM7aqG3-VyPBMd92gtW-9oi6JNS6f1LLwidekumI2YOPmmNWOLzZcrB4s3iUbrtHggZyH0mxMPytBxqajtCLyqVz8fqYJ7NgCH0KugKcaVaA04/s320/cloudy_white_patch.PNG" alt="" id="BLOGGER_PHOTO_ID_5518272846894846258" border="0" /></a></p><p style="text-align: center;" class="MsoNormal">white-balanced (cloudy) using White Patch algorithm</p><p style="text-align: center;" class="MsoNormal"><br /></p><p style="text-align: center;" class="MsoNormal"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXhKUUjOpu1vO5aV9GHsv1pvIuDOyGfM-t6fZsHF5XhaUT9svd1EDXbjKHycsSOvuDv_cASp_IoT9-t1cMQqMYmX2855okiBx2Ym49fnyjnVWMEILEh6PDwwrxjXNj9MaK5mro7OncMPQ/s1600/cloudy_gray_world.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 240px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXhKUUjOpu1vO5aV9GHsv1pvIuDOyGfM-t6fZsHF5XhaUT9svd1EDXbjKHycsSOvuDv_cASp_IoT9-t1cMQqMYmX2855okiBx2Ym49fnyjnVWMEILEh6PDwwrxjXNj9MaK5mro7OncMPQ/s320/cloudy_gray_world.PNG" alt="" id="BLOGGER_PHOTO_ID_5518459558094315810" border="0" /></a></p><p style="text-align: center;" class="MsoNormal">white-balanced (cloudy) using Gray World algorithm</p><p style="text-align: center;" class="MsoNormal"><br /></p><p style="text-align: center;" class="MsoNormal"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhExDyXEJ019WhoqN0sYyMwNc-eJOo375ZvsytKzVFRuwp3pCl7QpLToHFa4g8lBx6WEbLez6OoQNE23qIvMfT6k732ZkjxdwXYvBgG7vh3Jhx_SmqO6AuJsRRPdGnj3RMXmOr7gqCvikQ/s1600/tungsten_white_patch.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 240px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhExDyXEJ019WhoqN0sYyMwNc-eJOo375ZvsytKzVFRuwp3pCl7QpLToHFa4g8lBx6WEbLez6OoQNE23qIvMfT6k732ZkjxdwXYvBgG7vh3Jhx_SmqO6AuJsRRPdGnj3RMXmOr7gqCvikQ/s320/tungsten_white_patch.PNG" alt="" id="BLOGGER_PHOTO_ID_5518272859495992946" border="0" /></a></p><p style="text-align: center;" class="MsoNormal">white-balanced (tungsten) using White Patch algorithm</p><p style="text-align: center;" class="MsoNormal"><br /></p><p style="text-align: center;" class="MsoNormal"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgP1a1yMpyBpmYKKsP-D1qR5Xqe1rUz8t2tiyaCi1qoh2dTXGyEEzATLWgjQN-lda4dYREnG9mEaCVi6MdbNVaUuSAE6V7NvtBy0uAwWH8yeko-97jGRqKArSad0oB6Yf1YbF0kyj09c6s/s1600/tungsten_gray_world.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 240px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgP1a1yMpyBpmYKKsP-D1qR5Xqe1rUz8t2tiyaCi1qoh2dTXGyEEzATLWgjQN-lda4dYREnG9mEaCVi6MdbNVaUuSAE6V7NvtBy0uAwWH8yeko-97jGRqKArSad0oB6Yf1YbF0kyj09c6s/s320/tungsten_gray_world.PNG" alt="" id="BLOGGER_PHOTO_ID_5518459569173648546" border="0" /></a></p><p style="text-align: center;" class="MsoNormal">white-balanced (tungsten) using Gray World algorithm</p><p style="text-align: center;" class="MsoNormal"><br /></p><p style="text-align: center;" class="MsoNormal"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSzs-oUVAZb5S7RAV3IfGpHOo3Kmeu3Q__7kZjr30cyubQeHPtZ1Rg8ozZFwz1Y88QNOssigeAqG93FgOhIMNvkFh5Rtaf6lkRGLlLfUR8kDxtwIpcaeBvBKm4cwegmwBaesSOGpJnsTc/s1600/fluorescent_H_white_patch.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 240px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSzs-oUVAZb5S7RAV3IfGpHOo3Kmeu3Q__7kZjr30cyubQeHPtZ1Rg8ozZFwz1Y88QNOssigeAqG93FgOhIMNvkFh5Rtaf6lkRGLlLfUR8kDxtwIpcaeBvBKm4cwegmwBaesSOGpJnsTc/s320/fluorescent_H_white_patch.PNG" alt="" id="BLOGGER_PHOTO_ID_5518272865318446978" border="0" /></a></p><p style="text-align: center;" class="MsoNormal">white-balanced (fluorescent_H) using White Patch algorithm<br /></p><p style="text-align: center;" class="MsoNormal"><br /></p><p style="text-align: center;" class="MsoNormal"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgCgbFEeXQoCMskSYhorp_Rnn-PqOuyRPWrjXQ65ziRmPi4TAzCy0uUgFxbrIv3ot0r7cZcD4Ej3XuhQZ08Ns7yQcoe5XNI8X1R8lZMwBLzwxB32Nj1YqJP3IzjZMV6VE5eRLeMsQJJ1DQ/s1600/fluorescent_H_gray_world.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 240px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgCgbFEeXQoCMskSYhorp_Rnn-PqOuyRPWrjXQ65ziRmPi4TAzCy0uUgFxbrIv3ot0r7cZcD4Ej3XuhQZ08Ns7yQcoe5XNI8X1R8lZMwBLzwxB32Nj1YqJP3IzjZMV6VE5eRLeMsQJJ1DQ/s320/fluorescent_H_gray_world.PNG" alt="" id="BLOGGER_PHOTO_ID_5518459581659546770" border="0" /></a></p><p style="text-align: center;" class="MsoNormal">white-balanced (fluorescent_H) using Gray World algorithm</p><p style="text-align: center;" class="MsoNormal"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQ1Da05lQ1idTGBue066XeS6rPnHWEvMPzOjY8NJH_7_1wx3bFFyKDJK9VNS3lO3hi_zlvg14GUjThIKJqTN5vgcWdhonmrpTFBgCp6al3b-yMYX9zk2T68f3-VqxkK6HOVdzt_136Tu0/s1600/daylight_gray_world.PNG"><br /></a></p> <p class="MsoNormal">Wow!! White does really appear white here! It seems that as if a color overlay has been removed from the images and they now look brighter. The colors of the image became brighter and more vivid. Also, in the white-balanced images using the White Patch algorithm, I noticed that the area near the chosen pixel of a white object seems to be whiter or more saturated than the rest of the white background. Images that used the Gray World algorithm, meanwhile, appear more saturated. Perhaps this is because the majority of the pixels are white and thus when the average of the RGB values is taken and divided in their planes respectively, the image looks saturated.<br /></p> <p class="MsoNormal">Next we took another picture of an ensemble of objects having the hue along with a white object under a white-balancing setting that is not appropriate for the light source. In this case I used the tungsten setting and took the picture under the illumination of a fluorescent lamp. We then apply the White Patch algorithm and the Gray World algorithm independently and the results are:</p><p class="MsoNormal"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEixUSsH3Ed8jxffJJ0xPTwmlPItDUSOhnM9qNTlfi7mLyRuLt5MjcxIxi-MHmEeWq9GRUMCKrvYK9xB0lEoCqfALHHHx4IpLyecbN3H4sUBs2m2yqzIcaaJXu1uKL8_61p6-jfTTafxSWQ/s1600/red_tungsten.JPG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 240px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEixUSsH3Ed8jxffJJ0xPTwmlPItDUSOhnM9qNTlfi7mLyRuLt5MjcxIxi-MHmEeWq9GRUMCKrvYK9xB0lEoCqfALHHHx4IpLyecbN3H4sUBs2m2yqzIcaaJXu1uKL8_61p6-jfTTafxSWQ/s320/red_tungsten.JPG" alt="" id="BLOGGER_PHOTO_ID_5518466761779828594" border="0" /></a></p><p style="text-align: center;" class="MsoNormal">Image taken under "tungsten" white-balancing setting</p><p style="text-align: center;" class="MsoNormal"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvfO_ZH06CGgLE0aRCZbSNZACvvz5eahykDzrYCoX-VKfm2eM5MIcxUsjA8bW3ONQojbu3eoVFKnc-wVosXNOr1F60JP0RLkZZENhW1AmzoaTvDeSg-bOQbFErTj6vSujJVamaK7LceqU/s1600/allred_whitepatch.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 240px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvfO_ZH06CGgLE0aRCZbSNZACvvz5eahykDzrYCoX-VKfm2eM5MIcxUsjA8bW3ONQojbu3eoVFKnc-wVosXNOr1F60JP0RLkZZENhW1AmzoaTvDeSg-bOQbFErTj6vSujJVamaK7LceqU/s320/allred_whitepatch.PNG" alt="" id="BLOGGER_PHOTO_ID_5518473792024038226" border="0" /></a></p><p style="text-align: center;" class="MsoNormal">white-balanced using white patch algorithm</p><p style="text-align: center;" class="MsoNormal"><br /></p><p class="MsoNormal"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgFPKwuh0Wftqca92mprRnQIcESbytoGj0EZuw706B7WGNz7lAGrc05wOpv_KZyx71uCOjiFq-esEfQZw7RawnZp9BgRU99WNtDSFNQSrU0uOww6rVs2LkSPXm_MZ91xJuj4UMFIr-NFsw/s1600/allred_grayworld.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 240px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgFPKwuh0Wftqca92mprRnQIcESbytoGj0EZuw706B7WGNz7lAGrc05wOpv_KZyx71uCOjiFq-esEfQZw7RawnZp9BgRU99WNtDSFNQSrU0uOww6rVs2LkSPXm_MZ91xJuj4UMFIr-NFsw/s320/allred_grayworld.PNG" alt="" id="BLOGGER_PHOTO_ID_5518466789913525986" border="0" /></a></p><p style="text-align: center;" class="MsoNormal">white-balanced using gray world algorithm</p><p style="text-align: center;" class="MsoNormal"><br /></p> The balanced image using white patch algorithm looks almost the same as the original image, maybe because the white piece of paper may already look white. In the balanced image using gray world algorithm, the image once again looks saturated and moreover, it looks kind of bluish. But the white piece of paper does appear white though...<br /><p class="MsoNormal">Aside from this BA Racoma played around with the custom white-balancing setting and took a picture of me with a deliberately wrong setting. So I applied the two algorithms once again and…</p><div style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzLFzsCmhRInI-YwBjXmC1PCI8dGg19_jsfJy0IBj-nUufDajndUxH3b5RKPX6hYo_g0esMbBghxwlJ_UBxnENHLVA3x4joszwIKSkjDjXjGD7C34txU81N35EQdZ8RUjhp1np2k9k4ww/s1600/dennis.JPG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 240px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzLFzsCmhRInI-YwBjXmC1PCI8dGg19_jsfJy0IBj-nUufDajndUxH3b5RKPX6hYo_g0esMbBghxwlJ_UBxnENHLVA3x4joszwIKSkjDjXjGD7C34txU81N35EQdZ8RUjhp1np2k9k4ww/s320/dennis.JPG" alt="" id="BLOGGER_PHOTO_ID_5518473797348228786" border="0" /></a>wrongly balanced image<br /><br /><br /><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhJZwhrlMjpROKzcMgRTVHWGt8EHVzHh5gWr-HxN91hDfEUxwGBFX1H5VfraYu-i9N2wmOwAnA2GojNLB3KM8wzA9OHpMgB6F9kTchSUqDLaIixBE0G3fcLOyvfPeUTrhPPia8grHecjg/s1600/dennis_whitepatch.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 240px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhJZwhrlMjpROKzcMgRTVHWGt8EHVzHh5gWr-HxN91hDfEUxwGBFX1H5VfraYu-i9N2wmOwAnA2GojNLB3KM8wzA9OHpMgB6F9kTchSUqDLaIixBE0G3fcLOyvfPeUTrhPPia8grHecjg/s320/dennis_whitepatch.PNG" alt="" id="BLOGGER_PHOTO_ID_5518473807680646690" border="0" /></a>balanced using white patch algorithm<br /><br /><br /><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj503dVI87mniJyT7TdjD6TTbqYXJMvjtlbZ6erzBsFGvgzKSpJ5D6YQf4tjS9a2ESH2f7v1fOmNPlOoG-f5HXWfTByjmx18crPuJ-F-q3FMQ658MljpoEirycJW46UV95kiTleVlUoh1E/s1600/dennis_grayworld.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 240px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj503dVI87mniJyT7TdjD6TTbqYXJMvjtlbZ6erzBsFGvgzKSpJ5D6YQf4tjS9a2ESH2f7v1fOmNPlOoG-f5HXWfTByjmx18crPuJ-F-q3FMQ658MljpoEirycJW46UV95kiTleVlUoh1E/s320/dennis_grayworld.PNG" alt="" id="BLOGGER_PHOTO_ID_5518473818625892722" border="0" /></a>balanced using gray world algorithm<br /><br /><div style="text-align: left;">The original image looks greenish. After balancing with the white patch algorithm, the image looks a lot better with white being white. On the other hand, the balanced image using gray world algorithm looks saturated again, but white also appears white in the image. In my opinion the balanced image using white patch algorithm looks better although it's a bit dark. Balanced images using gray world algorithm also looks good except that it is too saturated. So if I were to pick one, I'd still pick the balanced image using white patch algorithm.<br /><br /></div></div><p class="MsoNormal"><br /></p><p class="MsoNormal">To grade myself, I give a 10/10 for understanding the lesson and producing the outputs required in this activity.</p> <p style="font-weight: bold;" class="MsoNormal">Score: 10/10</p> <p class="MsoNormal">Lastly I would like to acknowledge Dr. Soriano and BA Racoma for the helpful discussions. Also, thanks to Mayanne Tenorio,<span style=""> </span>Tisza Trono and BA Racoma for the materials used inthis activity.</p><p class="MsoNormal">References:</p><p class="MsoNormal">1. M. Soriano, "A12 - Color Camera Processing"<br /></p><p class="MsoNormal"><br /></p> <p class="MsoNormal">Appendix: (code)</p><p class="MsoNormal">// AP186 Color camera processing<br /><br />// White patch algorithm<br />A = imread("C:\fluorescent_H.JPG");<br /><br />R = A(:, :, 1);<br />G = A(:, :, 2);<br />B = A(:, :, 3);<br /><br />// RGB values of pixel belonging to white<br />Rw = R(270, 160);<br />Gw = G(270, 160);<br />Bw = B(270, 160);<br /><br />Rbal = R / Rw;<br />Gbal = G / Gw;<br />Bbal = B / Bw;<br /><br />Rbal(find(Rbal > 1)) = 1;<br />Gbal(find(Gbal > 1)) = 1;<br />Bbal(find(Bbal > 1)) = 1;<br /><br />A(:, :, 1) = Rbal;<br />A(:, :, 2) = Gbal;<br />A(:, :, 3) = Bbal;<br /><br />imwrite(A, "C:\fluorescent_H_white_patch.PNG");<br /><br />//imshow(A);<br /><br />//Gray world algorithm<br />A = imread("C:\fluorescent_H.JPG");<br /><br />R = A(:, :, 1);<br />G = A(:, :, 2);<br />B = A(:, :, 3);<br /><br />// Get average value for R, G and B planes<br />Rw = mean(R);<br />Gw = mean(G);<br />Bw = mean(B);<br /><br />Rbal = R / Rw;<br />Gbal = G / Gw;<br />Bbal = B / Bw;<br /><br />Rbal(find(Rbal > 1)) = 1;<br />Gbal(find(Gbal > 1)) = 1;<br />Bbal(find(Bbal > 1)) = 1;<br /><br />A(:, :, 1) = Rbal;<br />A(:, :, 2) = Gbal;<br />A(:, :, 3) = Bbal;<br /><br />//imshow(A);<br />imwrite(A, "C:\fluorescent_H_gray_world.PNG");</p><p class="MsoNormal"><br /></p><p class="MsoNormal">---------------- end ----------------------<br /></p>dennisivan89http://www.blogger.com/profile/04476991777095665795noreply@blogger.com1tag:blogger.com,1999:blog-7345763871585817117.post-7182297925237545002010-09-15T04:08:00.000-07:002010-09-23T08:53:02.524-07:00AP 186 Act13 - Color Image SegmentationSometimes in image processing, a Region Of Interest (ROI) needs to be isolated from the rest of the image. Thresholding is one way of doing it but when the color of the object or ROI is almost the same with the background, problems arise. Another way of doing it is through color image segmentation, which we will demonstrate in this activity.<br /><br />First I pick an image with a single color and I chose this picture which i took:<br /><br /><div style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxwH-mcMepW-hPsPFw9GWhsG_cyOXPKkKsTIKhVJH2VXfsTmXGNuDDJrILRXhLfZJPOymnbGNWghSnn_N-SyKT8n5eoYM2-fgloVpqXIQ2d1zsbXRM5N_T0UCycx6tGKgX8xfNRNGEPnw/s1600/Ferrari_side_view.JPG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 256px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxwH-mcMepW-hPsPFw9GWhsG_cyOXPKkKsTIKhVJH2VXfsTmXGNuDDJrILRXhLfZJPOymnbGNWghSnn_N-SyKT8n5eoYM2-fgloVpqXIQ2d1zsbXRM5N_T0UCycx6tGKgX8xfNRNGEPnw/s320/Ferrari_side_view.JPG" alt="" id="BLOGGER_PHOTO_ID_5517133879805454130" border="0" /></a>picture of a Ferrari to be used for this activity<br /></div><br />next we crop a region of interest that is monochromatic...<br /><br /><div style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEizdYfX-fiO6k5XK_Zjn71vEH5k1WHq1uD75c8Im33ADbPQKjLDqk5kQnNAt9LP7Ie7EgfyAcgF84ehQCA46siWhJTL_KvU82DnboDTRXDiSVC3iPquCAFtM56rkiLtHJblhiN1NtsusCo/s1600/ROI.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 162px; height: 81px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEizdYfX-fiO6k5XK_Zjn71vEH5k1WHq1uD75c8Im33ADbPQKjLDqk5kQnNAt9LP7Ie7EgfyAcgF84ehQCA46siWhJTL_KvU82DnboDTRXDiSVC3iPquCAFtM56rkiLtHJblhiN1NtsusCo/s320/ROI.PNG" alt="" id="BLOGGER_PHOTO_ID_5517133884143184562" border="0" /></a>region of interest cropped from the front hood of the car<br /></div><br />We first perform the parametric segmentation:<br />The ROI was loaded into scilab and the RGB colors were transformed into Normalized Chromaticity Coordinates (NCC) then from there the r and g values can be computed. After which we assumed independent Gaussian distributions in r and g and computed for their mean and standard deviation. From here the joint probability function is obtained and this criteria is used to segment the whole image. The result is a grayscale image:<br /><br /><div style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEin5CKWoe5aLtI_0lFY_Nk59IPYc1nklaCT68GBBTy0wO0jZvTg8qvrapCjrgEg5fZIqA2Rm6AIbRJK91kDQmcJU_p_ry_iI9wap7tfbj23ntqObNG2o78fTVsmsxmxW1CAHP_DJecpV6o/s1600/parametric.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 256px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEin5CKWoe5aLtI_0lFY_Nk59IPYc1nklaCT68GBBTy0wO0jZvTg8qvrapCjrgEg5fZIqA2Rm6AIbRJK91kDQmcJU_p_ry_iI9wap7tfbj23ntqObNG2o78fTVsmsxmxW1CAHP_DJecpV6o/s320/parametric.PNG" alt="" id="BLOGGER_PHOTO_ID_5517133888255210594" border="0" /></a>parametric segmentation of the region of interest (the car)<br /></div><br />and one can see that the red body of the car is isolated from the surroundings. The black spots near the front of the car are due to specular reflections in the image so they appear white and were not included. Even the reflection of the car from the glass window is included.<br /><br />Next we perform another method which is the non-parametric segmentation. This method utilizes the 2D histogram of the r and g values in the ROI. So instead of computing the joint probability per pixel, the method looks up the it's value in the 2D histogram using the pixel's r and g values - backprojection in short. So from the r and g values of the ROI we made the 2D histogram:<br /><br /><div style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMSQ1GKlZjlRypMIE7sJ5dx7Y-3RputPospkGI4MUuBnvI4Zp_fxiKFo9CAEwzlzi_wAyQrHRhsDLTwx2wIdsmMD48bGf-EKDpfYXH5P246R7Mp1uJHfOoYqTwhSsvNLsg1vU62h7HzR8/s1600/2D_histogram.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 173px; height: 173px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMSQ1GKlZjlRypMIE7sJ5dx7Y-3RputPospkGI4MUuBnvI4Zp_fxiKFo9CAEwzlzi_wAyQrHRhsDLTwx2wIdsmMD48bGf-EKDpfYXH5P246R7Mp1uJHfOoYqTwhSsvNLsg1vU62h7HzR8/s320/2D_histogram.PNG" alt="" id="BLOGGER_PHOTO_ID_5517133905639375250" border="0" /></a>2D histogram of r and g values of ROI<br /></div><br />but since its origin is on the top left corner, we rotate this by 90 degrees by using mogrify function:<br /><br /><div style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgeKsD4UDgfdr7DWeosnzPA_z9uMzBwpP4Fe5deBECROdKGwkmAEsp_-Y4zd2I630yAXiBu_FdKg12xUb5WfnyKfLPW5I0LfaOWQbTP1UejwbH06trawbK1uff3olCKirsnGd2kpIjgKTw/s1600/2Dhistogram_rot.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 187px; height: 187px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgeKsD4UDgfdr7DWeosnzPA_z9uMzBwpP4Fe5deBECROdKGwkmAEsp_-Y4zd2I630yAXiBu_FdKg12xUb5WfnyKfLPW5I0LfaOWQbTP1UejwbH06trawbK1uff3olCKirsnGd2kpIjgKTw/s320/2Dhistogram_rot.PNG" alt="" id="BLOGGER_PHOTO_ID_5517500878626780994" border="0" /></a>rotated 2D histogram of the ROI<br /><br /><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhT3R3Y55wLeYpGcHPi_P-QJ-Ykiu90YAAWQ2JRFEm5_yewLiMnKpXR42OBPKKsCRAwiwNDTftZE0DJ2MUeXeixTi3nUfoSVDoemqk9GmiNR-4g0P2m_Fgdz_pNyebSDyKJGFaffCiSzmI/s1600/chromaspace.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 213px; height: 187px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhT3R3Y55wLeYpGcHPi_P-QJ-Ykiu90YAAWQ2JRFEm5_yewLiMnKpXR42OBPKKsCRAwiwNDTftZE0DJ2MUeXeixTi3nUfoSVDoemqk9GmiNR-4g0P2m_Fgdz_pNyebSDyKJGFaffCiSzmI/s320/chromaspace.PNG" alt="" id="BLOGGER_PHOTO_ID_5517500882274418930" border="0" /></a>normalized chromaticity space<br /></div><br />and comparing this to the rg chromaticity diagram, the peak in the histogram coincide with the reddish part of the normalized chromaticity space which is correct since the ROI is reddish in color. Using this histogram, we performed histogram backprojection which is similar to activity 5 (Enhancement by histogram manipulation) and the result is:<br /><br /><div style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjU8qu4VTLU-VTCAux-uTw49soVRlIRqRWLnKvYO_rMxG3mOXznf0CY5yRpvR8zqN0E1_hHN3h87l2u7lGj7IvDaKgrxvwUq-J5Bsmrzvsyo9QcEnK75GyXgEK8MGYNucVPKqs3HCtRsU4/s1600/nonparametric.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 256px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjU8qu4VTLU-VTCAux-uTw49soVRlIRqRWLnKvYO_rMxG3mOXznf0CY5yRpvR8zqN0E1_hHN3h87l2u7lGj7IvDaKgrxvwUq-J5Bsmrzvsyo9QcEnK75GyXgEK8MGYNucVPKqs3HCtRsU4/s320/nonparametric.PNG" alt="" id="BLOGGER_PHOTO_ID_5517133913140575794" border="0" /></a>non-parametric segmentation of the ROI (the car)<br /><br /><div style="text-align: left;">Comparing the results of the two methods, I would really have to say that the parametric method worked better at first glance. Nearly the entire body of the car is separated from the background while in non-parametric segmentation, the bumper as well as some other parts of the car are very faint. Although both methods were able to get the reflection of the car from the windows, the result from the parametric method seems to be better and more detailed. Looking at the 1D histograms of r and g value of the ROI...<br /><br /><div style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgiBYjofc-ptKXTd3ehfHAEUBQjcjSic7NkVOJH3syLez9FfywXVlY05Pnrfc_ssl5fvCretlkZpU0K1N5cCfU2dCKvaXFwypfm4fb6TfLkwqPCdsIm_NVWSQIX4zDkXEyj7_lcsQ6ss68/s1600/r_histogram.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 247px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgiBYjofc-ptKXTd3ehfHAEUBQjcjSic7NkVOJH3syLez9FfywXVlY05Pnrfc_ssl5fvCretlkZpU0K1N5cCfU2dCKvaXFwypfm4fb6TfLkwqPCdsIm_NVWSQIX4zDkXEyj7_lcsQ6ss68/s320/r_histogram.PNG" alt="" id="BLOGGER_PHOTO_ID_5517146660468006722" border="0" /></a>histogram of r values of ROI<br /><br /><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3nX9Zio_4_3LQxmv3KjQm_iImYkU0BQhXiz9xeRSjpbl1dmLGxDA6uHnwgpeyt3UrSeqqWUJ0NxtH_ckwgQa5rbKgGpfroLMKVVjRyzNSL_uchOLQ2wKwQaRPs7ubBfKxcAvhlv6sRGg/s1600/g_histogram.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 242px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3nX9Zio_4_3LQxmv3KjQm_iImYkU0BQhXiz9xeRSjpbl1dmLGxDA6uHnwgpeyt3UrSeqqWUJ0NxtH_ckwgQa5rbKgGpfroLMKVVjRyzNSL_uchOLQ2wKwQaRPs7ubBfKxcAvhlv6sRGg/s320/g_histogram.PNG" alt="" id="BLOGGER_PHOTO_ID_5517146670577159042" border="0" /></a>histogram of g values of ROI<br /><br /><div style="text-align: left;">no wonder the results of the parametric method were so good... we assumed r and g to have a gaussian distribution and looking at the histograms above, a gaussian distribution would be a good enough fit.<br /><br /></div></div><br />To grade myself, I give a 10/10 for comprehending the lesson and producing the required results.<br /><span style="font-weight: bold;">Score: 10/10</span><br /><br />Lastly I would like to acknowledge Dr. Soriano for helping me understand more about this activity.<br /><br />References:<br />1. M. Soriano, "Color Image Segmentation"<br /><br /><br />Appendix: (code)<br /><br />// AP186 Act 12 Color Image Segmentation<br /><br />ROI = imread("C:\ROI.PNG");<br /><br />// PARAMETRIC METHOD<br />// Compute per pixel the r and g values<br />R = ROI(:,:,1);<br />G = ROI(:,:,2);<br />B = ROI(:,:,3);<br /><br />clear ROI;<br /><br />divisor = R + G + B;<br /><br />divisor(find(divisor==0)) = 1000000;<br /><br />r = R ./ divisor;<br />g = G ./divisor;<br /><br />clear R;<br />clear G;<br />clear B;<br /><br />// Get mean and stdev of r ang g:<br />rmean = mean(r);<br />gmean = mean(g);<br />rstdev = stdev(r);<br />gstdev = stdev(g);<br /><br /><br />// For the whole image...<br />A = imread("C:\Ferrari_side_view.JPG");<br /><br />// Compute per pixel the r and g values<br />R = A(:,:,1);<br />G = A(:,:,2);<br />B = A(:,:,3);<br /><br />clear A;<br /><br />divisor = R + G + B;<br /><br />divisor(find(divisor==0)) = 1000000;<br /><br />r = R ./ divisor;<br />g = G ./divisor;<br /><br />clear R;<br />clear G;<br />clear B;<br /></div></div><br />// Get their probabilities...<br />pr = 1/(rstdev * sqrt(2 * %pi)) * exp(-((r - rmean).^2)/(2*(rstdev^2)));<br />pg = 1/(gstdev * sqrt(2 * %pi)) * exp(-((g - gmean).^2)/(2*(gstdev^2)));<br /><br />JP = pr .* pg;<br /><br />//scf();<br />//imshow(JP, []);<br /><br /><br /><br />//NON-PARAMETRIC METHOD<br />// Compute per pixel the r and g values<br />ROI = imread("C:\ROI.PNG");<br />R = ROI(:,:,1);<br />G = ROI(:,:,2);<br />B = ROI(:,:,3);<br /><br />clear ROI;<br /><br />divisor = R + G + B;<br /><br />divisor(find(divisor==0)) = 1000000;<br /><br />r = R ./ divisor;<br />g = G ./divisor;<br /><br />clear R;<br />clear G;<br />clear B;<br /><br />BINS = 32;<br />rint = round(r*(BINS-1) + 1); //ranges from 1 to 32<br />gint = round(g*(BINS-1) + 1);<br /><br />colors = gint(:) + (rint(:)-1)*BINS;<br />hist = zeros(BINS, BINS);<br />for row = 1:BINS<br />for col = 1:(BINS-row+1)<br />hist(row, col) = length(find(colors==( ((col + (row-1)*BINS)))));<br />end;<br />end;<br /><br />//scf();<br />//histmax = max(hist);<br />//X = hist/histmax;<br />//Y = mogrify(X, ['-rotate', '-90']);<br />//imshow(Y, []);<br /><br />// For the whole image...<br />A = imread("C:\Ferrari_side_view.JPG");<br /><br />// Compute per pixel the r and g values<br />R = A(:,:,1);<br />G = A(:,:,2);<br />B = A(:,:,3);<br /><br />clear A;<br /><br />divisor = R + G + B;<br /><br />divisor(find(divisor==0)) = 1000000;<br /><br />r = R ./ divisor;<br />g = G ./divisor;<br /><br />clear R;<br />clear G;<br />clear B;<br /><br />//Backproject<br />s = size(r);<br />rows = s(1);<br />columns = s(2);<br /><br />S = zeros(rows, columns);<br /><br />for i=1:rows<br />for j=1:columns<br />rvalue = r(i, j);<br />gvalue = g(i, j);<br />// round off since hist has only 32 bins<br />rint = round(rvalue*(BINS-1) + 1);<br />gint = round(gvalue*(BINS-1) + 1);<br />value = hist(rint, gint);<br />// replace pixel with the value<br />S(i, j) = value;<br />end;<br />end;<br /><br />imshow(S, []);<br /><br /><br /><br />--------------------------end-----------------------dennisivan89http://www.blogger.com/profile/04476991777095665795noreply@blogger.com0tag:blogger.com,1999:blog-7345763871585817117.post-66356825129231262012010-09-12T07:20:00.000-07:002010-09-23T08:51:42.767-07:00AP186 Act11 - Playing notes by image processingJust as the title suggests, we will be playing some notes by using image processing. A simple musical piece was selected where only one note is present in every column. This is again another activity where we have to integrate the skills and lessons learned from past activities.<div><br /></div><div>My selected piece was the nursery rhyme "Mary had a little lamb". (right hand only, no bass) Special thanks to Troy Gonzales for composing a copy for me. :)</div><div><br /></div><div style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhqn6a13MdhRBFr94L97WDUkHYGnRwuC2qTFwxaWQKgg_sPdM0VmApdGFUwCFEqkGL02QMtnvxn9QgLuyi5-ie48BEBNEKbHyPE4A-CzpQMkwA6OOWRQzJ214DWYjZpaaG8NtPiLfrQhRw/s1600/musicsheet.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 124px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhqn6a13MdhRBFr94L97WDUkHYGnRwuC2qTFwxaWQKgg_sPdM0VmApdGFUwCFEqkGL02QMtnvxn9QgLuyi5-ie48BEBNEKbHyPE4A-CzpQMkwA6OOWRQzJ214DWYjZpaaG8NtPiLfrQhRw/s320/musicsheet.PNG" alt="" id="BLOGGER_PHOTO_ID_5517152225774961650" border="0" /></a>music piece used for this activity<br /></div><div><br /></div><div>First I chopped up the image into two images, one for each line and they both have the same dimensions and as much as possible, the positions of the staves in the images are the same. Then their colors were inverted such that the notes are white and the background is black.</div><div><br /></div><div><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiacPVADwTZNL2F__GlNrd40QHEAObBK5St4WoStKfOT1QuYrgNjtl8Q-_9Dt2EfI2Or_CERwFQlXKJjuYiMGXcHuwcaaLNGNq28MO3gcHECv7y8a7CSA26Wkp5i1ipKgaZ2vwOETflMvA/s1600/maryline2.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 418px; height: 34px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiacPVADwTZNL2F__GlNrd40QHEAObBK5St4WoStKfOT1QuYrgNjtl8Q-_9Dt2EfI2Or_CERwFQlXKJjuYiMGXcHuwcaaLNGNq28MO3gcHECv7y8a7CSA26Wkp5i1ipKgaZ2vwOETflMvA/s320/maryline2.PNG" alt="" id="BLOGGER_PHOTO_ID_5517152235076319858" border="0" /></a><br /><div style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_PLTo3fGZUtO2Cq7EJP-4FofbSgFHzUQKhK0UWqpp9WHKow29EDqFqi8l2OJxt-_e47WkIm8ZVqJMmYkFtg4Wd6Xui-5bfn0xBfXRMmushpi3BNook56kOCImttVGKqqZ6lJcD8CBntY/s1600/maryline1.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 414px; height: 40px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_PLTo3fGZUtO2Cq7EJP-4FofbSgFHzUQKhK0UWqpp9WHKow29EDqFqi8l2OJxt-_e47WkIm8ZVqJMmYkFtg4Wd6Xui-5bfn0xBfXRMmushpi3BNook56kOCImttVGKqqZ6lJcD8CBntY/s320/maryline1.PNG" alt="" id="BLOGGER_PHOTO_ID_5517152228247485074" border="0" /></a>inverted and "chopped" version of the music sheet<br /></div></div><div><br /></div><div>My approach in detecting the notes is to correlate them with templates of different notes. Luckily, this piece has only two kinds of notes: quarter note and half note. So, templates of these notes where made with the note being white and the background being black.</div><div><br /></div><div style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8_vXFRHprbmpqugYVzS-1UIPZOcBklTBBxu0jKaiN_Rk1wbOYdZnbWVMwfWUf-z2wBEiMh2UbhQPRJMTgjI3qdhrdWOikGzUW_aLjHVroW9fRB64WBPbW_U9CGMhlJpkSljXm5nwjmJ8/s1600/quarternote.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 397px; height: 32px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8_vXFRHprbmpqugYVzS-1UIPZOcBklTBBxu0jKaiN_Rk1wbOYdZnbWVMwfWUf-z2wBEiMh2UbhQPRJMTgjI3qdhrdWOikGzUW_aLjHVroW9fRB64WBPbW_U9CGMhlJpkSljXm5nwjmJ8/s320/quarternote.PNG" alt="" id="BLOGGER_PHOTO_ID_5517155032787055394" border="0" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQlKym0_rezoKNbG0p50yHN4BCQunrWibOc4VqMrXJdGN1zWEwrsXozlInRlkOBjaYKyBicUO172KjJSiJaJixFAFMpcWZPCriI8Q6cMHGiVIha7GTMZCDcuUPImZXcc_hEjfTo0roino/s1600/halfnote.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 395px; height: 32px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQlKym0_rezoKNbG0p50yHN4BCQunrWibOc4VqMrXJdGN1zWEwrsXozlInRlkOBjaYKyBicUO172KjJSiJaJixFAFMpcWZPCriI8Q6cMHGiVIha7GTMZCDcuUPImZXcc_hEjfTo0roino/s320/halfnote.PNG" alt="" id="BLOGGER_PHOTO_ID_5517155035517993282" border="0" /></a>quarter note and half note templates for matching<br /></div><div><br /></div><div>The 2 lines of the piece were loaded and binarized by determining the threshold from their grayscale histograms:</div><div><br /></div><div style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-09NbgCAFh8GjcIdDQ9Dp9lBwjdqgx65xV1EIPijtlA-j1519C6a5uGLTRAUhpkodDRSAF8k69Kh2nZhz-aH3VFhBNxUtsDEb6RXp3zJH9HHXPOhPZ25oLAzpiyJNyWcTIVy2_EEveAY/s1600/maryline1bw.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 392px; height: 31px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-09NbgCAFh8GjcIdDQ9Dp9lBwjdqgx65xV1EIPijtlA-j1519C6a5uGLTRAUhpkodDRSAF8k69Kh2nZhz-aH3VFhBNxUtsDEb6RXp3zJH9HHXPOhPZ25oLAzpiyJNyWcTIVy2_EEveAY/s320/maryline1bw.PNG" alt="" id="BLOGGER_PHOTO_ID_5517158842147851394" border="0" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrgM3wPA3FPg_3Ww4V8g594_A934sJhnqMnospXVyT6hINhTfnG7-B3OpKxUPPdi2GHtGf1jsOdNBF-e5zvVkofp7lKqYFxZfiXKXc-QcuQpzdEdLnvFyT9nK81bWr7_7nAj9FCIVF4BA/s1600/maryline2_bw.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 396px; height: 32px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrgM3wPA3FPg_3Ww4V8g594_A934sJhnqMnospXVyT6hINhTfnG7-B3OpKxUPPdi2GHtGf1jsOdNBF-e5zvVkofp7lKqYFxZfiXKXc-QcuQpzdEdLnvFyT9nK81bWr7_7nAj9FCIVF4BA/s320/maryline2_bw.PNG" alt="" id="BLOGGER_PHOTO_ID_5517158847083569106" border="0" /></a>black and white version of the two lines of notes<br /></div><br /><br /><div>Then their correlation with the quarter note and half note templates were taken. The result is a grayscale matrix and thresholding was once again done to reduce it into blobs. These blobs represent locations where there is a match. Afterwards these blobs were reduced into points or a single pixel for the next step - determining their relative locations from the staves.</div><div><br /></div><div style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEizr2-3ESB9xIWvf2dLAjBxVRsjT3WNiUD6O-38Nt3w5UwhFkfQyOyss12adSf7wRRa46bMxLJK6e65K83y0MjxtvA0grDsHaHsCEdTy-8RjmDs-SMA-r8OjgK7a50BN2dP0wbx8LT3EkA/s1600/line1corrquarternote.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 451px; height: 36px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEizr2-3ESB9xIWvf2dLAjBxVRsjT3WNiUD6O-38Nt3w5UwhFkfQyOyss12adSf7wRRa46bMxLJK6e65K83y0MjxtvA0grDsHaHsCEdTy-8RjmDs-SMA-r8OjgK7a50BN2dP0wbx8LT3EkA/s320/line1corrquarternote.PNG" alt="" id="BLOGGER_PHOTO_ID_5517161091293416386" border="0" /></a>line 1 correlated with the quarter note<br /><br /><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4abbgOR0kKHsCfjRaXkqz2sAyWk9T4duZ9N2MINnZxau1ljN58N9wLAhI85HV7YpeduTJ_bImUDw3V_ICybzWw0o7MBD_7_7QFEt6F3IpwjhyCnUeJXPEsC57ydoUq5t_KrVlu8w9XlA/s1600/linecorrhalfnote.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 468px; height: 38px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4abbgOR0kKHsCfjRaXkqz2sAyWk9T4duZ9N2MINnZxau1ljN58N9wLAhI85HV7YpeduTJ_bImUDw3V_ICybzWw0o7MBD_7_7QFEt6F3IpwjhyCnUeJXPEsC57ydoUq5t_KrVlu8w9XlA/s320/linecorrhalfnote.PNG" alt="" id="BLOGGER_PHOTO_ID_5517161102936130434" border="0" /></a>line 1 correlated with the half note<br /><br /><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVHGED38hjeiTrQWZcmQyWV91g9QRIrzITvb5Sif_gkt2Vf1vhyH22NPPQbAWNk7HNmM71cq3Zx5TssJf04S3VZ3_Rx51ckYYB1BoYtd_NZJ56zEK2VI1zv6viWHKOxpsr8drhkE1pZOw/s1600/line1corrquarternote_bw.png"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 448px; height: 36px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVHGED38hjeiTrQWZcmQyWV91g9QRIrzITvb5Sif_gkt2Vf1vhyH22NPPQbAWNk7HNmM71cq3Zx5TssJf04S3VZ3_Rx51ckYYB1BoYtd_NZJ56zEK2VI1zv6viWHKOxpsr8drhkE1pZOw/s320/line1corrquarternote_bw.png" alt="" id="BLOGGER_PHOTO_ID_5517161111339585426" border="0" /></a>black and white version of correlation of line 1 with quarter note<br /><br /><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSdk6egMX9RhivAgv81E8HbROSWk1QkYf6TRuv5nBssZCLEBCJsdiu7pleWYAawnfvPcr21bq-JDOtB77A6Og_RG-AfioQ00ydcR0QDLIrClRzY1tb18EUqj96dCbVaCSDCFvF2Xgh7Jk/s1600/line1corrquarternote_reduced.png"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 469px; height: 38px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSdk6egMX9RhivAgv81E8HbROSWk1QkYf6TRuv5nBssZCLEBCJsdiu7pleWYAawnfvPcr21bq-JDOtB77A6Og_RG-AfioQ00ydcR0QDLIrClRzY1tb18EUqj96dCbVaCSDCFvF2Xgh7Jk/s320/line1corrquarternote_reduced.png" alt="" id="BLOGGER_PHOTO_ID_5517161120562097522" border="0" /></a>reduced to single pixels (line 1 corr w/ quarter note)<br /></div><div><br /><div style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2h5FOow6HTII3DC2IplrY4tfZjWI2Strf9K762dy97U2G0d0pFNB8GATxfG2gvHD39qt0o4bvavC2QneM55L8lv4I22HOBhAgcsKNN4M-_QsDOKCmrPhz99iC-dWEunWITtov5HWUdc0/s1600/line1corrhalfnote_reduced.png"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 482px; height: 38px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2h5FOow6HTII3DC2IplrY4tfZjWI2Strf9K762dy97U2G0d0pFNB8GATxfG2gvHD39qt0o4bvavC2QneM55L8lv4I22HOBhAgcsKNN4M-_QsDOKCmrPhz99iC-dWEunWITtov5HWUdc0/s320/line1corrhalfnote_reduced.png" alt="" id="BLOGGER_PHOTO_ID_5517161128654259506" border="0" /></a>reduced to single pixels (line 1 corr w/ half note)<br /></div><br /></div><div>However, one problem encountered was that since the quarter and half notes differ by only just a little (shaded and not shaded), their correlation values with one another are high. Therefore when I used the quarter note template, all the quarter and half notes showed up. Adjusting the threshold didn't help as the true positives would disappear along with the false ones. Instead I remedied this by also taking the correlation with the half note and thresholding it such that only the quarter note showed up... and from these information, the type of note can be deduced.</div><div><br /></div><div>The next task is to determine their relative vertical positions in order to determine their frequency. Due to the correlation, there is an offset between the position of the pixel from where the "body/blob" of the note should be. This is easily fixed by determining that offset. Also, the positions of the lines in the staves as well as the center of the spaces between them are taken. Then using an if-elseif-else statement, the relative positions of the notes can be determined. An error of +- 3 pixels is incorporated to compensate for the small fluctuations of the positions of the notes.</div><div><br /></div><div>Finally, by combining the frequency of the note and it's timing (quarter or half), the piece can be played by the computer and the sound file is saved using wavwrite function. Here it is:</div><div><br /></div><div>http://www.mediafire.com/?4wlr5qfjwba88at</div><div><br /></div><div>Yay! :D</div><div><br /></div><div>Lastly to grade myself, I give a 10/10 for being able to produce the required output and understand and integrate past lessons.</div><div style="font-weight: bold;"><br /></div><div style="font-weight: bold;">Score: 10/10</div><div><br /></div><div>I would also like to thank Dr. Soriano, Arvin Mabilangan, Gino Leynes, Troy Gonzales, BA Racoma, Tisza Trono, Joseph Bunao for the very helpful discussions. :)<br /><br /><br />References:<br />1. M. Soriano, "A11 - Playing Notes by Image Processing<br />2. Physics of Music - Notes, (http://www.phy.mtu.edu/~suits/notefreqs.html) for the frequencies of the notes.<br /><br /><br />Appendix: (Code)<br />// AP186 Act11 Playing note by image processing<br /><br />function n = note(f,t)<br />n = sin(2*%pi*f*t)<br />endfunction;<br /><br /><br />A1 = gray_imread("C:\maryline1.png");<br />T = gray_imread("C:\quarternote.png");<br /><br />// threshold for A1 is determined to be 0.3<br />A1bw = im2bw(A1, 0.3);<br />Tbw = im2bw(T, 0.5);<br /><br />// correlate with quarternote<br />FTA = fft2(A1bw);<br />FTT = fft2(Tbw);<br />FTAconj = conj(FTA);<br />B = fftshift(abs(fft2(FTAconj.*FTT)));<br /><br />//threshold chosen to be 0.88<br />Bbw = im2bw(B, 0.88);<br /><br />[L, n] = bwlabel(Bbw);<br /><br />// To reduce blobs to dots<br />Bbwsize = size(Bbw);<br />quarternotecorr = zeros(Bbwsize(1), Bbwsize(2));<br />for i=1:n<br />[r, c] = find(L==i);<br />rc = [r' c'];<br />r = rc(:,1);<br />c = rc(:,2);<br />chalfvalue = c(int((length(c)+1)/2));<br />rhalfvalue = r(int((length(find(c==chalfvalue))+1)/2));<br />quarternotecorr(rhalfvalue, chalfvalue) = 1;<br />end<br /><br />// correlate with halfnote<br />T = gray_imread("C:\halfnote.png");<br />Tbw = im2bw(T, 0.5);<br /><br />FTT = fft2(Tbw);<br />B = fftshift(abs(fft2(FTAconj.*FTT)));<br /><br />//threshold chosen to be 0.96<br />Bbw = im2bw(B, 0.96);<br /><br />[L, n] = bwlabel(Bbw);<br /><br />// To reduce blobs to dots<br />Bbwsize = size(Bbw);<br />halfnotecorr = zeros(Bbwsize(1), Bbwsize(2));<br />for i=1:n<br />[r, c] = find(L==i);<br />rc = [r' c'];<br />r = rc(:,1);<br />c = rc(:,2);<br />chalfvalue = c(int((length(c)+1)/2));<br />rhalfvalue = r(int((length(find(c==chalfvalue))+1)/2));<br />halfnotecorr(rhalfvalue, chalfvalue) = 1;<br />end<br /><br />allnotes = halfnotecorr;<br /><br />// To determine which ones are halfnotes<br />strel = ones(25,25);<br />quarternotecorr_dilated = dilate(quarternotecorr, strel, [13,13]);<br /><br />[r c] = find(halfnotecorr==1);<br />rc=[r' c'];<br />len = length(rc(:,1));<br /><br />halfnotecorr = zeros(Bbwsize(1), Bbwsize(2)); // reuse variables<br />for i=1:len<br />halfr = rc(i,1);<br />halfc = rc(i,2);<br />value = quarternotecorr_dilated(halfr, halfc);<br />if value == 0<br /> halfnotecorr(halfr, halfc) = 1;<br />end<br />end<br /><br />// Determine the positions of the blobs and timing<br />[L, Nnotes] = bwlabel(allnotes);<br />t_quarter = soundsec(0.25);<br />t_half = soundsec(0.5);<br />t_error = soundsec(3);<br /><br />Cnote = 2*261.63;<br />Dnote = 2*293.66;<br />Enote = 2*329.63;<br />Fnote = 2*349.23;<br />Gnote = 2*392.00;<br /><br />err = 3;<br />offset = 17; // determined from pics<br />Clvl = 86;<br />Dlvl = 80;<br />Elvl = 73;<br />Flvl = 66;<br />Glvl = 60;<br /><br />s=[];<br /><br />halfnotecorr_dilated = dilate(halfnotecorr, strel, [13,13]);<br /><br />// BWLABEL IS NOT RELIABLE!!<br />[row, col] = find(allnotes==1);<br />n = length(row);<br /><br />for i=1:n<br />r = row(i);<br />c = col(i);<br />valueQTR = quarternotecorr_dilated(r, c);<br />valueHLF = halfnotecorr_dilated(r, c);<br />r = r + offset;<br />if r >= (Dlvl + 3)<br /> f = Cnote;<br />elseif r > (Elvl+3)<br /> f = Dnote;<br />elseif r > (Flvl +3)<br /> f = Enote;<br />elseif r >= (Glvl + 3)<br /> f = Fnote;<br />else<br /> f = Gnote;<br />end<br />if valueQTR == 1<br /> t = t_quarter;<br />elseif valueHLF == 1<br /> t = t_half;<br />else<br /> t = t_error;<br />end<br />s = [s note(f, t)];<br />clear r;<br />clear c;<br />end<br /><br /><br /><br /><br />///////////////////////////////////////////////////////<br /><br /><br /><br />// FOR THE 2ND LINE OF MARY HAD A LITTLE LAMB<br />A1 = gray_imread("C:\maryline2.png");<br />T = gray_imread("C:\quarternote.png");<br /><br />// threshold for A1 is determined to be 0.3<br />A1bw = im2bw(A1, 0.3);<br />Tbw = im2bw(T, 0.5);<br /><br />// correlate with quarternote<br />FTA = fft2(A1bw);<br />FTT = fft2(Tbw);<br />FTAconj = conj(FTA);<br />B = fftshift(abs(fft2(FTAconj.*FTT)));<br /><br />//threshold chosen to be 0.88<br />Bbw = im2bw(B, 0.88);<br /><br />[L, n] = bwlabel(Bbw);<br /><br />// To reduce blobs to dots<br />Bbwsize = size(Bbw);<br />quarternotecorr = zeros(Bbwsize(1), Bbwsize(2));<br />for i=1:n<br />[r, c] = find(L==i);<br />rc = [r' c'];<br />r = rc(:,1);<br />c = rc(:,2);<br />chalfvalue = c(int((length(c)+1)/2));<br />rhalfvalue = r(int((length(find(c==chalfvalue))+1)/2));<br />quarternotecorr(rhalfvalue, chalfvalue) = 1;<br />end<br /><br />// correlate with halfnote<br />T = gray_imread("C:\halfnote.png");<br />Tbw = im2bw(T, 0.5);<br /><br />FTT = fft2(Tbw);<br />B = fftshift(abs(fft2(FTAconj.*FTT)));<br /><br />//threshold chosen to be 0.995<br />Bbw = im2bw(B, 0.96);<br /><br />[L, n] = bwlabel(Bbw);<br /><br />// To reduce blobs to dots<br />Bbwsize = size(Bbw);<br />halfnotecorr = zeros(Bbwsize(1), Bbwsize(2));<br />for i=1:n<br />[r, c] = find(L==i);<br />rc = [r' c'];<br />r = rc(:,1);<br />c = rc(:,2);<br />chalfvalue = c(int((length(c)+1)/2));<br />rhalfvalue = r(int((length(find(c==chalfvalue))+1)/2));<br />halfnotecorr(rhalfvalue, chalfvalue) = 1;<br />end<br /><br />allnotes = halfnotecorr;<br /><br />// To determine which ones are halfnotes<br />strel = ones(25,25);<br />quarternotecorr_dilated = dilate(quarternotecorr, strel, [13,13]);<br /><br />[r c] = find(halfnotecorr==1);<br />rc=[r' c'];<br />len = length(rc(:,1));<br /><br />halfnotecorr = zeros(Bbwsize(1), Bbwsize(2)); // reuse variables<br />for i=1:len<br />halfr = rc(i,1);<br />halfc = rc(i,2);<br />value = quarternotecorr_dilated(halfr, halfc);<br />if value == 0<br /> halfnotecorr(halfr, halfc) = 1;<br />end<br />end<br /><br />// Determine the positions of the blobs and timing<br />[L, Nnotes] = bwlabel(allnotes);<br /><br />halfnotecorr_dilated = dilate(halfnotecorr, strel, [13,13]);<br /><br />// BWLABEL IS NOT RELIABLE!!<br />[row, col] = find(allnotes==1);<br />n = length(row);<br /><br />for i=1:n<br />r = row(i);<br />c = col(i);<br />valueQTR = quarternotecorr_dilated(r, c);<br />valueHLF = halfnotecorr_dilated(r, c);<br />r = r + offset;<br />if r >= (Dlvl + 3)<br /> f = Cnote;<br />elseif r > (Elvl+3)<br /> f = Dnote;<br />elseif r > (Flvl +3)<br /> f = Enote;<br />elseif r >= (Glvl + 3)<br /> f = Fnote;<br />else<br /> f = Gnote;<br />end<br />if valueQTR == 1<br /> t = t_quarter;<br />elseif valueHLF == 1<br /> t = t_half;<br />else<br /> t = t_error;<br />end<br />s = [s note(f, t)];<br />clear r;<br />clear c;<br />end<br /><br /><br />sound(s);<br /><br />--------------------------end----------------------------<br /></div>dennisivan89http://www.blogger.com/profile/04476991777095665795noreply@blogger.com0tag:blogger.com,1999:blog-7345763871585817117.post-59951879681034705382010-09-01T20:16:00.000-07:002010-09-23T08:51:06.207-07:00AP 186 Act10 - Binary OperationsWe're back again after a long delay because of SPP hahaha XD<br /><br />Anyway, in this activity we will be applying the morphological operations as well as the lessons learned in previous activities to determine the best estimate of a cell from an image and then filter out cancer cells later on. :)<br /><br />So the first part is to determine the best estimate (mean +- stdev) of a normal cell given an image. An image was provided to us wherein the punched papers represent the cells.<br /><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgqAn1fPmCYMZZYdjjMGD8dgSYBYPcgK_76MHiRJH1UYs3_7AyG40NF9PxEjgWcLMEZmXXMJ4YklX3OTZXPlcooJ9UJ9y1o9skonTaE-tz_jZtrdkKbj4sKfhXx5eLdEKnWpDNh6n2Pf4I/s1600/Circles002.jpg"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 174px; height: 217px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgqAn1fPmCYMZZYdjjMGD8dgSYBYPcgK_76MHiRJH1UYs3_7AyG40NF9PxEjgWcLMEZmXXMJ4YklX3OTZXPlcooJ9UJ9y1o9skonTaE-tz_jZtrdkKbj4sKfhXx5eLdEKnWpDNh6n2Pf4I/s320/Circles002.jpg" alt="" id="BLOGGER_PHOTO_ID_5512244654848182146" border="0" /></a>Circles<br /></div><br />And we were asked to crop this image into 256 x 256 sub images. Here are sample subimages:<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgsJ4tKb9qHtk7ZpmHIkePXB8ZMMWPwgz8vSIJQdy5-NGqP59yq8eXoLob40-6S_2Aw_HidE7uSb23CutRZtrAoybto48bqP8YzF9eNlmih4VfF3WTb1ruuhOm2R5KVPl7JemnUWivhsRs/s1600/C_01.png"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 153px; height: 153px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgsJ4tKb9qHtk7ZpmHIkePXB8ZMMWPwgz8vSIJQdy5-NGqP59yq8eXoLob40-6S_2Aw_HidE7uSb23CutRZtrAoybto48bqP8YzF9eNlmih4VfF3WTb1ruuhOm2R5KVPl7JemnUWivhsRs/s320/C_01.png" alt="" id="BLOGGER_PHOTO_ID_5512244664084052642" border="0" /></a><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-dvkNBtrLk0ZAU0ezudbyUoGGrPyHs9dT-ToUz1BVXIMX3uc-pi0FQea-fMc8xOQ1DTSrSEy7hN7mHgKGY42jo3tpglwdwAUq7K2jVdTvGpo44h0TXV8A7P3f-AYT9BDNRelK7Q4QtdE/s1600/C_09.png"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 144px; height: 144px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-dvkNBtrLk0ZAU0ezudbyUoGGrPyHs9dT-ToUz1BVXIMX3uc-pi0FQea-fMc8xOQ1DTSrSEy7hN7mHgKGY42jo3tpglwdwAUq7K2jVdTvGpo44h0TXV8A7P3f-AYT9BDNRelK7Q4QtdE/s320/C_09.png" alt="" id="BLOGGER_PHOTO_ID_5512244676225108706" border="0" /></a>sample sub-images<br /></div><br />We also cropped out an individual cell to determine it's size:<br /><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8tKEpcyvSmfDkY4UnbqSckIGPsOQelkjBx151fA9ZltzWJSHmY1E7W0vAd4vna_bDNhU5PuGcSUAEGCbxrdX0UDASptWu9oqot1pIdFYgWwKl3teEyeG-qlE4JmgWdBGxs3xVkUnwbks/s1600/unitcell.png"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 64px; height: 64px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8tKEpcyvSmfDkY4UnbqSckIGPsOQelkjBx151fA9ZltzWJSHmY1E7W0vAd4vna_bDNhU5PuGcSUAEGCbxrdX0UDASptWu9oqot1pIdFYgWwKl3teEyeG-qlE4JmgWdBGxs3xVkUnwbks/s320/unitcell.png" alt="" id="BLOGGER_PHOTO_ID_5512244689685330626" border="0" /></a>a normal cell<br /></div><br />So we get it's histogram and determine the best value for the threshold in converting it to black and white:<br /><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg0TltbfrKaCJSewTqLdRdFpZ8LAdoAoFra-u6VBsT8Y7pY7YRg59fAuyFjjIvj0bVSG9OHiyIZhhKSdh6vg2fSDE5_3T31TARushLdN9HP__ZT2F65hwfBt8pglwEotM3R8UMOoomokHg/s1600/normal+cell+grayscale+histogram.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 243px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg0TltbfrKaCJSewTqLdRdFpZ8LAdoAoFra-u6VBsT8Y7pY7YRg59fAuyFjjIvj0bVSG9OHiyIZhhKSdh6vg2fSDE5_3T31TARushLdN9HP__ZT2F65hwfBt8pglwEotM3R8UMOoomokHg/s320/normal+cell+grayscale+histogram.PNG" alt="" id="BLOGGER_PHOTO_ID_5512253390803398450" border="0" /></a>histogram of gray scale values<br /></div><br />and we have determined the threshold to be 0.79. Next we convert this image to black and white, and perform opening to close the salt and pepper noise around the cell. Then using what we learned in the Area estimation activity, I determined the cell to have an area of 519 pixels.<br /><br />However this is not the best estimate for the area, it is just to give us an idea around what value the area is. To determine the best estimate, we loop through every sub-image, convert this to black and white, perform closing to close off the holes inside the cell (due to noise), and then perform opening to remove the salt and pepper noise outside the cells. Then we used bwlabel to identify each blob, and for each blob, we measured the area and tallied them. This was done for all subimages.<br /><br />The structuring element (strel) for the opening operation is a circle with it's size being a little smaller than the area of the cell. Thus, blobs smaller than this would be erased. Meanwhile the strel used for the closing operation is also a circle but it's size is very small, this is to make the noise or small holes in the cell disappear while minimizing the tendency of closely adjacent blobs to merge due to the closing operation.<br /><br />Next we plot the histogram of all the tallied areas:<br /><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEirNxoiun9ySRnC5bPF2q6NLYvUIWwvU52YjxFdxx1xVYjs7Qiv3nu9BBnLy2NCv9kyNhoN97OoujyqWXdzvSNFPN-bJe2xLFAZ-RF8tLIJ_YxK7zRULq-hdrt67jKTcov0iknpsyElxgI/s1600/histogram.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 238px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEirNxoiun9ySRnC5bPF2q6NLYvUIWwvU52YjxFdxx1xVYjs7Qiv3nu9BBnLy2NCv9kyNhoN97OoujyqWXdzvSNFPN-bJe2xLFAZ-RF8tLIJ_YxK7zRULq-hdrt67jKTcov0iknpsyElxgI/s320/histogram.PNG" alt="" id="BLOGGER_PHOTO_ID_5512245598398107074" border="0" /></a>histogram of tallied areas<br /></div><br />zooming in to the range around 519... (area of the unit cell:<br /><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi0AsX_guwS61Sp_OJYzSQHV6C3TXusmAKionk_QLMvOCFirqD4lH-iShbQtZWtdPWjYTjSpxA6whVYRPgiOJda7HCVv3C0IPxP1qrVY-Zed2MfOdH9yKg-EqxTOXo-5SBsPl6qYsqUx90/s1600/histogram_2.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 236px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi0AsX_guwS61Sp_OJYzSQHV6C3TXusmAKionk_QLMvOCFirqD4lH-iShbQtZWtdPWjYTjSpxA6whVYRPgiOJda7HCVv3C0IPxP1qrVY-Zed2MfOdH9yKg-EqxTOXo-5SBsPl6qYsqUx90/s320/histogram_2.PNG" alt="" id="BLOGGER_PHOTO_ID_5512245604545427250" border="0" /></a>zoomed-in histogram of tallied areas<br /></div><br />but beware! Using too few bins for the histogram would lead to inaccurate estimates for the area. From the above histogram, one might think the range would be 350 - 650 pixels. However, using more bins we see that...<br /><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7GrBW_CuQyYIeg-daGX-e-HlzgarUIfIulM0RqO9H94xg6x2VXaFrTwHQP48ZDa7c9hhN_LB-XHmAWTUy04XXpyWPE7rK3jMk0yTouFW99gWq1rUcPRkDZwIYs31_w1T30Xw1OKKYZvE/s1600/histogram_better.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 238px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7GrBW_CuQyYIeg-daGX-e-HlzgarUIfIulM0RqO9H94xg6x2VXaFrTwHQP48ZDa7c9hhN_LB-XHmAWTUy04XXpyWPE7rK3jMk0yTouFW99gWq1rUcPRkDZwIYs31_w1T30Xw1OKKYZvE/s320/histogram_better.PNG" alt="" id="BLOGGER_PHOTO_ID_5512245619804503282" border="0" /></a>histogram of tallied areas using more bins<br /></div><br />and zooming in,<br /><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_Oae91zoZOY1cyqXymqr6kPm1r_UEAzLlTcOiglzKwXkITloZhbqYFuFjeyJCd37E1GI0BragfvBcvC4Ck9jo9xs7pL0oKiOm9Qwbe01kPvSKChm1D-pPdbjYptgs9WTqPJGseBVDCM8/s1600/histogram_better2.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 235px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_Oae91zoZOY1cyqXymqr6kPm1r_UEAzLlTcOiglzKwXkITloZhbqYFuFjeyJCd37E1GI0BragfvBcvC4Ck9jo9xs7pL0oKiOm9Qwbe01kPvSKChm1D-pPdbjYptgs9WTqPJGseBVDCM8/s320/histogram_better2.PNG" alt="" id="BLOGGER_PHOTO_ID_5512245622650698034" border="0" /></a>zoomed-in histogram using more bins<br /></div><br />We can see that it is now separated into two ranges. Therefore the more accurate range would be around 450 - 650 pixels. We then get the values falling in that range and compute for the mean and standard deviation. The best estimate for the normal cell is 528.96825 +- 25.079209 pixels.<br /><br />For the next part, we are given another image with some "cells" being bigger than others. These represent cancer cells and we're asked to design and implement a procedure for isolating these cells.<br /><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4jCNA2aBjdTp3hr0v6FsxLxXFLw_eyatnl5CnSV4eKkYIefi75EKDrc5VmXk8KKinmr0eWaaYxsi1yOgcbz1P8QPAUa4y9tsPHcoYdPpFAz6OVF3BOKnRapvQxdg1iyvD-JynSdx3CkM/s1600/Circles_with_cancer.jpg"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 247px; height: 203px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4jCNA2aBjdTp3hr0v6FsxLxXFLw_eyatnl5CnSV4eKkYIefi75EKDrc5VmXk8KKinmr0eWaaYxsi1yOgcbz1P8QPAUa4y9tsPHcoYdPpFAz6OVF3BOKnRapvQxdg1iyvD-JynSdx3CkM/s320/Circles_with_cancer.jpg" alt="" id="BLOGGER_PHOTO_ID_5512248956351833570" border="0" /></a>normal cells with cancer cells<br /></div><br />So just like in the procedure a while ago, we first determine the best threshold value by getting the histogram of the gray scale image:<br /><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjLk9aLHyZWlT6GDBZjxDukSgdpAVtEeFgLnwt3KcSn6jsAK5VMh-uZ0DeDynHcra3kDuxlvz1hpvbj7Y0wd-ai_24Z9Slu7XWxCoh_v7PQJo4t8O4qFNYIXlLv57KZx5uWpgYij1P8ftg/s1600/histogram_cancer.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 250px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjLk9aLHyZWlT6GDBZjxDukSgdpAVtEeFgLnwt3KcSn6jsAK5VMh-uZ0DeDynHcra3kDuxlvz1hpvbj7Y0wd-ai_24Z9Slu7XWxCoh_v7PQJo4t8O4qFNYIXlLv57KZx5uWpgYij1P8ftg/s320/histogram_cancer.PNG" alt="" id="BLOGGER_PHOTO_ID_5512248965769933554" border="0" /></a>histogram of gray scale image<br /></div><br />The best threshold is chosen to be 0.845. This is the black and white version of it:<br /><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgUAwueCgQ5139HJprjlZrKo3cvoC6Mh31eG7ynlAmgsSs-yfVNpPsaCuwM1a69qS0reWq4-xVEPk8f5G41dEvxPkvA9u5sn8RnPMom7gCUq4gXJ-iRFwHH8WJsS3nxEbhYrSV-T1EgEgc/s1600/cancer_bw.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 242px; height: 203px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgUAwueCgQ5139HJprjlZrKo3cvoC6Mh31eG7ynlAmgsSs-yfVNpPsaCuwM1a69qS0reWq4-xVEPk8f5G41dEvxPkvA9u5sn8RnPMom7gCUq4gXJ-iRFwHH8WJsS3nxEbhYrSV-T1EgEgc/s320/cancer_bw.PNG" alt="" id="BLOGGER_PHOTO_ID_5512248975104972962" border="0" /></a>after converting to black and white<br /></div><br />Then we cropped out an individual "cancer cell" and determined its size to be 998 pixels. We converted the image to black and white, perform closing and opening:<br /><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZ4-MKPRm3J1HcG1beKmQDyXAI2SjggCM3J42rROYTCkpWCQfAQXmH2M2M4JF8JVL5XfKDV7dWwBFlYh0lUn61taj0IO6l0n3kZwKj9xxsG6luMfDfw6sUoiy16B4Cmwq1lhrrIAxOUpY/s1600/unitcancercell.JPG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 66px; height: 61px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZ4-MKPRm3J1HcG1beKmQDyXAI2SjggCM3J42rROYTCkpWCQfAQXmH2M2M4JF8JVL5XfKDV7dWwBFlYh0lUn61taj0IO6l0n3kZwKj9xxsG6luMfDfw6sUoiy16B4Cmwq1lhrrIAxOUpY/s320/unitcancercell.JPG" alt="" id="BLOGGER_PHOTO_ID_5512248985949793058" border="0" /></a>"cancer cell"<br /><br /></div><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjan-xRRDJve7mtINASW7HcCljBYdzRrQQEb5UnIYpf-MkUPfQmLaoOOgXoaInlbLmQQNW_g0NBsIvTIla03fkUuTUEMR6qwVWjdH6ehWa-52wdhh5rtwWI2RQQJPF8OFCdYLYUGYsU_8w/s1600/cancer_after_closing_opening.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 230px; height: 190px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjan-xRRDJve7mtINASW7HcCljBYdzRrQQEb5UnIYpf-MkUPfQmLaoOOgXoaInlbLmQQNW_g0NBsIvTIla03fkUuTUEMR6qwVWjdH6ehWa-52wdhh5rtwWI2RQQJPF8OFCdYLYUGYsU_8w/s320/cancer_after_closing_opening.PNG" alt="" id="BLOGGER_PHOTO_ID_5512249390009147810" border="0" /></a>after performing closing and opening<br /></div><br />and using bwlabel, the areas of all the blobs were tallied and their histogram is:<br /><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTxsomY2U3FiUbjH2-Qs099bptHzFLtjPRpJA-PRQAiYO2mxlCXQBlzcn9dglbIxqFMpBD7wGXLdAm4_vPAhFULj6eMGgl66XW9JVQeTqfF8ljgTVr6S07f-ZwA24-RCNLpAMzKHWFu40/s1600/histogram_cancer2.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 234px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTxsomY2U3FiUbjH2-Qs099bptHzFLtjPRpJA-PRQAiYO2mxlCXQBlzcn9dglbIxqFMpBD7wGXLdAm4_vPAhFULj6eMGgl66XW9JVQeTqfF8ljgTVr6S07f-ZwA24-RCNLpAMzKHWFu40/s320/histogram_cancer2.PNG" alt="" id="BLOGGER_PHOTO_ID_5512248997077865554" border="0" /></a>histogram of tallied areas<br /></div><br />We select the range from 950 - 1050 pixels and get their mean and standard deviation. The best estimate of the "cancer cell" is 998.3333 +- 19.033304 pixels.<br /><br />Next, we loop through every blob and check if its area is within this range, if it is not, the blob is erased. Finally, we obtain the following result:<br /><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihgzQdhfSjB-xMgHcTfOgMNK-BacI_FYu7RO_DmpUF7r1oNRnYejjtUfI7WQbDsZ8A4XvzTu7IC8jCKXTNeAupZW7NDLdCtUmKI777nKpiildxHDUvqE-6OUEWPqps1qTcH-lmT8Y-a_g/s1600/cancer_filtered.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 264px; height: 218px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihgzQdhfSjB-xMgHcTfOgMNK-BacI_FYu7RO_DmpUF7r1oNRnYejjtUfI7WQbDsZ8A4XvzTu7IC8jCKXTNeAupZW7NDLdCtUmKI777nKpiildxHDUvqE-6OUEWPqps1qTcH-lmT8Y-a_g/s320/cancer_filtered.PNG" alt="" id="BLOGGER_PHOTO_ID_5512251326693580066" border="0" /></a>isolated cancer cells with some blobs of overlapping normal cells<br /></div><br />comparing this to the original image, all 5 "cancer cells" were isolated. However, there are also blobs which are just overlaps of two normal cells that are included because their area falls within the range. This is acceptable since this is just the first pass for the filter, additional filters would also examine the shape of these "cells" and distinguish which is which. But nevertheless we have isolated these "cancer cells" using binary operations. :D<br /><br />For the score, I give myself a 10/10 for producing all the required output and understanding the lesson.<br /><br /><span style="font-weight: bold;">Score : 10/10</span><br /><br />And I would like to acknowledge Dr. Soriano, BA Racoma, Theiss Trono, Arvin Mabilangan and Joseph Bunao for the helpful discussions. Thank you :)<br /><br />- Dennis<br /><br />References:<br />1. M. Soriano, "A10 - Binary Operations"<br /><br />Appendix: Code<br /><br />Getting threshold value of circles.jpg<br /><br />A = gray_imread("C:\unitcell.png");<br />histplot(75, A);<br /><br />// Set the strel:<br />nx = 27;<br />ny = 27;<br />x = linspace(-1,1,nx);<br />y = linspace(-1,1,ny);<br />[X,Y] = ndgrid(x,y);<br />r = sqrt(X.^2 + Y.^2);<br />strelopen = zeros (nx,ny);<br />strelopen(find(r<0.8)) strelclose =" zeros" arealist =" [];" b =" im2bw(A," c =" erode(B," d =" dilate(C," e="="1);" rc =" [r'" s =" size(rc);" unitcellsize =" s(1);" i =" 1:14" a =" gray_imread(" b =" im2bw(A," c =" dilate(B," d =" erode(C," e =" erode(D," f =" dilate(E," i =" 1:n" l="="i);" rc =" [r'" s =" size(rc);" area =" s(1);" arealist =" [Arealist" g =" find(Arealist" h =" Arealist(G);" i =" find(H"> 440);<br />J = H(I);<br /><br />// Get the mean and stdev:<br />ave = mean(J);<br />sdev = stdev(J);<br /><br />---------------------------------<br />For 2nd part:<br /><br /><br />// Procedure for isolating cancer cells in Circles_with_cancer.jpg<br />A = gray_imread("C:\Circles_with_cancer.jpg");<br /><br />//Get histogram of grayscale values:<br />histplot(75, A);<br />//Now you have the threshold value. Choose it to be 0.845<br />threshold = 0.845;<br /><br /><br />//Get area of cancer unit cell<br />A = gray_imread("C:\unitcancercell.jpg");<br />B = im2bw(A, threshold);<br />C = erode(B, strel, [13, 13]);<br />D = dilate(C, strel,[13, 13]);<br />[E, n] = bwlabel(D);<br />[r, c] = find(E==1);<br />rc = [r' c'];<br />s = size(rc);<br />unitcellsize = s(1);<br />unitcellsize is determined to be 998 pixels.<br /><br />B = im2bw(A, threshold);<br /><br />// Perform closing first<br />C = dilate(B, strelclose, [14, 14]);<br />D = erode(C, strelclose, [14,14]);<br /><br />// Perform opening<br />E = erode(D, strelopen, [14,14]);<br />F = dilate(E, strelopen, [14,14]);<br /><br />[L, n] = bwlabel(F);<br /><br />for i = 1:n<br />[r, c] = find(L==i);<br />rc = [r' c'];<br />s = size(rc);<br />Area = s(1);<br />Arealist = [Arealist Area];<br />end<br /><br />histplot(200, Arealist);<br /><br />// Cancer cell size: 998.3333 +- 19.033304 pixels.<br /><br />Area_lowerbound = 998.3333 - 19.033304;<br />Area_upperbound = 998.3333 + 19.033304;<br /><br />X = zeros(618, 748);<br /><br />for i = 1:n<br />[r, c] = find(L==i);<br />rc = [r' c'];<br />s = size(rc);<br />Area = s(1);<br />if Area > Area_lowerbound then<br /> if Area < Area_upperbound then<br /> X(find(L==i)) = 1;<br /> end<br />clear rc;<br />clear s;<br />clear Area;<br />end<br />end<br /><br />imshow(X,[]);<br /><br /><br />-----------end-------------dennisivan89http://www.blogger.com/profile/04476991777095665795noreply@blogger.com0tag:blogger.com,1999:blog-7345763871585817117.post-77584550237684768992010-08-10T02:26:00.000-07:002010-09-23T08:50:28.348-07:00AP 186 Act9 - Morphological OperationHere in this activity, we'll be familiarizing ourselves with some morphological operations such as dilation and erosion. Morphological operations are used in image processing to reshape the image in some way and this is useful when one is extracting information from an image.<br /><br />What we did is to try to predict the results of:<br /><br />1. 5 x 5 square<br />2. A triangle, base = 4 boxes, height = 3 boxes<br />3. A hollow 10 x 10 square, 2 boxes thick<br />4. A plus sign, one box thick and 5 boxes along each line.<br /><br />when dilated and eroded with:<br /><br />a. 2 x 2 ones<br />b. 2 x 1 ones<br />c. 1 x 2 ones<br />d. cross, 3 pixels long, 1 pixel thick<br />e. A diagonal line, two boxes long: [0 1, 1 0].<br /><br />and see if our results match when this is done via scilab.<br />The origin for the structuring element is (1, 1) if it can fit in a 2 x 2 array. If the (1, 1) element is not present, then the center will be (2, 1). For the cross, the center is located at its center.<br /><br />Now, the following are the results:<br /><br />Dilation:<br /><br /><span style="color: rgb(255, 0, 0);font-size:130%;" >5 x 5 square</span> dilated/eroded by a, b, c, d and e:<br /><br /><span style="font-weight: bold;">Left figure shows the original image, middle figure shows dilated/eroded image using scilab, right figure shows predicted image after dilation/erosion.</span><br /><br /><div style="text-align: left;">2 x 2 ones:<br />dilation:<br /></div><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjc-cDr-g8F9C5iRYhgxlrdmay5nZAVEUAddCw_tWllwPd4wgG9ddPw31FodxXAdHeRxG880aVRwLf3jcxg3BIBs2sjXpuWj4J82CIodNV0spw3jwAsO4lofevGqKpafeHWYPvVd3bQD-g/s1600/1dilate1.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 95px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjc-cDr-g8F9C5iRYhgxlrdmay5nZAVEUAddCw_tWllwPd4wgG9ddPw31FodxXAdHeRxG880aVRwLf3jcxg3BIBs2sjXpuWj4J82CIodNV0spw3jwAsO4lofevGqKpafeHWYPvVd3bQD-g/s320/1dilate1.PNG" alt="" id="BLOGGER_PHOTO_ID_5503715294460078994" border="0" /></a>erosion:<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhXr1zGhaXUhuk14yZ54s39HDSapv7Q-RsfEL8Pdvy3ZUZCF539zp5N090t9SSnX9ARayNMduC81yN4WlXgbMZNHl01xp0o_ye_blRIKM1bpY0SmsP7s-hz7GBkkpAaRBpVcIueEYKK6ag/s1600/1erode1.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 109px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhXr1zGhaXUhuk14yZ54s39HDSapv7Q-RsfEL8Pdvy3ZUZCF539zp5N090t9SSnX9ARayNMduC81yN4WlXgbMZNHl01xp0o_ye_blRIKM1bpY0SmsP7s-hz7GBkkpAaRBpVcIueEYKK6ag/s320/1erode1.PNG" alt="" id="BLOGGER_PHOTO_ID_5503734783001651138" border="0" /></a><br /><br />2 x 1 ones:<br />dilation:<br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiNdR7rELo7V9hH-EYORla_Bl8FLyKVi7ZuNpiR4cxFLZHmzUHA2XF6n5-_RzzUWYmz-wK4ZwhfhvL4p_x4v7a11d4al8U03sZ19CSy6fP8j6aHCMrvwk4m0nbYtLOHOWnh4GEhTQGuIDQ/s1600/1dilate2.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 100px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiNdR7rELo7V9hH-EYORla_Bl8FLyKVi7ZuNpiR4cxFLZHmzUHA2XF6n5-_RzzUWYmz-wK4ZwhfhvL4p_x4v7a11d4al8U03sZ19CSy6fP8j6aHCMrvwk4m0nbYtLOHOWnh4GEhTQGuIDQ/s320/1dilate2.PNG" alt="" id="BLOGGER_PHOTO_ID_5503715303334865106" border="0" /></a>erosion:<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihb3lSr3HExMZebi_BK4UR85z1ImS4ODUfX5WwXFel8tQRppXYJhw_E02KZQTNwKn1oOcvDom5rynyvWy6MiChxrVTAncmXBGpSOW0JTgw7rPMBoZDy66XTMkUbFe87wcv8GPdFuaH8xo/s1600/1erode2.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 106px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihb3lSr3HExMZebi_BK4UR85z1ImS4ODUfX5WwXFel8tQRppXYJhw_E02KZQTNwKn1oOcvDom5rynyvWy6MiChxrVTAncmXBGpSOW0JTgw7rPMBoZDy66XTMkUbFe87wcv8GPdFuaH8xo/s320/1erode2.PNG" alt="" id="BLOGGER_PHOTO_ID_5503734788549729794" border="0" /></a><br />1 x 2 ones:<br />dilation:<br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj6RiuLMOCf1vgPwC5iVs-aySnPuTgHlgu6eGrLGakAlEqtp_u_YQml5pNQzaFT0W9W0pBlIUNiqlZwuVkmXXChz85OWx7UXUAi6ZO9TCRVPQ5IURZp4jGIqaQpgcJorWeZObmujBR8thY/s1600/1dilate3.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 95px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj6RiuLMOCf1vgPwC5iVs-aySnPuTgHlgu6eGrLGakAlEqtp_u_YQml5pNQzaFT0W9W0pBlIUNiqlZwuVkmXXChz85OWx7UXUAi6ZO9TCRVPQ5IURZp4jGIqaQpgcJorWeZObmujBR8thY/s320/1dilate3.PNG" alt="" id="BLOGGER_PHOTO_ID_5503715310167111042" border="0" /></a>erosion:<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiX1fcByG2LH7U4je9MYXtM_ZbsJWR_n-ksLrXgEibSNqJw60cveF3G9X4Gao-vc7limzIL3J98bduTCqBE0zI6GGaQox10-1oFznY9lHCn-ftTmlPROFfVH6zqntStAXzFDMjOHPnFiuw/s1600/1erode3.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 108px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiX1fcByG2LH7U4je9MYXtM_ZbsJWR_n-ksLrXgEibSNqJw60cveF3G9X4Gao-vc7limzIL3J98bduTCqBE0zI6GGaQox10-1oFznY9lHCn-ftTmlPROFfVH6zqntStAXzFDMjOHPnFiuw/s320/1erode3.PNG" alt="" id="BLOGGER_PHOTO_ID_5503734792741968706" border="0" /></a><br /><br />cross:<br />dilation:<br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDhVwYMQsWBe3VGBdyTPCvK99C-0S7Uh03eogZhdaMA8slo7CqJr5B8TV0KMBWouUgPgpOqmgU-760ANVBWMj7Wk39h64MT1hUOsF2ODAPB9N2Q9VWidsnBuGiq9jS70VeBm5SPkCHKA0/s1600/1dilate4.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 93px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDhVwYMQsWBe3VGBdyTPCvK99C-0S7Uh03eogZhdaMA8slo7CqJr5B8TV0KMBWouUgPgpOqmgU-760ANVBWMj7Wk39h64MT1hUOsF2ODAPB9N2Q9VWidsnBuGiq9jS70VeBm5SPkCHKA0/s320/1dilate4.PNG" alt="" id="BLOGGER_PHOTO_ID_5503715321505783794" border="0" /></a>erosion:<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGW_RybzWkDU738KqOINSlSU33gJ63zlI-Q6WdddoCR_dq0r6cTmiWeegRmPx0u2Cu4B8SsGxKcyHZPwbb0LeSBzehB71eYTPdtY-HiOK3aeNzcl_qdGnPZGdKag3D6tSd1AlIF8gklTc/s1600/1erode4.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 106px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGW_RybzWkDU738KqOINSlSU33gJ63zlI-Q6WdddoCR_dq0r6cTmiWeegRmPx0u2Cu4B8SsGxKcyHZPwbb0LeSBzehB71eYTPdtY-HiOK3aeNzcl_qdGnPZGdKag3D6tSd1AlIF8gklTc/s320/1erode4.PNG" alt="" id="BLOGGER_PHOTO_ID_5503734799027028274" border="0" /></a><br /><br />diagonal line:<br />dilation:<br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhD0awgMsZCdY6PW2jz6Se7pInmOxY7C_WAgT3n4ZB_P1F6278yAnh2LmQT0QRX0g9flxPYr-8rHyxnVjlKE1N2-JCV5S3AT-TXarMW2xtRnvomMTm4P13C_xavIvicUccUCb_JlDeDqvc/s1600/1dilate5.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 99px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhD0awgMsZCdY6PW2jz6Se7pInmOxY7C_WAgT3n4ZB_P1F6278yAnh2LmQT0QRX0g9flxPYr-8rHyxnVjlKE1N2-JCV5S3AT-TXarMW2xtRnvomMTm4P13C_xavIvicUccUCb_JlDeDqvc/s320/1dilate5.PNG" alt="" id="BLOGGER_PHOTO_ID_5503715330736905010" border="0" /></a><br />erosion:<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJehKRRHmvA9buPj-avVEiC2F-bmDMM7pCfcMN__iY2ZjLkzJZGVNfcutu3SYfG3Z-9JgAJd1ERMvs1FYePSl-gcmbYS5Ex8cBUXOSP-9ECxrsfsH2gmCLKMRWtu6L8cNo1ucq0HAnEks/s1600/1erode5.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 111px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJehKRRHmvA9buPj-avVEiC2F-bmDMM7pCfcMN__iY2ZjLkzJZGVNfcutu3SYfG3Z-9JgAJd1ERMvs1FYePSl-gcmbYS5Ex8cBUXOSP-9ECxrsfsH2gmCLKMRWtu6L8cNo1ucq0HAnEks/s320/1erode5.PNG" alt="" id="BLOGGER_PHOTO_ID_5503734808196591666" border="0" /></a><br /><br /><br /><br /><span style="color: rgb(255, 0, 0);font-size:130%;" >Triangle</span> dilated/eroded by a, b, c, d and e:<br /><br />2 x 2 ones:<br />dilation:<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRD-HD32Qcm3jo609OWSDdz4rWs-idbMJtmfBl2ZAgRJC7NZUVjb2nuzjSSoDgHTrbqNz8XYncykx4Lb8FwXRM-k8nWSG36sCWA0UValpghX8yNT7F57fToiPdcXjFtydrrvNIvo-i9eY/s1600/2dilate1.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 88px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRD-HD32Qcm3jo609OWSDdz4rWs-idbMJtmfBl2ZAgRJC7NZUVjb2nuzjSSoDgHTrbqNz8XYncykx4Lb8FwXRM-k8nWSG36sCWA0UValpghX8yNT7F57fToiPdcXjFtydrrvNIvo-i9eY/s320/2dilate1.PNG" alt="" id="BLOGGER_PHOTO_ID_5503717343470820498" border="0" /></a><br />erosion:<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjR60DmkBRNGjCLtcSePpHaw-UxZ4jgL_m9H14lOZLxfCS3Mr50gahLiXz301GZC3YtIQObudUgVdF82u1m1iAvJ9LeT9rEvp1JLF4PcqegwKzYVYH61sbeu5qAARiW4U2EPa9Xo22IS-A/s1600/2erode1.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 85px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjR60DmkBRNGjCLtcSePpHaw-UxZ4jgL_m9H14lOZLxfCS3Mr50gahLiXz301GZC3YtIQObudUgVdF82u1m1iAvJ9LeT9rEvp1JLF4PcqegwKzYVYH61sbeu5qAARiW4U2EPa9Xo22IS-A/s320/2erode1.PNG" alt="" id="BLOGGER_PHOTO_ID_5503736457952983650" border="0" /></a><br /><br />2 x 1 ones:<br />dilation:<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgK64mV9nrNW4SXsQzmoY1WawHVIS1K7ijTxZWtYhXuDGYauGcN-rm8i9BqvRr9yskfiqNuxnrsTFFlBJeiHOsyrx_gqlI5NPUCGfDGjBZLep4Z9eX4KNWuYfJqztd2h78UqHXzsi4Q4S4/s1600/2dilate2.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 94px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgK64mV9nrNW4SXsQzmoY1WawHVIS1K7ijTxZWtYhXuDGYauGcN-rm8i9BqvRr9yskfiqNuxnrsTFFlBJeiHOsyrx_gqlI5NPUCGfDGjBZLep4Z9eX4KNWuYfJqztd2h78UqHXzsi4Q4S4/s320/2dilate2.PNG" alt="" id="BLOGGER_PHOTO_ID_5503717347733257250" border="0" /></a><br /><br />erosion:<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhHbwX6Il2SLbknW9Z7YEglQajHKRe2XozbEG-R8U9IxYdl6gdghjDULgLlb5YIJbVeYlVF380Gmngav0duxKpGsvedV7WCascPW7ipfIYdQY5jxfwFj2i3_y8Gpy0QVdGVaxnq-_9-kgo/s1600/2erode2.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 84px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhHbwX6Il2SLbknW9Z7YEglQajHKRe2XozbEG-R8U9IxYdl6gdghjDULgLlb5YIJbVeYlVF380Gmngav0duxKpGsvedV7WCascPW7ipfIYdQY5jxfwFj2i3_y8Gpy0QVdGVaxnq-_9-kgo/s320/2erode2.PNG" alt="" id="BLOGGER_PHOTO_ID_5503736462510749874" border="0" /></a><br /><br />1 x 2 ones:<br />dilation:<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgik3dYFPboRFQGQo9vnrSzyJIVi9Sihb3ejGR6yBTnUKfTbogQ0gCiBTc-Rw3eOQJjqbcdvtiG-MPjLbk7ewhWvrHTMrFjx3KY5zAme0JHaRxAMP3Ig5NsS91p4ptnTu1u27t6nVPF9mQ/s1600/2dilate3.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 88px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgik3dYFPboRFQGQo9vnrSzyJIVi9Sihb3ejGR6yBTnUKfTbogQ0gCiBTc-Rw3eOQJjqbcdvtiG-MPjLbk7ewhWvrHTMrFjx3KY5zAme0JHaRxAMP3Ig5NsS91p4ptnTu1u27t6nVPF9mQ/s320/2dilate3.PNG" alt="" id="BLOGGER_PHOTO_ID_5503717354585185090" border="0" /></a><br /><br />erosion:<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjnGPAG3hkUb-QEAfJCKRePpNLtVhIyPw7aIyQjoboGY2Orw8XlWsYfPKzjNudBAwsL04CR2o-5HM5u0rkCC80G03xO2AyKVd8gX43HRDumhjIkJ4KjE8xqHkrYvmZxH918ROBsJ52qIpY/s1600/2erode3.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 95px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjnGPAG3hkUb-QEAfJCKRePpNLtVhIyPw7aIyQjoboGY2Orw8XlWsYfPKzjNudBAwsL04CR2o-5HM5u0rkCC80G03xO2AyKVd8gX43HRDumhjIkJ4KjE8xqHkrYvmZxH918ROBsJ52qIpY/s320/2erode3.PNG" alt="" id="BLOGGER_PHOTO_ID_5503736474931699474" border="0" /></a><br /><br />cross:<br />dilation:<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkUf2JsjHSrE2rwVKszpiHSLQSCE75hgEEZ8AfCoLNG2QNv6I2uHhudKFqkpSE3eTrr05IJ4DySKK69AZkdPuBUFU3zuLXRDWqoxIXmMmUtUUg4hWolYgZHrcd8Ccz_oJLhWQ2-mkPmvw/s1600/2dilate4.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 82px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkUf2JsjHSrE2rwVKszpiHSLQSCE75hgEEZ8AfCoLNG2QNv6I2uHhudKFqkpSE3eTrr05IJ4DySKK69AZkdPuBUFU3zuLXRDWqoxIXmMmUtUUg4hWolYgZHrcd8Ccz_oJLhWQ2-mkPmvw/s320/2dilate4.PNG" alt="" id="BLOGGER_PHOTO_ID_5503717363433120706" border="0" /></a><br />erosion:<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHNDhLHORnPUyQgnVCj6ymOa0-lP9aJTziBsNl4lraLYSnH-B69x5HGqk1zpSk3nNXmup6LMn5b-ZG6J7Hphj7TtIlYJMk8wxxwaWwY3lzV7x3vXmYgNMBAPFJIiAC1UgBv8ZXFvTZZKE/s1600/2erode4.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 94px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHNDhLHORnPUyQgnVCj6ymOa0-lP9aJTziBsNl4lraLYSnH-B69x5HGqk1zpSk3nNXmup6LMn5b-ZG6J7Hphj7TtIlYJMk8wxxwaWwY3lzV7x3vXmYgNMBAPFJIiAC1UgBv8ZXFvTZZKE/s320/2erode4.PNG" alt="" id="BLOGGER_PHOTO_ID_5503736477602333906" border="0" /></a><br /><br />diagonal line:<br />dilation:<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjbh05lPLktdEyO4Mh49Dfm-Vr2KXU_ZNPbvr_URQLNx1SGMRwKsNeedv9hHYjeLSZcxU0t4SmyBZ69z7GUbJigI0L2OanPJ-2IeUGWNOwFekqvGQyu-ktuRPGlWrwVIomlpmoL0pXaWpc/s1600/2dilate5.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 90px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjbh05lPLktdEyO4Mh49Dfm-Vr2KXU_ZNPbvr_URQLNx1SGMRwKsNeedv9hHYjeLSZcxU0t4SmyBZ69z7GUbJigI0L2OanPJ-2IeUGWNOwFekqvGQyu-ktuRPGlWrwVIomlpmoL0pXaWpc/s320/2dilate5.PNG" alt="" id="BLOGGER_PHOTO_ID_5503717375139784338" border="0" /></a><br />erosion:<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3Igf3ELefxAGORLE_ekR4tPnEd1MJ1DOUx2UcIDvWyi3BoR89XNwwxLuborE3kM5GmL_3FaKVxtzGhZgP-_SgUwu9LlKkCKYck-OS33QcOMBJyEyRSq4RERwsqC24VoxvqfeYT5Tn7Zw/s1600/2erode5.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 96px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3Igf3ELefxAGORLE_ekR4tPnEd1MJ1DOUx2UcIDvWyi3BoR89XNwwxLuborE3kM5GmL_3FaKVxtzGhZgP-_SgUwu9LlKkCKYck-OS33QcOMBJyEyRSq4RERwsqC24VoxvqfeYT5Tn7Zw/s320/2erode5.PNG" alt="" id="BLOGGER_PHOTO_ID_5503736483552054322" border="0" /></a><br /><br /><span style="color: rgb(255, 0, 0);font-size:130%;" >Hollow 10 x 10 square</span> dilated/eroded by a, b, c, d and e:<br /><br />2 x 2 ones:<br />dilation:<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEizbhkutEhOrs4YIUS8SuAmSmo41PFEphhCPjTMXOMya7VJMRC0a8X4qk5JHZtBFYiT9FlkmyV_iDLmLiF_mzf-zwqEUmCRxzKwMXvbmgVcfWhOfcK7cuiKBXnqyG3S171nbKuV5F4M7pU/s1600/3dilate1.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 110px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEizbhkutEhOrs4YIUS8SuAmSmo41PFEphhCPjTMXOMya7VJMRC0a8X4qk5JHZtBFYiT9FlkmyV_iDLmLiF_mzf-zwqEUmCRxzKwMXvbmgVcfWhOfcK7cuiKBXnqyG3S171nbKuV5F4M7pU/s320/3dilate1.PNG" alt="" id="BLOGGER_PHOTO_ID_5503725538894778162" border="0" /></a><br />erosion:<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhla9FO3KinebCW_LJGiKdzCbW3VbgMfrSurJTc4oBS_JGo0tXWSsl6Dw5s0IVkmemLfsbz7cEQ6i968vj8f09cFwSlTSM8JpCgcEmu0-c-87Bbhi9kU7ki68ByJYU874PskS-8xwwRIBs/s1600/3erode1.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 99px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhla9FO3KinebCW_LJGiKdzCbW3VbgMfrSurJTc4oBS_JGo0tXWSsl6Dw5s0IVkmemLfsbz7cEQ6i968vj8f09cFwSlTSM8JpCgcEmu0-c-87Bbhi9kU7ki68ByJYU874PskS-8xwwRIBs/s320/3erode1.PNG" alt="" id="BLOGGER_PHOTO_ID_5503740536135842002" border="0" /></a><br /><br />2 x 1 ones:<br />dilation:<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBNhYNkPg8kYYL-ANqDC3E4m5ciOGnZvTepQQ8muh8Wl66uVobM-nbUWsubqNhKDGI6166hy0PNFXvvS6huL6njhNb0vpbB8C0X4ZGjPy-42j6YKiwI5l7JWIi37G6eXLlbNp9SxewGK4/s1600/3dilate2.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 106px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBNhYNkPg8kYYL-ANqDC3E4m5ciOGnZvTepQQ8muh8Wl66uVobM-nbUWsubqNhKDGI6166hy0PNFXvvS6huL6njhNb0vpbB8C0X4ZGjPy-42j6YKiwI5l7JWIi37G6eXLlbNp9SxewGK4/s320/3dilate2.PNG" alt="" id="BLOGGER_PHOTO_ID_5503725549583080962" border="0" /></a><br />erosion:<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhle4dz27Zbl7jngjJwP0IyX-nHkiShMFtfC5ThfBg_-7YptJxgSkTFaKpLAMwSjds6XPOK0LxyuIUoTYieY34ymaQNWg4Eudp7H8yNukgnfY5hswiu3P7Otx4N0xzlAJ0nl4HJnpw8kVI/s1600/3erode2.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 98px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhle4dz27Zbl7jngjJwP0IyX-nHkiShMFtfC5ThfBg_-7YptJxgSkTFaKpLAMwSjds6XPOK0LxyuIUoTYieY34ymaQNWg4Eudp7H8yNukgnfY5hswiu3P7Otx4N0xzlAJ0nl4HJnpw8kVI/s320/3erode2.PNG" alt="" id="BLOGGER_PHOTO_ID_5503740544856226178" border="0" /></a><br /><br />1 x 2 ones:<br />dilation:<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZI1QRnh63K0sGBL6n04FgAL4Oc2VnOG20HoKnSMZ3hun1aS4abLLcM23LEl_GG4mJ0hZYin2bkU1dXEznJJ4iTsfa7hgxMZKcaI85yKdlcOdScOPY2P5p_MaB9OaQ4n7gKN6MN4ZoiSc/s1600/3dilate3.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 104px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZI1QRnh63K0sGBL6n04FgAL4Oc2VnOG20HoKnSMZ3hun1aS4abLLcM23LEl_GG4mJ0hZYin2bkU1dXEznJJ4iTsfa7hgxMZKcaI85yKdlcOdScOPY2P5p_MaB9OaQ4n7gKN6MN4ZoiSc/s320/3dilate3.PNG" alt="" id="BLOGGER_PHOTO_ID_5503725570200667906" border="0" /></a><br />erosion:<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwIADK0miqwcsDH6SdiONMATNZBHkvNqzL8Tr2RnSctcesc7QH1Bl7xdoA4C4QCN_bFemor9kic6wE3xXMLc5qmcRm54mXf7tHp712k2uoSZlVbKxgUp2Wrp_VVfLvNnMrRwxTWwehJ0E/s1600/3erode3.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 107px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwIADK0miqwcsDH6SdiONMATNZBHkvNqzL8Tr2RnSctcesc7QH1Bl7xdoA4C4QCN_bFemor9kic6wE3xXMLc5qmcRm54mXf7tHp712k2uoSZlVbKxgUp2Wrp_VVfLvNnMrRwxTWwehJ0E/s320/3erode3.PNG" alt="" id="BLOGGER_PHOTO_ID_5503740550405691906" border="0" /></a><br /><br />cross:<br />dilation:<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7qAMK8JmX4Cj-SDi2OCenvGgxTNryCI4QJK7pQ2gQgU1AOHTj6NqpFC7fd5oQCofhMFIhkWVBUsMu_dMVLUoc1j3aGNwYyjJ8JmzCKq4wIuS-V_nhKaNI2T_BrGmN2Fvg6d4TPo1xvys/s1600/3dilate4.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 107px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7qAMK8JmX4Cj-SDi2OCenvGgxTNryCI4QJK7pQ2gQgU1AOHTj6NqpFC7fd5oQCofhMFIhkWVBUsMu_dMVLUoc1j3aGNwYyjJ8JmzCKq4wIuS-V_nhKaNI2T_BrGmN2Fvg6d4TPo1xvys/s320/3dilate4.PNG" alt="" id="BLOGGER_PHOTO_ID_5503725577683532754" border="0" /></a><br />erosion:<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEghhZ5QKTxLIVdHsmd4CAcAHWCLgBG2zguzp9Vvd_8XCkFJjkIO44otSJgIbdGSlTFAdlOPbKP3hGxCT7DrFEG3ag6mtC13l5uM97X0Zv6TQs-OSNZCoWGGq8ljTAmW_Ni6C7b4WaGvbCw/s1600/3erode4.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 100px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEghhZ5QKTxLIVdHsmd4CAcAHWCLgBG2zguzp9Vvd_8XCkFJjkIO44otSJgIbdGSlTFAdlOPbKP3hGxCT7DrFEG3ag6mtC13l5uM97X0Zv6TQs-OSNZCoWGGq8ljTAmW_Ni6C7b4WaGvbCw/s320/3erode4.PNG" alt="" id="BLOGGER_PHOTO_ID_5503740555437949954" border="0" /></a><br /><br />diagonal line:<br />dilation:<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihus6AJTvxftDeicVnYx24_hsOk_RguRvYYTbgMzEOHpfWiNGobZDCtL0gTKagBm8eKQ7Fj5pGWDWaKAXS41cFJZQUwGoLHtI5RiX34o6PwNahcrclkusKyYZqmyFbtojhihtfsPFSMG4/s1600/3dilate5.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 117px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihus6AJTvxftDeicVnYx24_hsOk_RguRvYYTbgMzEOHpfWiNGobZDCtL0gTKagBm8eKQ7Fj5pGWDWaKAXS41cFJZQUwGoLHtI5RiX34o6PwNahcrclkusKyYZqmyFbtojhihtfsPFSMG4/s320/3dilate5.PNG" alt="" id="BLOGGER_PHOTO_ID_5503725590836344082" border="0" /></a><br /><br />erosion:<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjORKn6-b7KVLT1iDiyIxRm0L_qaZ5jgns_Q2uZ8DCslKAMu-TjlnZJXbqDtUGxA-F0RoWJR3iNstcV8IACXbZ3A5imeyvVjaLqQygneq9RvLzwTF2Kgvc8nAZSz1CdZz5tOscQWUF1MPQ/s1600/3erode5.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 110px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjORKn6-b7KVLT1iDiyIxRm0L_qaZ5jgns_Q2uZ8DCslKAMu-TjlnZJXbqDtUGxA-F0RoWJR3iNstcV8IACXbZ3A5imeyvVjaLqQygneq9RvLzwTF2Kgvc8nAZSz1CdZz5tOscQWUF1MPQ/s320/3erode5.PNG" alt="" id="BLOGGER_PHOTO_ID_5503740564202936354" border="0" /></a><br /><br /><br /><span style="color: rgb(255, 0, 0);font-size:130%;" >Plus sign</span> dilated/eroded by a, b, c, d and e:<br /><br />2 x 2 ones:<br />dilation:<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWobC5ZPz6XFDoTc1EYHTrXmiE4LQoWyw5lrYZZJ-O_Qeu39swZ_yXE5zvpzJjboeIEQt10ONnFRpoPoBVSMFnkfyzMEYXTjMUotirZVCDIupZmRjVtmoa_mbYE3OUfL_lRu5hyCFoQj0/s1600/4dilate1.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 103px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWobC5ZPz6XFDoTc1EYHTrXmiE4LQoWyw5lrYZZJ-O_Qeu39swZ_yXE5zvpzJjboeIEQt10ONnFRpoPoBVSMFnkfyzMEYXTjMUotirZVCDIupZmRjVtmoa_mbYE3OUfL_lRu5hyCFoQj0/s320/4dilate1.PNG" alt="" id="BLOGGER_PHOTO_ID_5503727116661177554" border="0" /></a><br />erosion:<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGD7EMl_0xtW2sg5UW0J66EpddkgTmUuvvt27UmHEqxsHa2ySodbyZnpfAyg6TCK8w79YU2lGwOIvisXfOpLBlbE_f5IWxu6uwdnyehDXmKEnutsF09Sbx3vcxX_pth7hUyDuFlPXGans/s1600/4erode1.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 93px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGD7EMl_0xtW2sg5UW0J66EpddkgTmUuvvt27UmHEqxsHa2ySodbyZnpfAyg6TCK8w79YU2lGwOIvisXfOpLBlbE_f5IWxu6uwdnyehDXmKEnutsF09Sbx3vcxX_pth7hUyDuFlPXGans/s320/4erode1.PNG" alt="" id="BLOGGER_PHOTO_ID_5503742889198772802" border="0" /></a><br /><br />2 x 1 ones:<br />dilation:<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh65Q_kksvCGTgyr4gqpk9E2uMbG3kXVzPlLFA0a8i7qW_6Z4xrBsCnUnHtPOlaYxreRzEH3tsUW0SxF_n6LClsga059EN6qUWpUveNzV9IuJrjuJtMAhtjLj4qwtAlPRBjy2AzLH144o8/s1600/4dilate2.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 101px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh65Q_kksvCGTgyr4gqpk9E2uMbG3kXVzPlLFA0a8i7qW_6Z4xrBsCnUnHtPOlaYxreRzEH3tsUW0SxF_n6LClsga059EN6qUWpUveNzV9IuJrjuJtMAhtjLj4qwtAlPRBjy2AzLH144o8/s320/4dilate2.PNG" alt="" id="BLOGGER_PHOTO_ID_5503727121936045202" border="0" /></a><br />erosion:<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiaD0q_GACq9tkI_Z8t7dFMslfNFF8iLRcOLn8rVbPploWYs9OUI2499UxEv35M35bgN9lLmNCoo8QbhIG-IReUoa1BOaOXjl9Sjob7VIwwaXsXJg4Ns7SUXbbRtPbbFV0fjUd95lkZPQQ/s1600/4erode2.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 102px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiaD0q_GACq9tkI_Z8t7dFMslfNFF8iLRcOLn8rVbPploWYs9OUI2499UxEv35M35bgN9lLmNCoo8QbhIG-IReUoa1BOaOXjl9Sjob7VIwwaXsXJg4Ns7SUXbbRtPbbFV0fjUd95lkZPQQ/s320/4erode2.PNG" alt="" id="BLOGGER_PHOTO_ID_5503742894780806930" border="0" /></a><br /><br />1 x 2 ones:<br />dilation:<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhBSeGcbgOyoMC0NCu705Sl9l0OhYMcaqDJ-o_lyyhDXNIwxfSHo5tShaJuIZpJNJSYrS_63LnTTrrTTvNNkEDSEU2v6oAGpcW93SMQjiIG9G29unzPjVds1ce8lW-HeNmTmBB7Qh_bA3U/s1600/4dilate3.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 103px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhBSeGcbgOyoMC0NCu705Sl9l0OhYMcaqDJ-o_lyyhDXNIwxfSHo5tShaJuIZpJNJSYrS_63LnTTrrTTvNNkEDSEU2v6oAGpcW93SMQjiIG9G29unzPjVds1ce8lW-HeNmTmBB7Qh_bA3U/s320/4dilate3.PNG" alt="" id="BLOGGER_PHOTO_ID_5503727136259075890" border="0" /></a><br />erosion:<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8gb8G62R7whKX1jrhivqe-s_gDd5UBKkV9Rj4-9pyWrNBS8WDmohoODYJpO78qc6sOfMBLfEzO3qmNiXSkA_Y8PL6_y-22fVhAGJDlS6ntyDyItJBRXLtePHx1Bd7yltzddITmKsBHao/s1600/4erode3.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 100px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8gb8G62R7whKX1jrhivqe-s_gDd5UBKkV9Rj4-9pyWrNBS8WDmohoODYJpO78qc6sOfMBLfEzO3qmNiXSkA_Y8PL6_y-22fVhAGJDlS6ntyDyItJBRXLtePHx1Bd7yltzddITmKsBHao/s320/4erode3.PNG" alt="" id="BLOGGER_PHOTO_ID_5503742903959908850" border="0" /></a><br /><br />cross:<br />dilation:<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-ax4xI3Lg68XBAqLYVjkSRbAaoLRI_rWddUBykwYhLnNkzBQlhCM5z48EraxGhQDUAvPe-6XwyLQzcWfhX8RSnI2I6V2z7Df6By1QQRezZUBA_ffgquNOeBnt0GG-KGkp2SIih5JfFoM/s1600/4dilate4.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 96px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-ax4xI3Lg68XBAqLYVjkSRbAaoLRI_rWddUBykwYhLnNkzBQlhCM5z48EraxGhQDUAvPe-6XwyLQzcWfhX8RSnI2I6V2z7Df6By1QQRezZUBA_ffgquNOeBnt0GG-KGkp2SIih5JfFoM/s320/4dilate4.PNG" alt="" id="BLOGGER_PHOTO_ID_5503727140383815314" border="0" /></a><br />erosion:<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9sJ3PnZ_M9NmhmmlCqTxnUbxARQqyNUxvw-rJLueEv8GGcrdi4-1abhWMOwrLwbWisZ_TpkPtaHl9yfN1S9oDkPQ9OinyeCzq4mjemWXI8u5CPiN0zfgTKP7A9-KBVZPIIS8SkEKz4kI/s1600/4erode4.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 95px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9sJ3PnZ_M9NmhmmlCqTxnUbxARQqyNUxvw-rJLueEv8GGcrdi4-1abhWMOwrLwbWisZ_TpkPtaHl9yfN1S9oDkPQ9OinyeCzq4mjemWXI8u5CPiN0zfgTKP7A9-KBVZPIIS8SkEKz4kI/s320/4erode4.PNG" alt="" id="BLOGGER_PHOTO_ID_5503742909864524610" border="0" /></a><br /><br />diagonal line:<br />dilation:<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEig2RErrDA_talp7_MpJ9I4aiUt7mSwsOoIF8YUh2M1cfDX2XFaIl3j4l6XxbqNFBf9lJDXSuBdzSKYKBrnhu8PeE98MkDIUWE375ATOKov4HV1vnzEfoGKSYp4FqB-3_-vTQBFQpY2_mo/s1600/4dilate5.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 101px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEig2RErrDA_talp7_MpJ9I4aiUt7mSwsOoIF8YUh2M1cfDX2XFaIl3j4l6XxbqNFBf9lJDXSuBdzSKYKBrnhu8PeE98MkDIUWE375ATOKov4HV1vnzEfoGKSYp4FqB-3_-vTQBFQpY2_mo/s320/4dilate5.PNG" alt="" id="BLOGGER_PHOTO_ID_5503727150273855490" border="0" /></a><br />erosion:<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHHbCYYLOS7ZpR7N_U_msQjbPVVTunB0OSBXXUY7DY7ABKiRdk2wdJDHplk2i6-G8n76OEL5t3rAsQF-p6e3o8hWfTNuw8TDFHMA64vs5dNnivl1eAk0gs8pp7igkcJqxpaRUgONRhc24/s1600/4erode5.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 107px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHHbCYYLOS7ZpR7N_U_msQjbPVVTunB0OSBXXUY7DY7ABKiRdk2wdJDHplk2i6-G8n76OEL5t3rAsQF-p6e3o8hWfTNuw8TDFHMA64vs5dNnivl1eAk0gs8pp7igkcJqxpaRUgONRhc24/s320/4erode5.PNG" alt="" id="BLOGGER_PHOTO_ID_5503742919754982178" border="0" /></a><br /><br />As seen, the predictions match the outcomes from scilab. Yay! :D<br /><br />Next, we explore other morphological operations available in scilab such as thin and skel:<br /><br />The "thin" function utilizes the Zhang-Suen technique. Compared to the "skel" function, the output of the thin are not always connected. The Zhang Suen technique contains two sub-iterations, and it removes pixels if those pixels satisfy conditions such as connectivity, number of neighbors and the configuration of certain neighbors (on or off). The output of the "thin" function is an internal skeleton of the image which is capable of representing the shape and orientation of the original. It deletes the border of the image. As seen in the figure below, the sample image is "thinned" indeed.<br /><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMCpMOdir7GzaFbxETdQXNyKQOYx8ScXlBsYEW301gDP187j0OKP-X-tX0Mh2YGjUhvuyx4PxmPntfpjoffYYMbYnJ6x41lg5nVR0Zdcf8rqgYnwEXePJCPaTD49EOEc6lR-v0MUzcxl4/s1600/thin.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 240px; height: 153px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMCpMOdir7GzaFbxETdQXNyKQOYx8ScXlBsYEW301gDP187j0OKP-X-tX0Mh2YGjUhvuyx4PxmPntfpjoffYYMbYnJ6x41lg5nVR0Zdcf8rqgYnwEXePJCPaTD49EOEc6lR-v0MUzcxl4/s320/thin.PNG" alt="" id="BLOGGER_PHOTO_ID_5503794527412545026" border="0" /></a>Sample image (left) and the result after "thinning" (right)<br /></div><br />"skel" on the other hand, outputs three matrices (for scilab) - the grayscale skeleton image, the Euclidean distance transform of the image, and the discrete Voronoi Diagram of the boundary pixels. Thresholding can be applied to the grayscale skeleton system in order to get the binary skeleton of variable thickness depending on the threshold. The "skel" function is somewhat like a subset or a special case of "thinning" since getting the skeleton of an image involves thinning it down. And as mentioned earlier, the "skel" function will produce a connected skeleton.<br /><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjx9d8YTQTXfO6HvrZmT4zz9s7AQ8VrXn0IJbnCiOYiscUfO1qNtMjzZAamql9w8zz4JvKUm-V1zfRUGbG9Gn7Fj8nEIE1m7NpeAVLnGs_RrSoT0ucVe18yIJSE96idGuzX08a5PxLQHQ/s1600/skel.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 92px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjx9d8YTQTXfO6HvrZmT4zz9s7AQ8VrXn0IJbnCiOYiscUfO1qNtMjzZAamql9w8zz4JvKUm-V1zfRUGbG9Gn7Fj8nEIE1m7NpeAVLnGs_RrSoT0ucVe18yIJSE96idGuzX08a5PxLQHQ/s320/skel.PNG" alt="" id="BLOGGER_PHOTO_ID_5503794532363272242" border="0" /></a>from left to right: sample image, its grayscale skeleton image, euclidean distance transform image, and its discrete Voronoi diagram.<br /><br /><div style="text-align: left;"><br />Finally, I give myself a score of 10/10 for understanding the lesson and being able to (accurately) predict the dilation/erosion of the images as well as produce the required output.<br /><br /><span style="font-weight: bold;">Score: 10/10</span><br /><br />Lastly, I would like to acknowledge Dr. Soriano, Cheryl Abundo, Arvin Mabilangan, and BA Racoma for the insightful discussions that made me understand more about the techniques. :D<br /><br />- Dennis<br /></div></div><br />References:<br />1. M. Soriano, "Morphological Operations"<br />2. http://www.rupj.net/portfolio/docs/skeletonization.pdf<br />3. http://www.mathworks.com/access/helpdesk/help/toolbox/images/bwmorph.html<br /><br />Appendix: (Code, note, some semi colons are removed because it messes with the formatting)<br /><br /><br />// Square<br />nx = 9; ny = 9; //defines the number of elements along x and y<br /><br />x = linspace(1,9,nx); //defines the range<br />y = linspace(1,9,ny);<br />[X,Y] = ndgrid(x,y); //creates two 2-D arrays of x and y coordinates<br /><br />A = ones(nx,ny);<br />A(find(X<3))>7)) = 0;<br />A(find(Y<3))>7)) = 0;<br />// Triangle<br />nx = 5; ny = 6; //defines the number of elements along x and y<br /><br />x = linspace(1,5,nx); //defines the range<br />y = linspace(1,6,ny);<br />[X,Y] = ndgrid(x,y); //creates two 2-D arrays of x and y coordinates<br /><br />A = zeros(nx, ny);<br />A(find(X>3)) = 1;<br />A(2, 5) = 1;<br />A(3, 4) = 1;<br />A(3, 5) = 1;<br />A(find(X>4)) = 0;<br />A(find(Y<2))>5)) = 0;<br />// Hollow 10x10 square<br />nx = 14; ny = 14; //defines the number of elements along x and y<br /><br />x = linspace(1,nx,nx); //defines the range<br />y = linspace(1,nx,ny);<br />[X,Y] = ndgrid(x,y); //creates two 2-D arrays of x and y coordinates<br /><br />A = zeros(nx, ny);<br />A(find(X<5))>10)) = 1;<br />A(find(Y<5))>10)) = 1;<br />A(find(X>12)) = 0;<br />A(find(X<3))>12)) = 0;<br />A(find(Y<3)) nx =" 9;" ny =" 9;" x =" linspace(1,nx,nx);" y =" linspace(1,nx,ny);" a =" ones(nx,">5)) = 0;<br />A(find(X<5)) = 0;<br />A(3, 5) = 1;<br />A(4, 5) = 1;<br />A(6, 5) = 1;<br />A(7, 5) = 1;<br />A(5, 1) = 0;<br />A(5, 2) = 0;<br />A(5, 1) = 0;<br />A(5, 9) = 0;<br />A(5, 8) = 0;<br /><br /><br /><br />scf();<br />imshow(A,[]);<br />2x2<br />SE = [1 1; 1 1];<br /><br /><br />2x1<br />SE = [1; 1];<br /><br /><br /><br />1x2<br />SE = [1 1];<br /><br /><br /><br /><br />cross<br />SE = [0 1 0; 1 1 1; 0 1 0];<br /><br /><br /><br /><br />diagonal<br />SE = [0 1; 1 0];<br /><br /><br />R2 = erode(A, SE, [2, 1]);<br />R1 = dilate(A, SE, [2, 1]);<br />scf();<br />imshow(R1, []);<br /><br />scf();<br />imshow(R2, []);<br /><br />R3 = thin(A);<br /><br />scf();<br />imshow(R3, []);<br /><br />[R4, R5, R6] = skel(A);<br />scf();<br />imshow(R4, []);<br /><br />scf();<br />imshow(R5, []);<br /><br />scf();<br />imshow(R6, []);dennisivan89http://www.blogger.com/profile/04476991777095665795noreply@blogger.com0tag:blogger.com,1999:blog-7345763871585817117.post-81558024679404112552010-07-29T01:27:00.000-07:002010-09-23T08:49:33.187-07:00AP 186 Act8 - Enhancement in the Frequency DomainThis activity is mostly about applying what we've learned in the last two activities about Fourier Transforms (FT). We'll be applying the techniques to images, making them of better quality. :D<br /><br />Part A. Convolution Theorem<br />For this part we're first asked to make certain patterns and take their FT's.<br /><br />Two dots along x-axis symmetric about the center:<br /><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi7XCIZ-atVkfI46Oc0CCynvuF5wN7RO1VxlheYg4o6Ss27sQ99eQzLSUMbYyR8U0U1Wh5SaEv51LjzPe3brkrkFnpXYaRyKhvc-7OEbYN9JQihkowOlGsTov5AtomSxlD0inIQg1iFvhY/s1600/two+dots.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 152px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi7XCIZ-atVkfI46Oc0CCynvuF5wN7RO1VxlheYg4o6Ss27sQ99eQzLSUMbYyR8U0U1Wh5SaEv51LjzPe3brkrkFnpXYaRyKhvc-7OEbYN9JQihkowOlGsTov5AtomSxlD0inIQg1iFvhY/s320/two+dots.PNG" alt="" id="BLOGGER_PHOTO_ID_5499298051246037378" border="0" /></a>pattern (left) and its FT (right).<br /></div><br />Two circles along x-axis symmetric about the center:<br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjoHxvFUNtLHAjMTN9mjIZS6p3ZbKjIMq2N3oWKiftX6gtGK0U7ZEgysEeVQ_vE1vngi6cjPWNgp-6dpWbXFOWk-qmEbXZc6G7TcB7qc_p6ApTvcs3zXTuLShZdFixPq9Rgw9A1fgJIjyc/s1600/two+dots+2.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 153px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjoHxvFUNtLHAjMTN9mjIZS6p3ZbKjIMq2N3oWKiftX6gtGK0U7ZEgysEeVQ_vE1vngi6cjPWNgp-6dpWbXFOWk-qmEbXZc6G7TcB7qc_p6ApTvcs3zXTuLShZdFixPq9Rgw9A1fgJIjyc/s320/two+dots+2.PNG" alt="" id="BLOGGER_PHOTO_ID_5499298057619106338" border="0" /></a>Increasing the radius...<br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiUaATki7yPnX2l04E0dOOhTxerY5EVGC9KqNofsmtbif5hP4AEq24tz3xpFE3Sno7wwienmazIDA_4COVix4jKhgL-pwxOKgpkramxwpne5blylEg4o8PZMz4FwqA681jP88hQ3tTggiM/s1600/two+dots+3.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 153px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiUaATki7yPnX2l04E0dOOhTxerY5EVGC9KqNofsmtbif5hP4AEq24tz3xpFE3Sno7wwienmazIDA_4COVix4jKhgL-pwxOKgpkramxwpne5blylEg4o8PZMz4FwqA681jP88hQ3tTggiM/s320/two+dots+3.PNG" alt="" id="BLOGGER_PHOTO_ID_5499298060952838018" border="0" /></a><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjR2PhQlGNDKEnwpnlylGuArxdyi6kIju2iV0QlEW_S_2p_KZc7ekC9WR5RDMKRaj0mcWZztiFT2-hQr8PEJgnApgaEuGHIGwnTvw8QMcqHocQmEHK__yULOXFCpTfNcPnrfhWGvzHVZCY/s1600/two+dots+4.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 152px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjR2PhQlGNDKEnwpnlylGuArxdyi6kIju2iV0QlEW_S_2p_KZc7ekC9WR5RDMKRaj0mcWZztiFT2-hQr8PEJgnApgaEuGHIGwnTvw8QMcqHocQmEHK__yULOXFCpTfNcPnrfhWGvzHVZCY/s320/two+dots+4.PNG" alt="" id="BLOGGER_PHOTO_ID_5499298067122090242" border="0" /></a><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjag8yEXI_vnknw0LZWfkw5DnkCAIqEUvC61OysekXPy48ANZNMXz0F29Dk7cunwdkp6Az1Qg54VSstjF2j6o2JA7Et_7HHEE_OxU1e70q6wsULZ0zjzCecX59wd48BEc1a78HBgWncMz8/s1600/two+dots+5.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 154px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjag8yEXI_vnknw0LZWfkw5DnkCAIqEUvC61OysekXPy48ANZNMXz0F29Dk7cunwdkp6Az1Qg54VSstjF2j6o2JA7Et_7HHEE_OxU1e70q6wsULZ0zjzCecX59wd48BEc1a78HBgWncMz8/s320/two+dots+5.PNG" alt="" id="BLOGGER_PHOTO_ID_5499298071707289682" border="0" /></a><br />Note that by just adding a small finite radius to the dots, the FT immediately changes such that it is now a combination of an Airy disk with a sinusoid running along x-axis. This is because the FT of two peaks symmetric along the x-axis is a sinusoid while the FT of a circle is the Airy disk. The pattern is a convolution of the two peaks with the circle. Therefore, the FT modulus seen is a product of the sinusoid with the Airy disk. Furthermore, as we increase the radius of the dots, the Airy disk becomes smaller and smaller.<br /><br />Two squares along x-axis symmetric about the center:<br /><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqG_ECXiFkMkc_4HjB-I45k6OwFsrPfOHGwkVa7z2KzaOUYj7Xr4tJiqERip6dRDDV6v8S6M9JVQkSvmNxx1lnFUCHWaXxYKoB_e6gEMimRPLk6-GKkzafrt4AyXAUNg3f3Q1D8KlGMz8/s1600/two+squares+1.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 151px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqG_ECXiFkMkc_4HjB-I45k6OwFsrPfOHGwkVa7z2KzaOUYj7Xr4tJiqERip6dRDDV6v8S6M9JVQkSvmNxx1lnFUCHWaXxYKoB_e6gEMimRPLk6-GKkzafrt4AyXAUNg3f3Q1D8KlGMz8/s320/two+squares+1.PNG" alt="" id="BLOGGER_PHOTO_ID_5499299912407452418" border="0" /></a>pattern (left) and its FT (right).<br /><br /></div>Increasing the width...<br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhb1E_gNavne63pyVMWnEp07tXo368nHxgALsvTLhIc-ojp5zdnL5UOdaxdC2J48ZMz2wSxHduSdVIDBLjRc3G9aIWpWtkvnKzg7Fz42wLOBspCY-15DG7E4dLkTw6wNDylOt6VFXuIcR0/s1600/two+squares+1.5.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 154px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhb1E_gNavne63pyVMWnEp07tXo368nHxgALsvTLhIc-ojp5zdnL5UOdaxdC2J48ZMz2wSxHduSdVIDBLjRc3G9aIWpWtkvnKzg7Fz42wLOBspCY-15DG7E4dLkTw6wNDylOt6VFXuIcR0/s320/two+squares+1.5.PNG" alt="" id="BLOGGER_PHOTO_ID_5499299916047268386" border="0" /></a><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJs1sv_5VYqTCYP5j-P1JS8X0gu5Xf2UfImg1_UxeWh6nNMNR_oUQ0gVqqdWbbfevp043Rg5av_AbEbtj5x8cPkDNqhymfURXumWl5XKy22QW9CJXP6gZcv_zLfeaIGIy1I_AvWtQ_v_0/s1600/two+squares+2.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 152px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJs1sv_5VYqTCYP5j-P1JS8X0gu5Xf2UfImg1_UxeWh6nNMNR_oUQ0gVqqdWbbfevp043Rg5av_AbEbtj5x8cPkDNqhymfURXumWl5XKy22QW9CJXP6gZcv_zLfeaIGIy1I_AvWtQ_v_0/s320/two+squares+2.PNG" alt="" id="BLOGGER_PHOTO_ID_5499299922256303490" border="0" /></a><br />This pattern is again a convolution of two dirac delta's or peaks with a square aperture. Therefore, the FT modulus should be the product of a sinusoid with the cross-like rectangular patterns (FT of square aperture) and this is what we got. Increasing the width of the squares would make the rectangular pattern smaller (a property of FT's).<br /><br />Two gaussians along x-axis symmetric about the center:<br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgIwrEI5Y3L2WSdNOhrSv1KPAmFlhFf0PYFoZ9eoaogwKcL08PSvuhrMDG4DaEV8RPSPsTvSQK5hsmEAiq3SJWGhvhGHRDrPp6mDHM4B0-w_y7qSkKQ9ETNJksguxyRPwYUAZmj-8haj7Q/s1600/two+gaussian+0.5.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 153px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgIwrEI5Y3L2WSdNOhrSv1KPAmFlhFf0PYFoZ9eoaogwKcL08PSvuhrMDG4DaEV8RPSPsTvSQK5hsmEAiq3SJWGhvhGHRDrPp6mDHM4B0-w_y7qSkKQ9ETNJksguxyRPwYUAZmj-8haj7Q/s320/two+gaussian+0.5.PNG" alt="" id="BLOGGER_PHOTO_ID_5499300978863194514" border="0" /></a>pattern (left) and its FT (right)<br /><br /></div>Increasing the variance...<br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgqCZAKbroJQYAo5KKBNbcBtFL1gDKiSETw3DsCyLdYL3MuHn4fI-qe5iAAPp43agOjPFRQPt9wAMaOqImkQ8HmE7Synf4oNQEDx9E6xwMcRLgqq8pHJAGlMn9mxC0W0B5J9UsvUdFrXyc/s1600/two+gaussian+1.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 154px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgqCZAKbroJQYAo5KKBNbcBtFL1gDKiSETw3DsCyLdYL3MuHn4fI-qe5iAAPp43agOjPFRQPt9wAMaOqImkQ8HmE7Synf4oNQEDx9E6xwMcRLgqq8pHJAGlMn9mxC0W0B5J9UsvUdFrXyc/s320/two+gaussian+1.PNG" alt="" id="BLOGGER_PHOTO_ID_5499300983485769298" border="0" /></a><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZEwDoH6aJ1Z7Vo8ADqVTeUU6Lp9TharDxjbbwjPoE72H_fTIXL-8ugiWPH7HkeN2HIMEY-PAjXtr-y7UHu33D9a1vmat2WAhIiC46BqkAtzOJqig5a4SRO2q5hcfIhDCadx5_HSypzdY/s1600/two+gaussian+2.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 154px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZEwDoH6aJ1Z7Vo8ADqVTeUU6Lp9TharDxjbbwjPoE72H_fTIXL-8ugiWPH7HkeN2HIMEY-PAjXtr-y7UHu33D9a1vmat2WAhIiC46BqkAtzOJqig5a4SRO2q5hcfIhDCadx5_HSypzdY/s320/two+gaussian+2.PNG" alt="" id="BLOGGER_PHOTO_ID_5499300993657917426" border="0" /></a><br />This pattern is a convolution of two dirac delta's and a gaussian. The peaks are spaced futher apart therefore the lines are much closer together. The FT of a gaussian is still a gaussian so the FT modulus is the product of the sinusoid and the gaussian as seen in the figure. Increasing the variance of the gaussian leads to a smaller gaussian in the FT modulus.<br /><br />Next, we're asked to create a 200 x 200 array with ten 1's randomly located. Also, we made a 3x3 pattern of<br /><br />[0 0 1]<br />0 1 0<br />1 0 0]<br /><br /><div style="text-align: center;"><div style="text-align: left;">and convolved the two. The result is:<br /></div><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJ0CkrzMIUq7ccmHZMcIa7AkVy3ehmL0AL5gSI0d3c01OXHJQoZXz6vg4vejPD7bnF1lYVkwNJwpObWmVqGCOsMiyGz3Ts-OO9a7Id_PSNVnTcnikcro2YIz2rPS65sasPVqa991xrGHk/s1600/pattern+random.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 153px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJ0CkrzMIUq7ccmHZMcIa7AkVy3ehmL0AL5gSI0d3c01OXHJQoZXz6vg4vejPD7bnF1lYVkwNJwpObWmVqGCOsMiyGz3Ts-OO9a7Id_PSNVnTcnikcro2YIz2rPS65sasPVqa991xrGHk/s320/pattern+random.PNG" alt="" id="BLOGGER_PHOTO_ID_5499321229500294130" border="0" /></a>(left) array with random 1's. (right) convolved image<br /><br /></div>The dots are now replaced with the 3x3 pattern.<br /><br />Then, we create a 200 x 200 array with equally spaced 1's along the x and y axis. We vary the spacing of the 1's and then see what happens in the FT modulus:<br /><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhexF4_QLrDi4yskWsYOogXqdRtJuPMkI7XHsvOwcHMF6B1RsKJ1sIn4jgktJ2LbAeT3RXP57x2P0fdoXkMEwsEKXQ0muXGnrNAsQxEJvf5wRM5PU8e8S6QmNDs10BEUQgm261fiwdl7E0/s1600/grid+width40.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 154px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhexF4_QLrDi4yskWsYOogXqdRtJuPMkI7XHsvOwcHMF6B1RsKJ1sIn4jgktJ2LbAeT3RXP57x2P0fdoXkMEwsEKXQ0muXGnrNAsQxEJvf5wRM5PU8e8S6QmNDs10BEUQgm261fiwdl7E0/s320/grid+width40.PNG" alt="" id="BLOGGER_PHOTO_ID_5499322286322342642" border="0" /></a>grid pattern (left) and its FT (right). width = 5<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3k45nVOrbgRYtKa1oQXfH3UWm4j84zjWa42z2i6NWX5JiCFGVfJ3C9DltZa04pcIgt1exuj6JAHF2lv_-XrU40McPBZgWXZfk88kmXtelnc17xYEVpJKl93Wwt8n6Qs82ClfWHBJvMBM/s1600/grid+width20.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 153px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3k45nVOrbgRYtKa1oQXfH3UWm4j84zjWa42z2i6NWX5JiCFGVfJ3C9DltZa04pcIgt1exuj6JAHF2lv_-XrU40McPBZgWXZfk88kmXtelnc17xYEVpJKl93Wwt8n6Qs82ClfWHBJvMBM/s320/grid+width20.PNG" alt="" id="BLOGGER_PHOTO_ID_5499322276434077186" border="0" /></a>grid pattern (left) and its FT (right). width = 20<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhz3RFCu8uEK2RIO5i-2mxXGPTh-l29Ryvo92AMSCiy02q8476gYOcURFDirD5nIRAAp8PF83XgdbEJVpBqLeLilODXWmnFZDtw70Fd0AOiovYKg7yWuZ_kQ0xLftEwHfBlSIinoYyWMck/s1600/grid+width5.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 153px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhz3RFCu8uEK2RIO5i-2mxXGPTh-l29Ryvo92AMSCiy02q8476gYOcURFDirD5nIRAAp8PF83XgdbEJVpBqLeLilODXWmnFZDtw70Fd0AOiovYKg7yWuZ_kQ0xLftEwHfBlSIinoYyWMck/s320/grid+width5.PNG" alt="" id="BLOGGER_PHOTO_ID_5499322274984562482" border="0" /></a> grid pattern (left) and its FT (right). width = 40<br /></div><br />It is observed that the closer the 1's are spaced, the farther apart they are in frequency space, which is consisted with the inverse property of FT.<br /><br /><br />Part B. Fingerprints: Ridge Enhancement<br />For this part we'll be enhancing the ridges of the fingerprints by filtering in frequency space.<br /><br />I'm going to use this fingerprint that I got from the manual:<br /><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcRTQyHEhwnhXRvCKuiV8XMN_duCGZlKckWC_G3Qi0vXCWWfD8UU5baG9qqdkp5OGOkg8vxDVeNKv7yi9hLRtpylARHY7VPKmXT2Gf64j4jx3Z2mKs3Db9wEQC-SNVkzJoWOkjQRXte5c/s1600/fingerprint6.bmp"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 172px; height: 172px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcRTQyHEhwnhXRvCKuiV8XMN_duCGZlKckWC_G3Qi0vXCWWfD8UU5baG9qqdkp5OGOkg8vxDVeNKv7yi9hLRtpylARHY7VPKmXT2Gf64j4jx3Z2mKs3Db9wEQC-SNVkzJoWOkjQRXte5c/s320/fingerprint6.bmp" alt="" id="BLOGGER_PHOTO_ID_5499329011521905058" border="0" /></a>fingerprint</div><br />The fingerprint reminds me of sine waves that are propagating in all direction (2D) and it's like a ripple. So I thought: If you rotate the two peaks (FT of sinusoid) in all directions then you would get an annulus.<br /><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhyAo7vQajCouaPb3a8mED7jfMRTcITjtT7_CPXjxueAncwDzZ0_iSUAy9Sbov34QiXWSM4PafljOJV0gTJJ3vTYP4DoRbnjlNWbUh44Hm_aveeK9VMCoyXnklseysGtuEgdbGe82hp1x0/s1600/fingerprintmask.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 472px; height: 149px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhyAo7vQajCouaPb3a8mED7jfMRTcITjtT7_CPXjxueAncwDzZ0_iSUAy9Sbov34QiXWSM4PafljOJV0gTJJ3vTYP4DoRbnjlNWbUh44Hm_aveeK9VMCoyXnklseysGtuEgdbGe82hp1x0/s320/fingerprintmask.PNG" alt="" id="BLOGGER_PHOTO_ID_5499328991393120882" border="0" /></a>FT of fingerprint (left). Filtering mask (middle). Product of mask and FT (right).<br /></div><br />It's FT is the left figure and information is contained mostly in the bright annulus. So I designed the filter to let this part pass through as well as the center spot. Removing the center spot will invert the image (black --> white and white --> black) since 0's and 1's are interpreted as black and white respectively in scilab. Multiplying this filter or mask to the FT of the fingerprint and then inverse FT-ing results in:<br /><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh86hy6E2M4dhHALxSuscmBtz7XJJLkWVH1JbhD9uKjtuFvIh7h8mive5z9LeJ98GyhhiZcg93V0qUEBTRr05D7s58diltBZzHJM_X4Ejh8Y2aNv_zvPKj8_YiajHvtCcEsdXRuc0uGCDI/s1600/fingerprintbeforeafter.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 155px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh86hy6E2M4dhHALxSuscmBtz7XJJLkWVH1JbhD9uKjtuFvIh7h8mive5z9LeJ98GyhhiZcg93V0qUEBTRr05D7s58diltBZzHJM_X4Ejh8Y2aNv_zvPKj8_YiajHvtCcEsdXRuc0uGCDI/s320/fingerprintbeforeafter.PNG" alt="" id="BLOGGER_PHOTO_ID_5499328998128595138" border="0" /></a>original picture (left). Filtered fingerprint picture (right).<br /></div><br /><br />The black blotches that were present in the original (left) are now greatly reduced in the frequency filtered image (right). Putting a threshold or converting this to binary, we can see the effect of filtering more clearly:<br /><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXdYWZ79dl1lBGQW-7hdgfuRjPV_zJyNlrBvXUHHwfpT4-rNweaMfP-MJFwN8Ax-4Ou_7ySeJULkIlH3gOgg1VOuQzKFE10cw3jV63-cHig1EKJ6hTpZKFe6o70tjaTqH6dYuTz9ZpCbg/s1600/fingerprintbeforeafterbw.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 176px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXdYWZ79dl1lBGQW-7hdgfuRjPV_zJyNlrBvXUHHwfpT4-rNweaMfP-MJFwN8Ax-4Ou_7ySeJULkIlH3gOgg1VOuQzKFE10cw3jV63-cHig1EKJ6hTpZKFe6o70tjaTqH6dYuTz9ZpCbg/s320/fingerprintbeforeafterbw.PNG" alt="" id="BLOGGER_PHOTO_ID_5499329003280897666" border="0" /></a>original fingerprint (left). filtered fingerprint (right).<br /><br /></div>We can see that the blotches are removed and the ridges are enhanced. :)<br /><br /><br />Part C. Lunar Landing Scanned Pictures: Line Removal<br />Basically we're asked to remove the vertical lines in the picture caused by piecing together individual pictures into a composite one.<br /><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidLRUY3nzWmgQcoFoX8fWoo9f_skWUO6ezoVCrTb0mWH42vtUqLQtSIkII9MzO9W2REeZqtC9mLpsL4WBxz7zeE9kJ-Okkn9jIiuZ5-WnQjsgM-EIyihS0QLRsEmcxgYsAhyphenhyphenkO3FRwj5U/s1600/lunar.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 443px; height: 162px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidLRUY3nzWmgQcoFoX8fWoo9f_skWUO6ezoVCrTb0mWH42vtUqLQtSIkII9MzO9W2REeZqtC9mLpsL4WBxz7zeE9kJ-Okkn9jIiuZ5-WnQjsgM-EIyihS0QLRsEmcxgYsAhyphenhyphenkO3FRwj5U/s320/lunar.PNG" alt="" id="BLOGGER_PHOTO_ID_5499333325388725554" border="0" /></a>lunar picture (left) and its FT (right).<br /></div><br /><br />It's FT is shown on the right and since the vertical lines are equally spaced, we can think of this as a sinusoid. Therefore, the frequency components that make up these vertical lines belong to the horizontal bright line in the FT. Therefore I designed my filter to be:<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_dok7K-aTQgdQAIHTTtI8eqw2_k82H6leTBIChfjNB0Lnof1AP19gSSguRkq5UOVq0FwI2mcwxhOq-Aizf9D23bLb5auxA1ix3sQAk1H6U8GIDyYMIc9U38LGIuFBQCxV2zsY9Vdletw/s1600/lunar+filter.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 168px; height: 126px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_dok7K-aTQgdQAIHTTtI8eqw2_k82H6leTBIChfjNB0Lnof1AP19gSSguRkq5UOVq0FwI2mcwxhOq-Aizf9D23bLb5auxA1ix3sQAk1H6U8GIDyYMIc9U38LGIuFBQCxV2zsY9Vdletw/s320/lunar+filter.PNG" alt="" id="BLOGGER_PHOTO_ID_5499333337824395666" border="0" /></a><br />and applying this, I get:<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFmRWY2Ke7h-fr54vaYfgX_KkTZvlihua5LZ57ZJLXkp_bqUdecaWtlPsoNpXuxC6FV4O14psCVfKKz15PArwRu7J285aqBZUjFJGrOzfe0R_UZfo_pg-0ab5RFq3zSuIykxYAcEAXLgE/s1600/lunar+before+after.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 507px; height: 184px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFmRWY2Ke7h-fr54vaYfgX_KkTZvlihua5LZ57ZJLXkp_bqUdecaWtlPsoNpXuxC6FV4O14psCVfKKz15PArwRu7J285aqBZUjFJGrOzfe0R_UZfo_pg-0ab5RFq3zSuIykxYAcEAXLgE/s320/lunar+before+after.PNG" alt="" id="BLOGGER_PHOTO_ID_5499333329660068866" border="0" /></a><br />and the vertical lines are gone! The left one is the original while the right figure is the filtered one. :)<br /><br /><br />Part D. Canvas weave modeling and Removal<br />For this part, we're asked to remove the canvas weave patterns by filtering in the frequency domain.<br /><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-Cbgcsb6TU8i6Lww-6xjtapZUwqgHKVjdBUkZWkpvS3C6cUBoJEHf4YRwxb8ZDWkNuWHz4DENRZrgf_ZOQOLgGUAqg8yAHmx3q5LTP913BiqxuFjaDAhXHU4JDjjMz4Q_N5O9f7pA8J0/s1600/canvasweave.JPG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 230px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-Cbgcsb6TU8i6Lww-6xjtapZUwqgHKVjdBUkZWkpvS3C6cUBoJEHf4YRwxb8ZDWkNuWHz4DENRZrgf_ZOQOLgGUAqg8yAHmx3q5LTP913BiqxuFjaDAhXHU4JDjjMz4Q_N5O9f7pA8J0/s320/canvasweave.JPG" alt="" id="BLOGGER_PHOTO_ID_5499335168115410914" border="0" /></a>Oil painting from UP Vargas Museum Collection.<br /></div><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3tQiQFahAoFo4HlciGZDiX6XErXRaO8rdEF83QX9rI09r3f3kdP-UtfqQrygC-RcqcsVstbzcFC6H8wojK2dojYqWPPWDFkEva3rxWBozjqQor6fpVmPua8NrmV7pO-AWSQEcdamR9tM/s1600/painting+before+after.PNG"><br /></a><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1mCM_pcGPf1BdwHhjXrYWIKSLOz8ldPHomkwv8JwPCH4SvRnYm7YMDzccyJEdJsAe6vhy89ute6KQAgyTHbkXSpU6QAaRpod6lEMsJtHUYsGSL51Ne6s0Rhdq9jm4xIiBvHa_lNadBL4/s1600/painting+filter.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 441px; height: 156px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1mCM_pcGPf1BdwHhjXrYWIKSLOz8ldPHomkwv8JwPCH4SvRnYm7YMDzccyJEdJsAe6vhy89ute6KQAgyTHbkXSpU6QAaRpod6lEMsJtHUYsGSL51Ne6s0Rhdq9jm4xIiBvHa_lNadBL4/s320/painting+filter.PNG" alt="" id="BLOGGER_PHOTO_ID_5499334397298340482" border="0" /></a>FT of the painting (left) and with a filtering mask applied to it (right).<br /></div><br />The FT of the picture is shown in the left figure. Note that there are bright horizontal and vertical lines as well as some bright peaks. The canvas weaves are like grids so they can be thought of sine waves in the horizontal and vertical so I designed my mask to "cover" them as shown in the right. And after applying the filter, what I got is:<br /><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3tQiQFahAoFo4HlciGZDiX6XErXRaO8rdEF83QX9rI09r3f3kdP-UtfqQrygC-RcqcsVstbzcFC6H8wojK2dojYqWPPWDFkEva3rxWBozjqQor6fpVmPua8NrmV7pO-AWSQEcdamR9tM/s1600/painting+before+after.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 569px; height: 196px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3tQiQFahAoFo4HlciGZDiX6XErXRaO8rdEF83QX9rI09r3f3kdP-UtfqQrygC-RcqcsVstbzcFC6H8wojK2dojYqWPPWDFkEva3rxWBozjqQor6fpVmPua8NrmV7pO-AWSQEcdamR9tM/s320/painting+before+after.PNG" alt="" id="BLOGGER_PHOTO_ID_5499334395513897314" border="0" /></a>Original painting (left) and filtered image of painting (right).<br /></div><br />Voila! The canvas weave patterns are gone! :D :D Also, the brushstrokes in the painting seems to have been enhanced as compared to the original.<br /><br />Lastly, we invert the filtering mask and then take it's inverse FT. What I get is:<br /><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgP3xEhbNh8ph4pQw1QGkKBRhegE6oct3EDuXZ6o9qwglOdDYtl2xbeHPKNZRiXvNmdMjrdZlYAjAEZZWPYPxloAcx19SA7VDsqLXEk6H_iyiqMdO_9TQs0QjNmECH6pxiBM202YhE_LXc/s1600/paint+filter+fft.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 422px; height: 148px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgP3xEhbNh8ph4pQw1QGkKBRhegE6oct3EDuXZ6o9qwglOdDYtl2xbeHPKNZRiXvNmdMjrdZlYAjAEZZWPYPxloAcx19SA7VDsqLXEk6H_iyiqMdO_9TQs0QjNmECH6pxiBM202YhE_LXc/s320/paint+filter+fft.PNG" alt="" id="BLOGGER_PHOTO_ID_5499334404106424274" border="0" /></a>Inverted mask (left) and its inverse FT (right).<br /><br /></div><br />Cool pattern! Not only that, it looks like the canvas weave pattern in some way because it has grids too. :D<br /><br /><br />Grading myself, I give a 10/10 for understanding the lesson and producing the required outputs (whew!)<br /><span style="font-weight: bold;">Score: 10/10</span><br /><br />Finally, I would like to acknowledge Dr. Soriano, Tisza Trono, Arvin Mabilangan, BA Racoma and Joseph Bunao for the helpful discussions. :D<br /><br />References:<br />1. M. Soriano, "A8 - Enhancement in the Frequency Domain"<br /><br />Appendix: (Code) (There are missing semi-colons and slash because i removed them. This blog sometimes just won't display the codes correctly.)<br /><br />nx = 256;<br />ny = 256;<br />x = linspace(-128,128,nx);<br />y = linspace(-128,128,ny);<br />[X,Y] = ndgrid(x,y);<br /><br />// two dots<br />A = ones(nx, ny);<br />A(find(Y>20)) = 0;<br />A(find(Y<19))>1)) = 0;<br />A(find(X<-1)) = 0; two circles r= sqrt(X.^2 + Y.^2); A = zeros (nx,ny); A(find((X.^2 + (Y+20).^2) < a =" ones(nx,">25)) = 0;<br />A(find(Y<15))>5)) = 0;<br />A(find(X<-5)) = 0; two gaussians nx = 256; ny = 256; x = linspace(-1,1,nx); y = linspace(-1,1,ny); [X,Y] = ndgrid(x,y); r= sqrt((X.^2 + (Y+0.4).^2)/0.0001); A1 = exp(-r); r= sqrt((X.^2 + (Y-0.4).^2)/0.0001); A2 = exp(-r); A = A1 + A2; grid A = zeros(200, 200); width = 5; for i = 1:width:200 for j = 1: width:200 A(i, j) = 1; end end For Part B: nx = 419; ny = 581; x = linspace(-1,1,nx); y = linspace(-1,1,ny); [X,Y] = ndgrid(x,y); r= sqrt(X.^2 + Y.^2); finger = gray_imread("C:\fingerprint.jpg"); FTfinger = fftshift(fft2(finger)); mask = ones(nx, ny); mask = zeros(nx, ny); mask(find(r<0.20)) a =" FTfinger" b =" im2bw(finger," c =" im2bw(abs(ifft(A))," a =" gray_imread(" fta =" fftshift(fft2(A));" nx =" 480;" ny =" 640;" x =" linspace(-1,1,nx);" y =" linspace(-1,1,ny);" mask =" ones(nx,">0.10)) = 0;<br />mask(find(abs(X)>0.045)) = 1;<br /><br />C = FTA .* mask;<br /><br />scf();<br />imshow(log(abs(C)+0.1), []);<br /><br />scf();<br />imshow(A, []);<br /><br />scf();<br />imshow(abs(fft2(C)),[]);<br /><br /><br />For Part D:<br /><br />nx = 419; ny = 581; //defines the number of elements along x and y<br /><br />x = linspace(-1,1,nx); //defines the range<br />y = linspace(-1,1,ny);<br />[X,Y] = ndgrid(x,y);<br />r= sqrt(X.^2 + Y.^2);<br /><br /><br />mask1 = ones(nx, ny);<br />mask1(find(abs(Y)<0.02)) = 0;<br />mask1(find(abs(X)<0.04)) = 1;<br /><br />mask2 = ones(nx, ny);<br />mask2(find(abs(X)<0.02)) = 0;<br />mask2(find(abs(Y)<0.04)) = 1;<br /><br /><br />mask = ones(nx, ny);<br />mask(find((Y.^2 + (X+0.43).^2) < 0.0004)) = 0;<br />mask(find((Y.^2 + (X-0.43).^2) < 0.0004)) = 0;<br />mask(find((Y.^2 + (X+0.205).^2) < 0.0004)) = 0;<br />mask(find((Y.^2 + (X-0.205).^2) < 0.0004)) = 0;<br /><br />mask(find(((Y+0.31).^2 + X.^2) < 0.0004)) = 0;<br />mask(find(((Y-0.31).^2 + X.^2) < 0.0004)) = 0;<br />mask(find(((X+0.1).^2 + (Y-0.16).^2) < 0.0004)) = 0;<br />mask(find(((X-0.1).^2 + (Y-0.16).^2) < 0.0004)) = 0;<br />mask(find(((X+0.1).^2 + (Y+0.16).^2) < 0.0004)) = 0;<br />mask(find(((X-0.1).^2 + (Y+0.16).^2) < 0.0004)) = 0;<br /><br /><br />//scf();<br />//imshow(log(abs(FTA)+0.1),[]);<br /><br />C = FTA .* mask2 .* mask1 .* mask;<br /><br />scf();<br />imshow(log(abs(C)+0.1), []);<br /><br />scf();<br />imshow(A, []);<br /><br />scf();<br />imshow(abs(ifft(C)),[]);dennisivan89http://www.blogger.com/profile/04476991777095665795noreply@blogger.com0tag:blogger.com,1999:blog-7345763871585817117.post-47327052974868592512010-07-21T20:01:00.000-07:002010-09-23T08:48:43.500-07:00AP 186 Act7 - Properties of the 2D Fourier TransformFor this activity, we'll explore some properties of the 2D Fourier Transform (FT):<br /><br />Part A: Familiarization with FT of different 2D patterns<br />In this part, we created 2D patterns and then took their FT's and see what it looks like.<br /><br /><div style="text-align: center;"><div style="text-align: left;">Square:<br /></div><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjoCvlaucji6giLzmyXVKUdcuGsrYx9k867KcK4NTUsKo4gD67go40CBEWx9JRDyLjGSuV7FL1fBUyvibvk5JjMBfA3U4HVDQab-q-5N6D6E3nCeFMmifJvU0mI2RrRDgJrN0LiQLFL1xo/s1600/square.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 153px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjoCvlaucji6giLzmyXVKUdcuGsrYx9k867KcK4NTUsKo4gD67go40CBEWx9JRDyLjGSuV7FL1fBUyvibvk5JjMBfA3U4HVDQab-q-5N6D6E3nCeFMmifJvU0mI2RrRDgJrN0LiQLFL1xo/s320/square.PNG" alt="" id="BLOGGER_PHOTO_ID_5496565526937831106" border="0" /></a>square pattern and its FT<br /></div><br /><div style="text-align: left;">Annulus (Donut):<br /><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgoyQWB5IPGiaHKLPVtCtOAPBiyM761iw6ZOvnW3CXjoBkj89PQfyE8SaKlu5siM3yco_R1LKwTAKBQzc3Wg_25fy5LPSYJtYL9BBtpYx3SF7NnQqcwzi5iZUqo-_chxImW2Fq1XjfXimk/s1600/annulus.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 154px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgoyQWB5IPGiaHKLPVtCtOAPBiyM761iw6ZOvnW3CXjoBkj89PQfyE8SaKlu5siM3yco_R1LKwTAKBQzc3Wg_25fy5LPSYJtYL9BBtpYx3SF7NnQqcwzi5iZUqo-_chxImW2Fq1XjfXimk/s320/annulus.PNG" alt="" id="BLOGGER_PHOTO_ID_5496565530232223266" border="0" /></a>Annulus pattern and its FT<br /></div></div><br />Square annulus:<br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOTZjyA7eUYcqUHdNaGBEWkLqu1CtEkzhHMQb1MmHQyF9YvSWcUer_VBpoF7qYwY6JdTKTcDxXgn9lt7OahQgM2jO5xjhdO6SraYqDEfA7ro44zKQnRpZny37QTqRkReQpuAJyBYZ2cEE/s1600/square+annulus.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 152px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOTZjyA7eUYcqUHdNaGBEWkLqu1CtEkzhHMQb1MmHQyF9YvSWcUer_VBpoF7qYwY6JdTKTcDxXgn9lt7OahQgM2jO5xjhdO6SraYqDEfA7ro44zKQnRpZny37QTqRkReQpuAJyBYZ2cEE/s320/square+annulus.PNG" alt="" id="BLOGGER_PHOTO_ID_5496565537741428066" border="0" /></a>square annulus and its FT<br /></div><br />Two slits along the x-axis symmetric about the center:<br /><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMEyvbmCvOm2dU4EXUe3VzinT0-nIRPtEc8bSdz6GsWFR_9FyMskMxXXsc1MqKYr74oLIFmfw5J5C4A6UajvBuDnlrkyJEBt8OvXa_sEDqHNkDac3gxAR5TNa3Z-TteI_PvmoVOwl5K9Y/s1600/double+slit.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 141px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMEyvbmCvOm2dU4EXUe3VzinT0-nIRPtEc8bSdz6GsWFR_9FyMskMxXXsc1MqKYr74oLIFmfw5J5C4A6UajvBuDnlrkyJEBt8OvXa_sEDqHNkDac3gxAR5TNa3Z-TteI_PvmoVOwl5K9Y/s320/double+slit.PNG" alt="" id="BLOGGER_PHOTO_ID_5496565543392698690" border="0" /></a>double slit pattern along x-axis and its FT<br /></div><br />Two dots along x-axis symmetric about the center:<br /><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9O2HjzqNZe-iuWF6x4l9i7sjpKGZQ7jzTOJtaw9Gq1T4mExmeb9zn91YJRDfsBY7YtFmESMOhKWE_WVXt1JmBEfZcmPGOwRvsADEG34AsCVRzkoHoiVnCsN00ptYxYwB4F-P36Q8DLR4/s1600/two+dots+tlga.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 151px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9O2HjzqNZe-iuWF6x4l9i7sjpKGZQ7jzTOJtaw9Gq1T4mExmeb9zn91YJRDfsBY7YtFmESMOhKWE_WVXt1JmBEfZcmPGOwRvsADEG34AsCVRzkoHoiVnCsN00ptYxYwB4F-P36Q8DLR4/s320/two+dots+tlga.PNG" alt="" id="BLOGGER_PHOTO_ID_5496565552183485554" border="0" /></a>Two dots (1 pixel) along x-axis pattern and its FT<br /><br /></div>Note: If the dots are not of 1 pixel, a whole different FT pattern will appear:<br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhf16o7pGgjWntFwSgGMn2TW1AtFi-O_L4giLYfrNOOJXHpudlu-rUwruguvZPu6z75ZzWy8Zuz6QxKyukO3wIsm2FeZ-Dkis6LXxUKTEzN7k-cy6B2Q1LNK_h5vSNL18MoY1OuIVfPTD0/s1600/two+dots.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 153px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhf16o7pGgjWntFwSgGMn2TW1AtFi-O_L4giLYfrNOOJXHpudlu-rUwruguvZPu6z75ZzWy8Zuz6QxKyukO3wIsm2FeZ-Dkis6LXxUKTEzN7k-cy6B2Q1LNK_h5vSNL18MoY1OuIVfPTD0/s320/two+dots.PNG" alt="" id="BLOGGER_PHOTO_ID_5496568495455838274" border="0" /></a>different FT pattern if dots are not of 1 pixel<br /></div><br /><br />Part B: Anamorphic property of the Fourier Transform<br /><br />First, we're asked to make a 2D sinusoid in the x direction (like a corrugated roof) and take it's FT:<br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhR76mysd150RVBYVqq-hfz-uLOsT9YVtN97j2xTkAQoyZ37KEtls3nmOXYEatO4047bXxjrDK3N86MWOeCa2Z2W60gVMDed6zXVjFZ0q8yElXwR9GJ3hfFWfMpALvJT8ZP1lyOVx0RxDY/s1600/sine+2hz.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 154px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhR76mysd150RVBYVqq-hfz-uLOsT9YVtN97j2xTkAQoyZ37KEtls3nmOXYEatO4047bXxjrDK3N86MWOeCa2Z2W60gVMDed6zXVjFZ0q8yElXwR9GJ3hfFWfMpALvJT8ZP1lyOVx0RxDY/s320/sine+2hz.PNG" alt="" id="BLOGGER_PHOTO_ID_5496569509977349346" border="0" /></a>sine wave (f=2Hz) and its FT<br /></div><br />Next we change the frequency of the sinusoid:<br /><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgd6zAdpXnMfFUM-z0ETvhHRA3jyldiueMBN7VlrNB8o8zDIY4a0RJMwtql1tJSA17yDazetlI7IVkyNjpTISUGqZnPJLWCxQHyTG0ooB_551uhqxI3X5rfOevCUCHss499QmJiTNwPIug/s1600/sine+4hz.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 156px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgd6zAdpXnMfFUM-z0ETvhHRA3jyldiueMBN7VlrNB8o8zDIY4a0RJMwtql1tJSA17yDazetlI7IVkyNjpTISUGqZnPJLWCxQHyTG0ooB_551uhqxI3X5rfOevCUCHss499QmJiTNwPIug/s320/sine+4hz.PNG" alt="" id="BLOGGER_PHOTO_ID_5496569514957567698" border="0" /></a>f = 4 Hz<br /></div><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDNh6jK7HEMsHLVKoeitqp6f4hknsi_xi87X96Q3Sr-2c0T0JoexwO2leE8q1W9-kLVNqht4XrOC9ZABqoB0r1hpE1BpBXUVZ-3ThIn-fc188E2oF_SODHUIa_hAwxvrw4RhLJ7t9FhQs/s1600/sine+8hz.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 149px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDNh6jK7HEMsHLVKoeitqp6f4hknsi_xi87X96Q3Sr-2c0T0JoexwO2leE8q1W9-kLVNqht4XrOC9ZABqoB0r1hpE1BpBXUVZ-3ThIn-fc188E2oF_SODHUIa_hAwxvrw4RhLJ7t9FhQs/s320/sine+8hz.PNG" alt="" id="BLOGGER_PHOTO_ID_5496569523836149858" border="0" /></a>f = 8 Hz<br /><br /></div><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjij4DlQ8qLwINSgSn_IBmiWl1hDb5lPdmq0skxgoIk4BiLBYPDaz6HpyB5J2fdkly4B3PCyIlEeH9jqBtob_xZP5KWV7ICpKGAXkbOqVjBxW2zG4BmLU54TrZ9opNfI15OOQR4f_6bfpM/s1600/sine+16hz.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 151px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjij4DlQ8qLwINSgSn_IBmiWl1hDb5lPdmq0skxgoIk4BiLBYPDaz6HpyB5J2fdkly4B3PCyIlEeH9jqBtob_xZP5KWV7ICpKGAXkbOqVjBxW2zG4BmLU54TrZ9opNfI15OOQR4f_6bfpM/s320/sine+16hz.PNG" alt="" id="BLOGGER_PHOTO_ID_5496569528896290802" border="0" /></a>f = 16 Hz<br /><br /><div style="text-align: left;">As the frequency of the sine wave is increased or decreased, the two peaks in the frequency space moves farther apart or closer together, respectively. This is because low frequencies are close to the center (zero) in frequency space and as you move away from the center, the frequency increases.<br /><br />Adding a bias to the sinusoid and taking the FT:<br /><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgztYj8R35bP3e0KXJZ0-SuLGRDtJvnafaNi9lKv9ABetNq2uYuQVwzRjOtcRAB5jhtdnXpp7hOeS3WMVsb62VuqW6zx2OKOj_6rvKm2zNJtasmqzadTiCdY7KnV4pSA1zsv1DnB9a9q4c/s1600/sine+bias.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 155px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgztYj8R35bP3e0KXJZ0-SuLGRDtJvnafaNi9lKv9ABetNq2uYuQVwzRjOtcRAB5jhtdnXpp7hOeS3WMVsb62VuqW6zx2OKOj_6rvKm2zNJtasmqzadTiCdY7KnV4pSA1zsv1DnB9a9q4c/s320/sine+bias.PNG" alt="" id="BLOGGER_PHOTO_ID_5496569535936166322" border="0" /></a>sinusoid with bias and its FT<br /><br /><div style="text-align: left;">By adding the bias, the sinusoid now oscillates with non-negative values. However, we can see that there's an additional peak right in the middle of its FT. Digital images have no negative values so for example, what I can do to find the actual frequencies of the interferogram from Young's double slit experiment is to DC-filter it first. DC filtering will remove the bias and hence the middle peak in the FT. If the bias is non-constant, e.g. low frequency sinusoids, I can still get the frequencies of the interferogram by applying a high pass filter. This way, the low frequencies (the noise in this case), will be removed.<br /><br />Next, we rotate the sinusoid and take its FT:<br /><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjAojaNAHwDSgF_iOoYx8eL6fFAQulKDja0HhZqY7guHryjf5f7yT7eviNpE4DRLRr1tZdT-KPBnMpX1fkQVnH5ZwPFAJC8b59SH6Y0drWqpZAjk70z6Xl9I-AoGMkoip99FZLgKGJ27bc/s1600/sine+rotated+30.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 148px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjAojaNAHwDSgF_iOoYx8eL6fFAQulKDja0HhZqY7guHryjf5f7yT7eviNpE4DRLRr1tZdT-KPBnMpX1fkQVnH5ZwPFAJC8b59SH6Y0drWqpZAjk70z6Xl9I-AoGMkoip99FZLgKGJ27bc/s320/sine+rotated+30.PNG" alt="" id="BLOGGER_PHOTO_ID_5496573120815130130" border="0" /></a>rotated 30 degrees<br /><br /></div></div></div></div></div><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgB-hcpBMp5nHzLoCBYe9k4GPVvgLlBvyOeG-YUaUtcbMcVNnWPRN5C1E-5-CbmxXr5fLKzjAQOtNVMYuO8v1N2fFxeUyIhRNH0PJj4Scdq2BpiD31qRKYzoSB5tGiOcoz61Ftm9GNYYLk/s1600/sine+rotated+45.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 153px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgB-hcpBMp5nHzLoCBYe9k4GPVvgLlBvyOeG-YUaUtcbMcVNnWPRN5C1E-5-CbmxXr5fLKzjAQOtNVMYuO8v1N2fFxeUyIhRNH0PJj4Scdq2BpiD31qRKYzoSB5tGiOcoz61Ftm9GNYYLk/s320/sine+rotated+45.PNG" alt="" id="BLOGGER_PHOTO_ID_5496573128657351730" border="0" /></a>rotated 45 degrees<br /></div><br />Rotating the sinusoid also amounts to rotating their FT by the same amount. This is a unique property of the 2D FT compared to the 1D FT.<br /><br />Next, we created a pattern which is a combination of sinusoids in the X and Y direction, take its FT and see what it looks like:<br /><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgh0Iyro7RKXvvkvAz8Kj6J-HlbFc65sBDU9ywSJ-HKlmhiNVn0bsPdcMZay2ynTJLvX5jbGWYnQNPmz6nvcFXQQiKL5U0IQ8UgPmq8ckNYbr2nGqMIWnPvsPBzdGnAcCrZVglQC5MK-N8/s1600/sine+xy.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 152px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgh0Iyro7RKXvvkvAz8Kj6J-HlbFc65sBDU9ywSJ-HKlmhiNVn0bsPdcMZay2ynTJLvX5jbGWYnQNPmz6nvcFXQQiKL5U0IQ8UgPmq8ckNYbr2nGqMIWnPvsPBzdGnAcCrZVglQC5MK-N8/s320/sine+xy.PNG" alt="" id="BLOGGER_PHOTO_ID_5496578346380817474" border="0" /></a>combination of sinusoids in the X and Y and its FT<br /><br /><div style="text-align: left;">Then we add several rotated sinusoids in the pattern. I added two sinusoids: 1 rotated by 30 degrees and another one rotated by 45 degrees. Since I know that rotating the sinusoids will also rotate their FT, the FT's of the added sinusoids individually are shown in the last part. At first I predict that adding the sinusoids would result in a rotation of the FT of the "eggcart". But remembering that the FT is a linear transformation, the FT of the result should be the addition of the FT's of the components. Therefore, the resulting FT should be something like 4 peaks on the corners of a square, then two peaks tilted at 30 degrees and another 2 peaks tilted 45 degrees. Checking this prediction:<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBl2L8qjBNDoHfqJCXlo5W6cHwEncwG5-YjFdEppjFc5tW14Hl516VJhYEgaQMkma_shzvsyHfVg6zUXNJK-QGMPt3j92-vxJTJdQyoK_hzT9u6hIFHlZqp6vMOVZWK8xE-S8oAN6EvbU/s1600/last+part.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 153px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBl2L8qjBNDoHfqJCXlo5W6cHwEncwG5-YjFdEppjFc5tW14Hl516VJhYEgaQMkma_shzvsyHfVg6zUXNJK-QGMPt3j92-vxJTJdQyoK_hzT9u6hIFHlZqp6vMOVZWK8xE-S8oAN6EvbU/s320/last+part.PNG" alt="" id="BLOGGER_PHOTO_ID_5496578350487468450" border="0" /></a><br />Indeed, the resulting FT is the same as the prediction! :D<br /><br /><br />Rating myself, I would give myself a 10/10 for understanding the lesson and producing the required outputs.<br /><br /><span style="font-weight: bold;">Score: 10/10<br /><br /></span>Lastly, I would like to acknowledge Dr. Soriano, BA Racoma and Androphil Polinar<span style="font-weight: bold;"><br /></span>for the helpful discussions.<span style="font-weight: bold;"><br /><br /></span>- Dennis<span style="font-weight: bold;"><br /></span><span><br />References:<br />1. M. Soriano, "A7 - Properties of the 2D Fourier Transform"</span><span style="font-weight: bold;"><br /></span></div></div>dennisivan89http://www.blogger.com/profile/04476991777095665795noreply@blogger.com0tag:blogger.com,1999:blog-7345763871585817117.post-43119203936734147482010-07-19T19:21:00.000-07:002010-09-23T08:47:54.457-07:00AP 186 Act6 – Fourier Transform Model of Image FormationIn this activity we will be dealing with Fourier Transforms (Fast Fourier Transforms) and their applications in image processing. Cooley and Tukey made the FFT algorithm and it’s widely used in image as well as signal processing. <p class="MsoNormal">Part A. Familiarization with FFT</p> <p class="MsoNormal">First we’re asked to make a white circle centered on a black background:</p> <p class="MsoNormal"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiga4TUTW9ZCDbcjcMvV5LN3iFsxevEBGgWLsWpXD2WiqcB2_9ow-qSqg0xQyqb-ERK31b_d8akfU7HrVMqXsVTy_xY49XaOg2xCZEbxdm6L7ztbYq_Q5cEO314YCRUfurKld22xOGR3SA/s1600/circle.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 128px; height: 128px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiga4TUTW9ZCDbcjcMvV5LN3iFsxevEBGgWLsWpXD2WiqcB2_9ow-qSqg0xQyqb-ERK31b_d8akfU7HrVMqXsVTy_xY49XaOg2xCZEbxdm6L7ztbYq_Q5cEO314YCRUfurKld22xOGR3SA/s320/circle.PNG" alt="" id="BLOGGER_PHOTO_ID_5495808454436714514" border="0" /></a></p> <p class="MsoNormal">(Note that this circle can also represent a circular aperture. I’ve made my circle smaller since this will result in a bigger Airy disk as will be seen later.)</p> <p class="MsoNormal">Then we converted this to grayscale and performed the Fast Fourier Transform (FFT). Abs() was used to get the intensity values since the FFT will return an array of complex numbers.<br /></p><p class="MsoNormal"></p><blockquote style="color: rgb(0, 102, 0);">I = imread('C:\circle.PNG');<br />Igray = im2gray(I);<br />FIgray = fft2(Igray);<br />imshow(abs(FIgray), []);<br /></blockquote>And this is the result:<p></p> <p style="text-align: center;" class="MsoNormal"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiciqB0kFziFc88ffPSHiqKvTBnuMrIwXCXV8rK6BkAoKFTsXYGomMqfhK1Gxlr448tuh3CptuJaBpk0jzg4ForEmVYm3p0j17Zab-5EWXdSJqYvFIu7zCbHb70F81q9PpAfHTbwvC5sTc/s1600/A1.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 264px; height: 264px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiciqB0kFziFc88ffPSHiqKvTBnuMrIwXCXV8rK6BkAoKFTsXYGomMqfhK1Gxlr448tuh3CptuJaBpk0jzg4ForEmVYm3p0j17Zab-5EWXdSJqYvFIu7zCbHb70F81q9PpAfHTbwvC5sTc/s320/A1.PNG" alt="" id="BLOGGER_PHOTO_ID_5495808460577425602" border="0" /></a>FFT of the white circle<br /></p> <p class="MsoNormal">It looks like a pure black picture but take a look at the four corners. :p</p> <p class="MsoNormal">This is a result of the FFT. It’s fast, but it also results in the reversal of the quadrants diagonally. Therefore, applying the fftshift will give:</p><blockquote style="color: rgb(0, 102, 0);">imshow(fftshift(abs(FIgray)), []);</blockquote><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_BQfT10s_WAlwEk6qnWruB_HEYso19SCOWuqAixvQL3BxgxlM8mPeKjzLb9hlSt5pSvHHb9OMgOBAoLbv7LheX0c7m0ryXy4mdX2tNyqmxtNPL0fE7diJolXO2zm2KqXGCwHtA3cGdkM/s1600/A2.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 270px; height: 271px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_BQfT10s_WAlwEk6qnWruB_HEYso19SCOWuqAixvQL3BxgxlM8mPeKjzLb9hlSt5pSvHHb9OMgOBAoLbv7LheX0c7m0ryXy4mdX2tNyqmxtNPL0fE7diJolXO2zm2KqXGCwHtA3cGdkM/s320/A2.PNG" alt="" id="BLOGGER_PHOTO_ID_5495808477614909362" border="0" /></a>shifted FFT of the circle<br /></div><p class="MsoNormal">Now that’s better. :) That’s the Fourier transform of the white circle.</p> <p class="MsoNormal">Applying the FFT again on the transformed image (or consequently, applying the FFT twice on the original image) will theoretically result in an inverted original image:</p><div style="text-align: left;"><blockquote style="color: rgb(0, 102, 0);">imshow(abs(fft2(FIgray)));<br /></blockquote></div><p style="text-align: center;" class="MsoNormal"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZejMY4VvGeIQqsBLczMPNJ-i5CWinI7fWUkuJpn7sUOZLI-BeTxT8SVwQ-dhJJUtAg5OwNEBhY9sSH2qbRJGll_thL4wgVxyXvI6hVIMrRSME2nOJBBZYP7R84LborbsStZLMzbjcZPM/s1600/A3.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 225px; height: 224px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZejMY4VvGeIQqsBLczMPNJ-i5CWinI7fWUkuJpn7sUOZLI-BeTxT8SVwQ-dhJJUtAg5OwNEBhY9sSH2qbRJGll_thL4wgVxyXvI6hVIMrRSME2nOJBBZYP7R84LborbsStZLMzbjcZPM/s320/A3.PNG" alt="" id="BLOGGER_PHOTO_ID_5495808492502799394" border="0" /></a>circle FFT'ed twice<br /></p><p class="MsoNormal">Well, we got the original image alright. But we can’t tell if this is inverted since an inverted circle is still a circle. So we try this on the letter “A”:</p> <p class="MsoNormal">The (unshifted) FFT of A:</p><p style="text-align: left;" class="MsoNormal"><span style="color: rgb(0, 102, 0);"></span></p><blockquote><span style="color: rgb(0, 102, 0);">I = imread('A.bmp');</span><br /><span style="color: rgb(0, 102, 0);">Igray = im2gray(I);</span><br /><span style="color: rgb(0, 102, 0);">FIgray = fft2(Igray);</span><br /><span style="color: rgb(0, 102, 0);">imshow(abs(FIgray), []);</span></blockquote><p></p><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjN4HwZTrrC9TBKzwSgkOPv5iKHEispjwRY2s5q-zIORkkvV7hhQBQINhbz_HGD6fLUydcwaG4K9C0VrhQfIYIqdFNNpXF2KtxYdER8s8odIPC0yU9WKsEAYaq_d0pWv8CK4U-GgmDZ3lE/s1600/A4.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 286px; height: 286px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjN4HwZTrrC9TBKzwSgkOPv5iKHEispjwRY2s5q-zIORkkvV7hhQBQINhbz_HGD6fLUydcwaG4K9C0VrhQfIYIqdFNNpXF2KtxYdER8s8odIPC0yU9WKsEAYaq_d0pWv8CK4U-GgmDZ3lE/s320/A4.PNG" alt="" id="BLOGGER_PHOTO_ID_5495809301962885778" border="0" /></a>unshifted FFT of "A"<br /></div><p class="MsoNormal">And applying fftshift:</p><div style="text-align: left;"><blockquote style="color: rgb(0, 102, 0);">imshow(fftshift(abs(FIgray)), []);</blockquote></div><p style="text-align: center;" class="MsoNormal"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQrO6gtF_ovjXs68PyoUknyAoWiEmZhDg88K9X7JS8ExzmkUtH-mij90uFQtqKRBi_lxbNvii99jkFpDMXd1Q2TH1wYd8dE72L5x7JQgsMBXbhRxS4bC5wxG5Bi4ak_ZyTtnv-nP8Jlzs/s1600/A5.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 283px; height: 283px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQrO6gtF_ovjXs68PyoUknyAoWiEmZhDg88K9X7JS8ExzmkUtH-mij90uFQtqKRBi_lxbNvii99jkFpDMXd1Q2TH1wYd8dE72L5x7JQgsMBXbhRxS4bC5wxG5Bi4ak_ZyTtnv-nP8Jlzs/s320/A5.PNG" alt="" id="BLOGGER_PHOTO_ID_5495809305801326210" border="0" /></a>shifted FFT of "A"<br /></p><p class="MsoNormal">And that’s the Fourier transform of “A”.</p> <p class="MsoNormal">Now applying the FFT twice… we get:</p><p style="color: rgb(0, 102, 0);" class="MsoNormal"></p><blockquote>imshow(abs(fft2(FIgray)));</blockquote><p></p> <p style="text-align: center;" class="MsoNormal"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwdhZ0dnLU5LQ1UvYGV5ZoN3-bhqUluA9vVQpNWef4vuzRFF0XfxX5fPfbiNiYV8Lg5NdtFzw72qeIYgH6tUVVbayn7GbDkYwrVjwRhsjxedP_1p8Fue8BgaMntMI3cKo7WslYohYPUhQ/s1600/A6.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 226px; height: 227px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwdhZ0dnLU5LQ1UvYGV5ZoN3-bhqUluA9vVQpNWef4vuzRFF0XfxX5fPfbiNiYV8Lg5NdtFzw72qeIYgH6tUVVbayn7GbDkYwrVjwRhsjxedP_1p8Fue8BgaMntMI3cKo7WslYohYPUhQ/s320/A6.PNG" alt="" id="BLOGGER_PHOTO_ID_5495809311600483282" border="0" /></a>"A" FFT'ed twice<br /></p><p class="MsoNormal">Which is indeed, the inverted image of the letter “A”. :D An inverted image results in the application of FFT twice because doing so will result in the introduction of a negative sign in the x’s and y’s. If you want to get your original image back from a Fourier transformed image, do the inverse Fourier transform. :)</p> <p class="MsoNormal"><o:p> </o:p></p> <p class="MsoNormal">Part B. Simulation of an imaging device</p> <p class="MsoNormal">We’re asked to create an image of the letters “VIP” and this will be our object to be imaged. I used Arial font because according to the activity manual, sans serif fonts are sharp.</p> <p style="text-align: center;" class="MsoNormal"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipu32zo5O4ZeyZrldED15deGdte5z7HpCx-IdZgt0Y-Z1Ls4dvgl8VoqJ2yz3hSBZd_zb6ehnLRppsfRDYlmuR3vLtEu2AKZJQ5vTRFLLw7WfNS9Douq_EEmeIdF-TkpmzHFT0G4ioWlg/s1600/VIP.bmp"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 128px; height: 128px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipu32zo5O4ZeyZrldED15deGdte5z7HpCx-IdZgt0Y-Z1Ls4dvgl8VoqJ2yz3hSBZd_zb6ehnLRppsfRDYlmuR3vLtEu2AKZJQ5vTRFLLw7WfNS9Douq_EEmeIdF-TkpmzHFT0G4ioWlg/s320/VIP.bmp" alt="" id="BLOGGER_PHOTO_ID_5495809998807987634" border="0" /></a>object<br /></p><p class="MsoNormal">We also created a white circle on a black background and this represents the aperture of a lens.</p> <p style="text-align: center;" class="MsoNormal"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiga4TUTW9ZCDbcjcMvV5LN3iFsxevEBGgWLsWpXD2WiqcB2_9ow-qSqg0xQyqb-ERK31b_d8akfU7HrVMqXsVTy_xY49XaOg2xCZEbxdm6L7ztbYq_Q5cEO314YCRUfurKld22xOGR3SA/s1600/circle.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 128px; height: 128px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiga4TUTW9ZCDbcjcMvV5LN3iFsxevEBGgWLsWpXD2WiqcB2_9ow-qSqg0xQyqb-ERK31b_d8akfU7HrVMqXsVTy_xY49XaOg2xCZEbxdm6L7ztbYq_Q5cEO314YCRUfurKld22xOGR3SA/s320/circle.PNG" alt="" id="BLOGGER_PHOTO_ID_5495808454436714514" border="0" /></a>aperture<br /></p> <p class="MsoNormal">The image of the “VIP” can be obtained by convolving the object with the transfer function of the imaging system. Convolution is done by taking the product of the FFT of the grayscaled object with the fftshifted aperture and then inverse fourier transforming. The aperture image doesn’t need to be FFT-ed because it is already in the Fourier Plane.<br /></p><p class="MsoNormal"></p><blockquote style="color: rgb(0, 102, 0);">T = gray_imread('C:\VIP.bmp');<br />A = gray_imread('C:\circle.PNG');<br />Ar = fftshift(A);<br />Ta = fft2(T);<br />FRA = Ta.*Ar;<br />IRA = fft2(FRA);<br />imshow(abs(IRA), []);<br /></blockquote>The output is:<p></p> <p style="text-align: center;" class="MsoNormal"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGuLtBX-JY1EiMFfKbOhJXTC4C3WZpdvR91qqnwXRVJ5M_bKQNaJVCUrayPrECPbCblPZwYO5kK-OyltckFxXxAXnggCW61Pe4JhxQCK8A4fQiodxQAspJPrtkYZkYOZyWXnWZkBkKsmk/s1600/B+r%3D07.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 278px; height: 278px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGuLtBX-JY1EiMFfKbOhJXTC4C3WZpdvR91qqnwXRVJ5M_bKQNaJVCUrayPrECPbCblPZwYO5kK-OyltckFxXxAXnggCW61Pe4JhxQCK8A4fQiodxQAspJPrtkYZkYOZyWXnWZkBkKsmk/s320/B+r%3D07.PNG" alt="" id="BLOGGER_PHOTO_ID_5495810003573250418" border="0" /></a>r = 0.7<br /></p> <p class="MsoNormal">Note that it is inverted and this is true for real images.</p> <p class="MsoNormal">Making the size of the aperture smaller, we get…</p> <p style="text-align: center;" class="MsoNormal"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgpTMrQLqSO9FId1c5-wlAOLRbWtcnav7sl-HxGyJUi2sgbYoID7b70ZmoCFNXzCrr3mU8ZKeJDwS2B7TfCvYJ9NlSPaM35TpIe6OHbqrmIKweTh8KeBhPYDSXlsmCZs_tgL_KJlOLU8Ok/s1600/B+r%3D04.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 261px; height: 261px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgpTMrQLqSO9FId1c5-wlAOLRbWtcnav7sl-HxGyJUi2sgbYoID7b70ZmoCFNXzCrr3mU8ZKeJDwS2B7TfCvYJ9NlSPaM35TpIe6OHbqrmIKweTh8KeBhPYDSXlsmCZs_tgL_KJlOLU8Ok/s320/B+r%3D04.PNG" alt="" id="BLOGGER_PHOTO_ID_5495810009739233042" border="0" /></a>r = 0.4<br /></p> <p style="text-align: center;" class="MsoNormal"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiz0FiZQ_Xz8TsqDuLz6YVSxOp8bc49KQVe4F8SfR4yzIcNKIhFaJW69KW-W9rBG8On5CBcsQisIBZrJZATDAEZQVk7OnVZJIcqsnPo9MW3OWyDFckjcsTT5n0PCdmzs9smBMfaREZrdII/s1600/B+r%3D025.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 277px; height: 278px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiz0FiZQ_Xz8TsqDuLz6YVSxOp8bc49KQVe4F8SfR4yzIcNKIhFaJW69KW-W9rBG8On5CBcsQisIBZrJZATDAEZQVk7OnVZJIcqsnPo9MW3OWyDFckjcsTT5n0PCdmzs9smBMfaREZrdII/s320/B+r%3D025.PNG" alt="" id="BLOGGER_PHOTO_ID_5495810013659539586" border="0" /></a>r = 0.25<br /></p> <p style="text-align: center;" class="MsoNormal"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrCt5bRLN688RIZEb4C8ieEuSXKwEDsS5dZIs0ukrPLypPuR4_Zze9ccIjr8yRyv6lba8Gc9u0CVCaCxMAiqHHl5sXEzhYWeZZ-6eagYf6PieAOhiqsbpZiu9tWRjl6x1SCUHzFG4ZnIs/s1600/B+r%3D01.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 261px; height: 261px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrCt5bRLN688RIZEb4C8ieEuSXKwEDsS5dZIs0ukrPLypPuR4_Zze9ccIjr8yRyv6lba8Gc9u0CVCaCxMAiqHHl5sXEzhYWeZZ-6eagYf6PieAOhiqsbpZiu9tWRjl6x1SCUHzFG4ZnIs/s320/B+r%3D01.PNG" alt="" id="BLOGGER_PHOTO_ID_5495810022110641202" border="0" /></a>r = 0.1<br /></p><p class="MsoNormal">The image quality reduces when the lens aperture becomes smaller and smaller because less and less rays are able to pass through it. The more rays the lens can collect, the better the image quality.</p> <p class="MsoNormal"><o:p> </o:p></p> <p class="MsoNormal">Part C. Template Matching using correlation</p> <p class="MsoNormal">Template matching is basically a type of pattern recognition in which it will determine matches between the test object and the template.</p> <p class="MsoNormal">For this part, we created the white texts in black background of: “THE RAIN IN SPAIN STAYS MAINLY IN THE PLAIN.”</p> <p style="text-align: center;" class="MsoNormal"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgd7tJlnoRo6Le7BwenK4Xfvau7oGZsnsRNPjV5FZd5mxTIARHYvCdstUKq_cj1ENRAeSS_U9W6CqqN8qEJcvJotDw0CRftZlArWyMs5BiHKWeuITOq0ZuvLRepm5Gzw76KZfZThWH4ZPY/s1600/text.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 128px; height: 128px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgd7tJlnoRo6Le7BwenK4Xfvau7oGZsnsRNPjV5FZd5mxTIARHYvCdstUKq_cj1ENRAeSS_U9W6CqqN8qEJcvJotDw0CRftZlArWyMs5BiHKWeuITOq0ZuvLRepm5Gzw76KZfZThWH4ZPY/s320/text.PNG" alt="" id="BLOGGER_PHOTO_ID_5495812189592476450" border="0" /></a>text<br /></p><p class="MsoNormal">and our template will be the letter “A” with the same font style and size as in our text:</p> <p style="text-align: center;" class="MsoNormal"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3HSRj4Fv90ds_Ydmie9nwBsYHssMTZFiqyKj6YugilLECWpwF9uNIHOoV2HO-Ivk6gDrSE5kR7dJT-AZx_9CwyOet5BSF3TDuDJgxdYVRCzandDkCIelwi2QvIzfzkCw1PpCvKIXEF0s/s1600/A6C.bmp"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 128px; height: 128px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3HSRj4Fv90ds_Ydmie9nwBsYHssMTZFiqyKj6YugilLECWpwF9uNIHOoV2HO-Ivk6gDrSE5kR7dJT-AZx_9CwyOet5BSF3TDuDJgxdYVRCzandDkCIelwi2QvIzfzkCw1PpCvKIXEF0s/s320/A6C.bmp" alt="" id="BLOGGER_PHOTO_ID_5495812197260223266" border="0" /></a>template<br /></p><p class="MsoNormal">We get the correlation of these two by multiplying the FT of A and the conjugate of the FT of the text and then inverse Fourier transforming by using ifft().<br /></p><p class="MsoNormal"><span style="color: rgb(0, 102, 0);"></span></p><blockquote><span style="color: rgb(0, 102, 0);">T = gray_imread('C:\text.PNG');</span><br /><span style="color: rgb(0, 102, 0);">A = gray_imread('C:\A.bmp');</span><br /><span style="color: rgb(0, 102, 0);">FT = fft2(T);</span><br /><span style="color: rgb(0, 102, 0);">FA = fft2(A);</span><br /><span style="color: rgb(0, 102, 0);">FTconj = conj(FT);</span><br /><span style="color: rgb(0, 102, 0);">FRA = FA.*FTconj;</span><br /><span style="color: rgb(0, 102, 0);">IRA = ifft(FRA);</span><br /><span style="color: rgb(0, 102, 0);">imshow(abs(IRA), []);</span><br /></blockquote>This is what I got:<p></p> <p style="text-align: center;" class="MsoNormal"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgd2CjqDSh1xev2kilgkUH3Qi6MQW4oypCPQ97EQ4u-MURsGDt9u5S44oQeJ0wfoDnyX-6UsaEuUi-d2Gzdo__4HimQrJW4WkZUsnppxu7JfhTsI24JK5iHkJNB1xE2eA1dirAwjzryjmc/s1600/Cifft.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 243px; height: 243px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgd2CjqDSh1xev2kilgkUH3Qi6MQW4oypCPQ97EQ4u-MURsGDt9u5S44oQeJ0wfoDnyX-6UsaEuUi-d2Gzdo__4HimQrJW4WkZUsnppxu7JfhTsI24JK5iHkJNB1xE2eA1dirAwjzryjmc/s320/Cifft.PNG" alt="" id="BLOGGER_PHOTO_ID_5495812201400964050" border="0" /></a>correlation of text and template using ifft<br /></p><p class="MsoNormal">It looked like the quadrants were reversed diagonally so I applied the fftshift after inverse FT-ing:</p><div style="text-align: left;"><blockquote style="color: rgb(0, 102, 0);">imshow(fftshift(abs(IRA)), []);<br /></blockquote></div><p style="text-align: center;" class="MsoNormal"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNqoGK-7iS2rH5m9KaPS3rsa76KTanFmy4dYWkhlLrpfYP43x76UuWQwwf_AZvNC84-04D_NOHUUNUMK2qFfWG8_GI4Kla8Pne4O6yIK5LlHwnAFOyHY-cycQIW5oYbrj7QqK0vbiNhZ8/s1600/Cifftshifted.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 263px; height: 263px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNqoGK-7iS2rH5m9KaPS3rsa76KTanFmy4dYWkhlLrpfYP43x76UuWQwwf_AZvNC84-04D_NOHUUNUMK2qFfWG8_GI4Kla8Pne4O6yIK5LlHwnAFOyHY-cycQIW5oYbrj7QqK0vbiNhZ8/s320/Cifftshifted.PNG" alt="" id="BLOGGER_PHOTO_ID_5495812205100275954" border="0" /></a>shifted correlation<br /></p><p class="MsoNormal">Now it looks inverted… so I tried using the fft2 instead of ifft:</p><div style="text-align: left;"></div><p style="text-align: center;" class="MsoNormal"></p><blockquote style="color: rgb(0, 102, 0);"><div style="text-align: left;">IRA = fft2(FRA);<br /></div><div style="text-align: left;">imshow(abs(IRA), []);<br /></div></blockquote><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9XjV_YN8MR15NQZ067B59_DN8q6xbjC_eJBhp9xhiHGebMw4krMVkjGi5lISxYOh7W5DVrBGjBaDoSniFoSmEckadvaA2v1QNyclKfxaU63-ZbjvFNQueaWW_fHwvMkufaDpSPzjR4EQ/s1600/Cfft2.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 249px; height: 249px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9XjV_YN8MR15NQZ067B59_DN8q6xbjC_eJBhp9xhiHGebMw4krMVkjGi5lISxYOh7W5DVrBGjBaDoSniFoSmEckadvaA2v1QNyclKfxaU63-ZbjvFNQueaWW_fHwvMkufaDpSPzjR4EQ/s320/Cfft2.PNG" alt="" id="BLOGGER_PHOTO_ID_5495813315242431954" border="0" /></a>correlation of text with template using ifft2<br /><p></p><p class="MsoNormal">and fftshifting…</p><p style="text-align: center;" class="MsoNormal"><br /></p><div style="text-align: left;"><blockquote style="color: rgb(0, 102, 0);">imshow(fftshift(abs(IRA)), []);<br /></blockquote></div><p style="text-align: center;" class="MsoNormal"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgIPIt21lS7Yo-ezUbkjH2UDICGuLizs8etlpwD26Mi8JsiSjLVjwFX935Hba1qLhCjFE_lz-E4ZZXpYuskZpr2ZIk0UPVa0E9fsiY2kCEI6q9bBWnzzALZwSYz020YLxO6pgczAJHawAk/s1600/Cshifted.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 259px; height: 260px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgIPIt21lS7Yo-ezUbkjH2UDICGuLizs8etlpwD26Mi8JsiSjLVjwFX935Hba1qLhCjFE_lz-E4ZZXpYuskZpr2ZIk0UPVa0E9fsiY2kCEI6q9bBWnzzALZwSYz020YLxO6pgczAJHawAk/s320/Cshifted.PNG" alt="" id="BLOGGER_PHOTO_ID_5495813324544041138" border="0" /></a>shifted correlation<br /></p><p class="MsoNormal">Now this looks more correct. The original text could be made out from this image but there seems to be bright spots were the letter “A” is present. Therefore the bright spots represent a match since these are the positions were the correlation is highest.</p> <p class="MsoNormal">I thought… what if the template is a “P” and there are “B”’s in the text… what would happen? So I made my own text:</p> <p style="text-align: center;" class="MsoNormal"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUEoMwUenVJrLM9Melcp2PoVq1FBO5OuxK6pqFVeUDEPD-ARnwCaOWRHDG6pws8kRv85n4ti4p2QTqVSy52-Ud71-yiM89r0PauC3JLfLCoGgDxJAvpTrP3fF8nP-ev8slLGNzEkUoVD0/s1600/text2.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 128px; height: 128px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUEoMwUenVJrLM9Melcp2PoVq1FBO5OuxK6pqFVeUDEPD-ARnwCaOWRHDG6pws8kRv85n4ti4p2QTqVSy52-Ud71-yiM89r0PauC3JLfLCoGgDxJAvpTrP3fF8nP-ev8slLGNzEkUoVD0/s320/text2.PNG" alt="" id="BLOGGER_PHOTO_ID_5495813334990342738" border="0" /></a>text 2<br /></p> <p class="MsoNormal">And my own template:</p> <p style="text-align: center;" class="MsoNormal"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEixtU6c6O2TYmfyBbBraqUswzBf5NybuFa2qWYD1pBiXARaawWK3yR1L8U2uGKJNe4buY-RE8_9r37dCwhUt_T9pq5qa_gzbgMuuzxBVvCVYgRif-NN7WzXRuknnKgJ9eWPXo0l30vkC34/s1600/P.bmp"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 128px; height: 128px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEixtU6c6O2TYmfyBbBraqUswzBf5NybuFa2qWYD1pBiXARaawWK3yR1L8U2uGKJNe4buY-RE8_9r37dCwhUt_T9pq5qa_gzbgMuuzxBVvCVYgRif-NN7WzXRuknnKgJ9eWPXo0l30vkC34/s320/P.bmp" alt="" id="BLOGGER_PHOTO_ID_5495813343978374882" border="0" /></a>template 2<br /></p><p class="MsoNormal">And the correlation is…</p> <p style="text-align: center;" class="MsoNormal"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcnjn1tSyYvyi4ucQeOn0aXEagMUr68w2vYO6WjQozs4L67ITylUdiFl_BgvV1dS_hfQccTstsS3aUGXxTjignP5WguaKLGbUUMiXLjYjmrqakM9p3Fo2CJXRLZI6WcRV7YyFMneEk1is/s1600/Climitation.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 229px; height: 229px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcnjn1tSyYvyi4ucQeOn0aXEagMUr68w2vYO6WjQozs4L67ITylUdiFl_BgvV1dS_hfQccTstsS3aUGXxTjignP5WguaKLGbUUMiXLjYjmrqakM9p3Fo2CJXRLZI6WcRV7YyFMneEk1is/s320/Climitation.PNG" alt="" id="BLOGGER_PHOTO_ID_5495814192531087762" border="0" /></a>limitation of method<br /></p><p class="MsoNormal">It can be seen that despite there is only one capital “P”, there are multiple bright spots. This is because the other letters like “B” looks very similar to P except that it has an extra part at the bottom. The other letters also have parts that are similar to “P” so they have a high correlation. Therefore this shows the limitation of the technique.</p><p class="MsoNormal"><br /></p><p class="MsoNormal">Part D. Edge detection using the convolution integral</p><p class="MsoNormal">We were asked to make a 3x3 matrix pattern of edges such that the sum of all the elements is zero. Then we convolved this with the "VIP" image using imcorrcoef():</p><p class="MsoNormal">For the matrix:</p><p class="MsoNormal">[-1 -1 -1</p><p class="MsoNormal"> 2 2 2</p><p class="MsoNormal"> -1 -1 -1]<br /></p><p class="MsoNormal">We get:</p><p style="text-align: center;" class="MsoNormal"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhqNzPtCRlLNp5OINCvOM3XboAtx0JdIxmx28VuPEQjsompzoy-YaPhSxz0DSh8rcP8TqOuqpDmuNKYU8_OuuNxGVEDZEBhVSBX3uzfORp81FCjILK1lUdNbZD1YhlLieJ7IyelCTMmzx4/s1600/Dhorizontal.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 166px; height: 166px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhqNzPtCRlLNp5OINCvOM3XboAtx0JdIxmx28VuPEQjsompzoy-YaPhSxz0DSh8rcP8TqOuqpDmuNKYU8_OuuNxGVEDZEBhVSBX3uzfORp81FCjILK1lUdNbZD1YhlLieJ7IyelCTMmzx4/s320/Dhorizontal.PNG" alt="" id="BLOGGER_PHOTO_ID_5495817409497443986" border="0" /></a>convolved image<br /></p>We can see that the horizontal edges of the image are brighter. Also note that the matrix has the same values horizontally. What this does it that it scans the image and tries to match its edges with the matrix.<br /><br />For the vertical matrix:<br />[-1 2 -1<br /> -1 2 -1<br /> -1 2 -1]<br /><br />We get:<br /><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjBJYdeVedS6kVaqpYe5hTKUxCO-Y4OO92fTANp5jnzCa8-nTncpwKYYgu2_Te9NQOi3fLnb0DJtFAff81yLBEHJdbE9vbhwFowH_FTPVebNLlntsfRdr7KNZjJkTo0CwekY2dOxu7cxR4/s1600/Dvertical.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 225px; height: 225px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjBJYdeVedS6kVaqpYe5hTKUxCO-Y4OO92fTANp5jnzCa8-nTncpwKYYgu2_Te9NQOi3fLnb0DJtFAff81yLBEHJdbE9vbhwFowH_FTPVebNLlntsfRdr7KNZjJkTo0CwekY2dOxu7cxR4/s320/Dvertical.PNG" alt="" id="BLOGGER_PHOTO_ID_5495817412760891650" border="0" /></a>convolved image<br /><br /><div style="text-align: left;">This time, the vertical edges of the image are brighter :D<br /><br />For the spot pattern:<br />[-1 -1 -1<br /> -1 8 -1<br /> -1 -1 -1] :<br /><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEirQrRHfmZL36Wml0_KDtr23epkiPpf944XGhDCtVQpGxyFn8gPA8LXIKK4cHQqnENsSjlIV4wNYdEvgsnSHAbRGWH3BZp14rgLS4MnalZ7qLKc6GXFsGnP_DX4a1rIhexLkpkedoDbhp0/s1600/Dspot.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 237px; height: 238px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEirQrRHfmZL36Wml0_KDtr23epkiPpf944XGhDCtVQpGxyFn8gPA8LXIKK4cHQqnENsSjlIV4wNYdEvgsnSHAbRGWH3BZp14rgLS4MnalZ7qLKc6GXFsGnP_DX4a1rIhexLkpkedoDbhp0/s320/Dspot.PNG" alt="" id="BLOGGER_PHOTO_ID_5495817417393301266" border="0" /></a>convolved image<br /><br /><div style="text-align: left;">This time, all of the edges of the image are bright. This is because in the pattern, all of the edges have the same value.<br /><br />The code for this is:<br /><blockquote><span style="color: rgb(0, 102, 0);">T = gray_imread("C:\VIP.bmp");<br /><br /></span><span style="color: rgb(0, 102, 0);">pattern = [-1 -1 -1; 2 2 2; -1 -1 -1]</span>;<br /><br /><span style="color: rgb(0, 102, 0);">F = imcorrcoef(T, pattern);</span><br /><br /><span style="color: rgb(0, 102, 0);">imshow(F, []);</span><br /></blockquote><br />And that wraps up the activity. :)<br /><br />For the score, I give myself a 10/10 for producing the required output and understanding the lesson. Plus 2 points for testing the limitations of the technique of correlation, which gives a total of...<br /><br /><span style="font-weight: bold;">Score: 12/10<br /><br /></span>Lastly, I would like to acknowledge Dr. Soriano for the helpful discussions. :D<br /><br /><br />- Dennis<br /><br />References:<br />1. M. Soriano, "A6 - Fourier Transform Model of Image Formation"<br /><span style="font-weight: bold;"></span></div></div></div> </div>dennisivan89http://www.blogger.com/profile/04476991777095665795noreply@blogger.com0tag:blogger.com,1999:blog-7345763871585817117.post-67595453559275362010-07-07T20:49:00.000-07:002010-09-23T08:47:13.438-07:00AP 186 Activity 5: Enhancement by Histogram ManipulationIn this activity we will be modifying the histogram of the image in order to enhance its quality and improve certain image features. This can be done by mapping the graylevel values of the image such that the new image will have the desired cumulative distribution function (CDF).<br /><br />I've chosen this picture:<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgH7T2WD7trRbh0VuzNcKo8FlT7mrpQCHKMW7gcq46SN9DJ0x8uJhq67KjCUOV7IGmFb8_s9nUQAr5QA7P_HNlfOUowgKRhz5nDerLJV5qmNGh1kpz7XPBzFdpreqY6T3Dr7DKlyz_O0cU/s1600/test1.jpg"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 287px; height: 215px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgH7T2WD7trRbh0VuzNcKo8FlT7mrpQCHKMW7gcq46SN9DJ0x8uJhq67KjCUOV7IGmFb8_s9nUQAr5QA7P_HNlfOUowgKRhz5nDerLJV5qmNGh1kpz7XPBzFdpreqY6T3Dr7DKlyz_O0cU/s320/test1.jpg" alt="" id="BLOGGER_PHOTO_ID_5491380992823776146" border="0" /></a><br />and I ran the following code in Scilab:<br /><blockquote style="color: rgb(0, 102, 0);">stacksize(10000000);<br />A = gray_imread("C:\test1.jpg");<br />B = tabul(A, "i");<br />B1 = B(:,1);<br />B2 = B(:,2);<br />size(A);<br />s = 540*720;<br />B2norm = B2/s;<br />B2cumsum = cumsum(B2norm);<br />A1d = A(:);<br />yCDF = interp1(B1, B2cumsum, A1d);<br />xdesired = interp1(B1, B1, yCDF);<br />Aedited = matrix(xdesired, [540, 720]);<br />imwrite(Aedited, "C:\test1modified.png");</blockquote>Basically what this code does is it loads the image into scilab, then it gets the image's normalized histogram and CDF. Then, it interpolates in order to get the y values in the image's CDF. After that it interpolates once again in order to get the grayscale value having this CDF value in the desired CDF. All the pixels in the image are backprojected and replaced by the x-values of the desired CDF.<br /><br />In this case, the desired CDF is a line with slope = 1, that is, its PDF is just a uniform distribution. Executing the code above, I get:<br /><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh9ZCW0uoQR1kwsGxSBAJ9h_zxdLgTMfqZE3ri5e7j6_xb8s_zYp7BttHsOAUUcXQpaIIq_Pj98zutgarTzyN5y_KmIN4fHj2AZUQXBN3Zo1hRlmdzUDlylI8dGOw60JYv0khHeefvgPUs/s1600/unnormedhist.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 285px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh9ZCW0uoQR1kwsGxSBAJ9h_zxdLgTMfqZE3ri5e7j6_xb8s_zYp7BttHsOAUUcXQpaIIq_Pj98zutgarTzyN5y_KmIN4fHj2AZUQXBN3Zo1hRlmdzUDlylI8dGOw60JYv0khHeefvgPUs/s320/unnormedhist.PNG" alt="" id="BLOGGER_PHOTO_ID_5491386524043773378" border="0" /></a>histogram of the image (not normalized)<br /><br /><br /></div><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUKb-AE2RDXpMTsEFXrxqWtjPylPNgb6jcvlBJU72gqD418FkFIp6KpIkzqHOe3-gJoTGVXJcJU-J-AWM29FARe8_P9wTk_2AGLTEmnC5-NysNpIFvCu0Dz19bNG1rMFsnIk76BHJ-do0/s1600/normedhist.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 284px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUKb-AE2RDXpMTsEFXrxqWtjPylPNgb6jcvlBJU72gqD418FkFIp6KpIkzqHOe3-gJoTGVXJcJU-J-AWM29FARe8_P9wTk_2AGLTEmnC5-NysNpIFvCu0Dz19bNG1rMFsnIk76BHJ-do0/s320/normedhist.PNG" alt="" id="BLOGGER_PHOTO_ID_5491386532336139954" border="0" /></a>normalized histogram of the image<br /></div><br /><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1cKq28svp_Jdy0yIvQVBvRcnnNGPggoQcLZfnP0xPcB0q10S6UEFS0EiyiAhyqQu41swihcz0Y43svXdGN80jh-0gDx8bGN7GBA9pr77NfAbUY2okiSy05w7HzUFS_xKqYudMQpvbgPc/s1600/test1modified.png"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 377px; height: 282px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1cKq28svp_Jdy0yIvQVBvRcnnNGPggoQcLZfnP0xPcB0q10S6UEFS0EiyiAhyqQu41swihcz0Y43svXdGN80jh-0gDx8bGN7GBA9pr77NfAbUY2okiSy05w7HzUFS_xKqYudMQpvbgPc/s320/test1modified.png" alt="" id="BLOGGER_PHOTO_ID_5491386544265731042" border="0" /></a>Histogram equalized image<br /><br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjlZwcM4WNDJBMCGMCXIu9-NWZwY4CtjyLo8GFpnd2XrxiNipRY2wd_KHZobnPiQRYVgEcSYRkYqt4IDsWba5AYqR7bdES0EMaKG3JHsh9lZdzVQlRYozQ39puUpa8nXkMgq-0iO7gA5g4/s1600/test1convert2gray.png"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 374px; height: 279px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjlZwcM4WNDJBMCGMCXIu9-NWZwY4CtjyLo8GFpnd2XrxiNipRY2wd_KHZobnPiQRYVgEcSYRkYqt4IDsWba5AYqR7bdES0EMaKG3JHsh9lZdzVQlRYozQ39puUpa8nXkMgq-0iO7gA5g4/s320/test1convert2gray.png" alt="" id="BLOGGER_PHOTO_ID_5491388000729279426" border="0" /></a>Original grayscaled image<br /><br /><div style="text-align: left;">and comparing the CDF's before and after:<br /><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjpUfystgFN4e_30S6xlnAyErChRV9_6iVFoE8y5-WBQFrhv9eie8AIeFJtBVOcsn0eQ-cBO3myePHGs0gVEc7gZsTPT40xhVheFBnEKnZ1H6tpaKE9nCeS4i91T3k_FYFVmBJOFdGPRb0/s1600/CDF.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 245px; height: 217px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjpUfystgFN4e_30S6xlnAyErChRV9_6iVFoE8y5-WBQFrhv9eie8AIeFJtBVOcsn0eQ-cBO3myePHGs0gVEc7gZsTPT40xhVheFBnEKnZ1H6tpaKE9nCeS4i91T3k_FYFVmBJOFdGPRb0/s320/CDF.PNG" alt="" id="BLOGGER_PHOTO_ID_5491386555619319378" border="0" /></a>CDF before enhancement<br /><br /><br /></div><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrMLQcQsDnHDkvvhqRBF1rMqFESD01JdJHWC_Kcq1QWapTmRhWOL4vXhhN_pkREzZEjBXrzbf1q3B2dLWIHTWt00XPYJZGEvKxL3AoPQOhufo46kxztKOUzHq_URKaQTWL7PTD072OZbM/s1600/CDFaftermodify.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 259px; height: 229px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrMLQcQsDnHDkvvhqRBF1rMqFESD01JdJHWC_Kcq1QWapTmRhWOL4vXhhN_pkREzZEjBXrzbf1q3B2dLWIHTWt00XPYJZGEvKxL3AoPQOhufo46kxztKOUzHq_URKaQTWL7PTD072OZbM/s320/CDFaftermodify.PNG" alt="" id="BLOGGER_PHOTO_ID_5491386535113066226" border="0" /></a>CDF after enhancement<br /><br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjfL9il9zYqpHydSXpeupqHkPz7XdZIqIcYlg0Fh2GQq-RUA8VtPwk-6OWLyxg0anqq-GGfCt5GP2Vwwbj33zkmOvH0w8_mLnWXjKXcWP0Oc8wQqKFFCxNBHQPHod9ArE49A0nwVbkgIfY/s1600/PDFaftermodify.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 284px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjfL9il9zYqpHydSXpeupqHkPz7XdZIqIcYlg0Fh2GQq-RUA8VtPwk-6OWLyxg0anqq-GGfCt5GP2Vwwbj33zkmOvH0w8_mLnWXjKXcWP0Oc8wQqKFFCxNBHQPHod9ArE49A0nwVbkgIfY/s320/PDFaftermodify.PNG" alt="" id="BLOGGER_PHOTO_ID_5491427535256876866" border="0" /></a>PDF after enhancement<br /><br /></div></div></div><br />It is noticeable that the modified image has a higher contrast than the original. The light colored pixels seem to become lighter and the dark pixels seem to become darker. It also looks like that the "gray fog" over the original picture has been removed. The image is called histogram equalized image because we have modified its histogram such that every gray level the original image possess now have equal probability. Thanks to this, the picture is now brightened up a bit. :)<br /><br />Also, the CDF of the enhanced image is a straight line and that was our desired CDF. Note that there's a small horizontal segment. This is because in the histogram of the original image, there's a range of grayscale values where no or very little pixels possess. This can also be seen in the modified PDF.<br /><br />Next, I tried the technique on different CDF's. The first one is normal distribution: (mean = 0.5, std = 0.1)<br /><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh9nSFL8dOKDCGRQoNiZv2j_aPGe-KG9L3SE4yOAr5ZL5o0k3xdI3sHRUUbxu_2jadd11wrWlN07wmhsRvIdMWGst1jPmcnIW9pBVuqOePu6zS-hY-QaA8hvDdfFTSu8OWaN1Se4La07wk/s1600/unnormedchosenhist.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 274px; height: 245px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh9nSFL8dOKDCGRQoNiZv2j_aPGe-KG9L3SE4yOAr5ZL5o0k3xdI3sHRUUbxu_2jadd11wrWlN07wmhsRvIdMWGst1jPmcnIW9pBVuqOePu6zS-hY-QaA8hvDdfFTSu8OWaN1Se4La07wk/s320/unnormedchosenhist.PNG" alt="" id="BLOGGER_PHOTO_ID_5491430220408840722" border="0" /></a>histogram of normal distribution<br /><br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRSyhneXqNhXQYBjNqeX_uBV77lYES6qe1Q8VsMAWCkhyphenhyphen04qxwc_d-AlEuYFgZ6u-mUZyR9GzWWEgxSM16AMlW56c2xGFbiqscZvQU-gN9-WcctoOjSvS386uiv4Q38iZ9ZnpGGI5-8F4/s1600/CDFwanted.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 285px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRSyhneXqNhXQYBjNqeX_uBV77lYES6qe1Q8VsMAWCkhyphenhyphen04qxwc_d-AlEuYFgZ6u-mUZyR9GzWWEgxSM16AMlW56c2xGFbiqscZvQU-gN9-WcctoOjSvS386uiv4Q38iZ9ZnpGGI5-8F4/s320/CDFwanted.PNG" alt="" id="BLOGGER_PHOTO_ID_5491430211480674098" border="0" /></a>CDF of normal distribution<br /><div style="text-align: left;"><br />The code was slightly changed:<br /><blockquote style="color: rgb(0, 102, 0);">A = gray_imread("C:\test1.jpg");<br />B = tabul(A, "i");<br />B1 = B(:,1);<br />B2 = B(:,2);<br />size(A);<br />s = 540*720;<br />B2norm = B2/s;<br />B2cumsum = cumsum(B2norm);<br />A1d = A(:);<br /><br />y = grand(1, s, 'nor', 0.5, 0.1);<br />C = tabul(y, "i");<br />C1 = C(:,1);<br />C2 = C(:,2);<br />C2norm = C2/s;<br />C2cumsum = cumsum(C2norm);<br /><br />yCDF = interp1(B1, B2cumsum, A1d);<br />xdesired = interp1(C2cumsum, C1, yCDF);<br />Aedited = matrix(xdesired, [540, 720]);<br />imwrite(Aedited, "C:\test1modified.png");</blockquote><br />And the resulting image is:<br /><br /></div><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9xrO1WwA0OWy4DvB9OUzkOc4nfHS-qg-XJRzh37ZO4sgdTCKCBNxuxCg2gw0MkIMoU6ZFY2wpVoivLinBPpXfnBAg8Dwi67t0kwdxkqIubQgNEyLHZdMLF9OKj85TF_el7inaHCiAkwQ/s1600/test1modified2.png"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 274px; height: 205px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9xrO1WwA0OWy4DvB9OUzkOc4nfHS-qg-XJRzh37ZO4sgdTCKCBNxuxCg2gw0MkIMoU6ZFY2wpVoivLinBPpXfnBAg8Dwi67t0kwdxkqIubQgNEyLHZdMLF9OKj85TF_el7inaHCiAkwQ/s320/test1modified2.png" alt="" id="BLOGGER_PHOTO_ID_5491430232151151074" border="0" /></a>Histogram manipulated image<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjlZwcM4WNDJBMCGMCXIu9-NWZwY4CtjyLo8GFpnd2XrxiNipRY2wd_KHZobnPiQRYVgEcSYRkYqt4IDsWba5AYqR7bdES0EMaKG3JHsh9lZdzVQlRYozQ39puUpa8nXkMgq-0iO7gA5g4/s1600/test1convert2gray.png"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 283px; height: 210px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjlZwcM4WNDJBMCGMCXIu9-NWZwY4CtjyLo8GFpnd2XrxiNipRY2wd_KHZobnPiQRYVgEcSYRkYqt4IDsWba5AYqR7bdES0EMaKG3JHsh9lZdzVQlRYozQ39puUpa8nXkMgq-0iO7gA5g4/s320/test1convert2gray.png" alt="" id="BLOGGER_PHOTO_ID_5491388000729279426" border="0" /></a>Original image<br /><br /><div style="text-align: left;">Personally, I don't think using the histogram manipulated image is of better quality than the original image; it looks more hazy and less contrasted than the original. This is because for the normal distribution, most of its elements are concentrated near the mean and the standard deviation used here is quite small, meaning the pixels are concentrated around a range of graylevel values, which explains image's low contrast.<br /><br />Like our first case, the histogram and CDF of the modified image resembles the desired one:<br /><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDLaq2O0go5TiTe7noviB6G0fFGWewkwGQBJpap5yRomA6GI9pLiJFiKNb_B6cBNtKj7f68qz0JO8rXzqVS-HyChkf_x5YSvblRFzTdQ4oAhX7_6MM3jseDCX1x1MkLg26E4y3Jd9oC1U/s1600/PDFaftermodify2.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 234px; height: 209px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDLaq2O0go5TiTe7noviB6G0fFGWewkwGQBJpap5yRomA6GI9pLiJFiKNb_B6cBNtKj7f68qz0JO8rXzqVS-HyChkf_x5YSvblRFzTdQ4oAhX7_6MM3jseDCX1x1MkLg26E4y3Jd9oC1U/s320/PDFaftermodify2.PNG" alt="" id="BLOGGER_PHOTO_ID_5491431115487936722" border="0" /></a>histogram of modified image<br /><br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiva65zwFlsPFWZWpTVK3eI8w__Sl2ooayqZLezY7Ku2eGemFNUllsBgdWw8-xVKWSy8Acl2AhWjnYg5AcAgukFa08rHk13OyFlRbuyrdFnXxUJtGwS7SsLp5ViSeCfPCX-Ow4dkmdltL0/s1600/CDFaftermodify2.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 245px; height: 219px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiva65zwFlsPFWZWpTVK3eI8w__Sl2ooayqZLezY7Ku2eGemFNUllsBgdWw8-xVKWSy8Acl2AhWjnYg5AcAgukFa08rHk13OyFlRbuyrdFnXxUJtGwS7SsLp5ViSeCfPCX-Ow4dkmdltL0/s320/CDFaftermodify2.PNG" alt="" id="BLOGGER_PHOTO_ID_5491430241505833042" border="0" /></a>CDF of modified image<br /><br /><div style="text-align: left;">Next, I tried the exponential distribution:<br /><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiuWkoqTZw8QT0MCMmTrXnBqw49dfTKzfYSlSS89IWXYtC620uqqwieAU8TGfbBTfwBeHnI4IAefhfzdXQ1GEF1JdL6-8Fgv3M_K46g07-mWnT5fIJhUpDz-0FV6PxChf0E6EbT38G8m5E/s1600/unnormedchosenhist2.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 259px; height: 229px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiuWkoqTZw8QT0MCMmTrXnBqw49dfTKzfYSlSS89IWXYtC620uqqwieAU8TGfbBTfwBeHnI4IAefhfzdXQ1GEF1JdL6-8Fgv3M_K46g07-mWnT5fIJhUpDz-0FV6PxChf0E6EbT38G8m5E/s320/unnormedchosenhist2.PNG" alt="" id="BLOGGER_PHOTO_ID_5491437430763606658" border="0" /></a>Histogram of exponential distribution<br /><br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwApDwgA_H6jNNKg-fWoY8pi7sdOoJyptyNcmIU4PkaCGTT3RNc-2a7zH5mSE-EaRjxV0MaZK_xO0UQxlGmJsxdBh2XKW7gUEQG6dPqgildFCcWf1_EBhI3GJ2hyIOG4X22csayiAc_OU/s1600/CDFwanted2.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 285px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwApDwgA_H6jNNKg-fWoY8pi7sdOoJyptyNcmIU4PkaCGTT3RNc-2a7zH5mSE-EaRjxV0MaZK_xO0UQxlGmJsxdBh2XKW7gUEQG6dPqgildFCcWf1_EBhI3GJ2hyIOG4X22csayiAc_OU/s320/CDFwanted2.PNG" alt="" id="BLOGGER_PHOTO_ID_5491437438710493490" border="0" /></a>CDF of exponential distribution<br /><br /><div style="text-align: left;">And the result is:<br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1U-hzAQmkUWMO3eiug3SlNwo5KlXB5jEpMqws-aOV8iM91VvPWhMKNyQuUOJS136eAXy6lXmoXBloRVb_6ULgekJt-OfE9hr-WKwpt0Zc4YbmFaHQoxmlVfsXwtp9anFw8EgKp6PRafc/s1600/test1modified3.png"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 240px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1U-hzAQmkUWMO3eiug3SlNwo5KlXB5jEpMqws-aOV8iM91VvPWhMKNyQuUOJS136eAXy6lXmoXBloRVb_6ULgekJt-OfE9hr-WKwpt0Zc4YbmFaHQoxmlVfsXwtp9anFw8EgKp6PRafc/s320/test1modified3.png" alt="" id="BLOGGER_PHOTO_ID_5491446596549994306" border="0" /></a>histogram manipulated image<br /></div><div style="text-align: center;"><br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjlZwcM4WNDJBMCGMCXIu9-NWZwY4CtjyLo8GFpnd2XrxiNipRY2wd_KHZobnPiQRYVgEcSYRkYqt4IDsWba5AYqR7bdES0EMaKG3JHsh9lZdzVQlRYozQ39puUpa8nXkMgq-0iO7gA5g4/s1600/test1convert2gray.png"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 283px; height: 210px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjlZwcM4WNDJBMCGMCXIu9-NWZwY4CtjyLo8GFpnd2XrxiNipRY2wd_KHZobnPiQRYVgEcSYRkYqt4IDsWba5AYqR7bdES0EMaKG3JHsh9lZdzVQlRYozQ39puUpa8nXkMgq-0iO7gA5g4/s320/test1convert2gray.png" alt="" id="BLOGGER_PHOTO_ID_5491388000729279426" border="0" /></a>original image<br /><br /><div style="text-align: left;">The manipulated image appears a lot darker than the original image because due to the exponential distribution, the pixels are concentrated at the left of the histogram, meaning there are now more pixels having darker values.<br /><br />And the histogram and CDF of the modified image are:<br /><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEizFCgPxUCf9dXfQ3bLeK57u6dQ_1pDk8lrBDF8i0YvgMfcxOOuGk4t0fYWIzACnO1CqxbCdMGkR7USmxUQRViTiJS3pielypDJ8wx7wjZowFoQPTlgve4X0-l7iRe15yvRCXQ_I0Gtems/s1600/PDFaftermodify3.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 261px; height: 233px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEizFCgPxUCf9dXfQ3bLeK57u6dQ_1pDk8lrBDF8i0YvgMfcxOOuGk4t0fYWIzACnO1CqxbCdMGkR7USmxUQRViTiJS3pielypDJ8wx7wjZowFoQPTlgve4X0-l7iRe15yvRCXQ_I0Gtems/s320/PDFaftermodify3.PNG" alt="" id="BLOGGER_PHOTO_ID_5491446600185291682" border="0" /></a>histogram of manipulated image<br /><br /><br /></div><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhindXmyBPSGFMVymt3PD0MFGT93GVBAPkhEBGY1NH_C4iwMKdRyEG2Ueasg5wCEl6R8DZAFVQC4yZ0GA3FG8a2T9VdVgalbWK82VFWQL7TRgKlYTpw6DzeUkkfjcx6n2DqREbtA1hmfpY/s1600/CDFaftermodify3.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 260px; height: 231px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhindXmyBPSGFMVymt3PD0MFGT93GVBAPkhEBGY1NH_C4iwMKdRyEG2Ueasg5wCEl6R8DZAFVQC4yZ0GA3FG8a2T9VdVgalbWK82VFWQL7TRgKlYTpw6DzeUkkfjcx6n2DqREbtA1hmfpY/s320/CDFaftermodify3.PNG" alt="" id="BLOGGER_PHOTO_ID_5491446604195192306" border="0" /></a>CDF of manipulated image<br /><br /><div style="text-align: left;">Lastly, I used Photoshop to manipulate the histogram of the image:<br /><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWPCyIzxvgN08Rfs6gxwpnGhZIaj13noiEBiF_NzrQZqsRyTUQe7qRFb68ooicZZ-rX6DldKMg8Ru9-Nstpoj9RcOysUX_sbqk28WQ-At6iStEq4uu-xfzX6dwQ5QIHHJ4HHzCp3w02zo/s1600/photoshop.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 178px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWPCyIzxvgN08Rfs6gxwpnGhZIaj13noiEBiF_NzrQZqsRyTUQe7qRFb68ooicZZ-rX6DldKMg8Ru9-Nstpoj9RcOysUX_sbqk28WQ-At6iStEq4uu-xfzX6dwQ5QIHHJ4HHzCp3w02zo/s320/photoshop.PNG" alt="" id="BLOGGER_PHOTO_ID_5491454193728119074" border="0" /></a>Using Photoshop to manipulate the CDF<br /></div><div style="text-align: center;"><br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbNqzd-K9IXoCp_HNszesX8hxyDUzlOdbj-8dM6lqC5jNZycYYrmweetbMsWfnT6DP2IWRWYL8uP-FMbrLmcKr1QyIHQiU_VYDgwURCBvLbNCZDVQVtvpJxkWQ_7WCm8xzqmbDyrQCbNo/s1600/PSadjust.png"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 266px; height: 199px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbNqzd-K9IXoCp_HNszesX8hxyDUzlOdbj-8dM6lqC5jNZycYYrmweetbMsWfnT6DP2IWRWYL8uP-FMbrLmcKr1QyIHQiU_VYDgwURCBvLbNCZDVQVtvpJxkWQ_7WCm8xzqmbDyrQCbNo/s320/PSadjust.png" alt="" id="BLOGGER_PHOTO_ID_5491454201145144834" border="0" /></a>histogram manipulated image<br /><br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjlZwcM4WNDJBMCGMCXIu9-NWZwY4CtjyLo8GFpnd2XrxiNipRY2wd_KHZobnPiQRYVgEcSYRkYqt4IDsWba5AYqR7bdES0EMaKG3JHsh9lZdzVQlRYozQ39puUpa8nXkMgq-0iO7gA5g4/s1600/test1convert2gray.png"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 283px; height: 210px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjlZwcM4WNDJBMCGMCXIu9-NWZwY4CtjyLo8GFpnd2XrxiNipRY2wd_KHZobnPiQRYVgEcSYRkYqt4IDsWba5AYqR7bdES0EMaKG3JHsh9lZdzVQlRYozQ39puUpa8nXkMgq-0iO7gA5g4/s320/test1convert2gray.png" alt="" id="BLOGGER_PHOTO_ID_5491388000729279426" border="0" /></a>original image<br /></div><br />The image now is of higher contrast and it looks better! For me, its quality is better than the other histogram manipulated images. :D<br /><br />For the score, I give myself 10/10 for understanding the lesson and being able to produce the requirements.<br /><br /><span style="font-weight: bold;">Score:</span> <span style="font-weight: bold;">10/10<br /><span style="font-weight: bold;"><br /></span></span>Finally, I would like to thank Dr. Soriano, Joseph Bunao, Arvin Mabilangan<span><span>, BA Racoma, and Andy Polinar </span></span><span><span>for the insightful</span></span><span style="font-weight: bold;"><span style="font-weight: bold;"> </span></span><span><span>and helpful discussions. </span></span><span style="font-weight: bold;"><span style="font-weight: bold;"><br /></span></span><br />References:<br />1. M. Soriano, "A5 - Enhancement by Histogram Manipulation"<br /></div></div></div></div></div></div></div></div></div></div></div>dennisivan89http://www.blogger.com/profile/04476991777095665795noreply@blogger.com0tag:blogger.com,1999:blog-7345763871585817117.post-80214137229418632442010-06-27T00:20:00.000-07:002010-09-23T08:46:21.754-07:00AP 186 Activity 4: Area Estimate of Images with Defined EdgesThe objective of this activity is to be able to estimate the area of images that have defined edges using Green's theorem.<br /><br />First, we're asked to make a black and white image of a regular object with the object being white and the background colored black. The area of the object must be known in order to compare it with the results. So I made this 150 by 80 pixel white rectangle with it's upper left corner starting at 100, 100 (origin at upper left corner) using Paint.<br /><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUhqCicB-ZGvkOm3ZAh_HxpBo5K9OZRuM3UaYy2FHOqRALkvRsN4HzjbvJOJ5-IbhyTVDwwbrdehiQLAWpLdIR8nYfR84eOVxrXsmSxMePb8BE8M6acEDNi075Wsj7-nVhemO0uvnjrNM/s1600/shape150x80.bmp"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 151px; height: 116px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUhqCicB-ZGvkOm3ZAh_HxpBo5K9OZRuM3UaYy2FHOqRALkvRsN4HzjbvJOJ5-IbhyTVDwwbrdehiQLAWpLdIR8nYfR84eOVxrXsmSxMePb8BE8M6acEDNi075Wsj7-nVhemO0uvnjrNM/s320/shape150x80.bmp" alt="" id="BLOGGER_PHOTO_ID_5487355836430461154" border="0" /></a>white rectangle (150 x 80 pixels)<br /><br /></div>And as told, I saved it in BMP format rather than JPG. So the white rectangle has an area of 150 x 80 = <span style="font-weight: bold; color: rgb(204, 0, 0);">12,000 pixels</span>.<br /><br />Next, let's load this into scilab and compute for the area:<br /><blockquote>I = imread("C:\shape.bmp");<br />[x, y] = follow(I);<br />xiplus1 = x;<br />d = xiplus1(1);<br />xiplus1(1) = [];<br />xiplus1(452) = d;<br />yiplus1 = y;<br />e = yiplus1(1);<br />yiplus1(1) = [];<br />yiplus1(452) = e;<br /><br />A = 0.5 * sum((x .* yiplus1) - (y .* xiplus1))</blockquote>The removal and addition of the 1st and last elements on xiplus1 and yiplus1 are just to shift it one place. x and y contains 452 elements. And fortunately, the follow function gives out the parametrized contour vectors x and y, so x and y are in coordinate system (not rows and columns).<br /><br />I got the answer of <span style="font-weight: bold; color: rgb(204, 0, 0);">11,544 pixels</span> which has a<span style="color: rgb(204, 0, 0);"> <span style="font-weight: bold;">3.8</span></span><span style="font-weight: bold; color: rgb(204, 0, 0);">% error</span>:It's a good estimate since the error's under 5%; it's a fairly accurate technique. Although personally, I was expecting it to perform better since the shape was a simple rectangle.<br /><br /><div style="text-align: center;"><br /></div>Now let's try the area estimation on a real location. Using Google maps, I picked the Quezon City Circle, which is bounded by the Elliptical road.<br /><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZa5LjwsG9rXtP2djwSyu1V3UOf6XYFdE7pXJ3QIBY6p-YEUgKeRC3_Uv5MkHgCiMHfJF38EukVbGZMH_Oy2WgurbW78majgXpkSMWr09Y546NoHA3Y4vklWONoWle7u610IYA8xSCNp8/s1600/map_orig.bmp"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 511px; height: 295px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZa5LjwsG9rXtP2djwSyu1V3UOf6XYFdE7pXJ3QIBY6p-YEUgKeRC3_Uv5MkHgCiMHfJF38EukVbGZMH_Oy2WgurbW78majgXpkSMWr09Y546NoHA3Y4vklWONoWle7u610IYA8xSCNp8/s320/map_orig.bmp" alt="" id="BLOGGER_PHOTO_ID_5487425216610653090" border="0" /></a>Image of Quezon City circle taken from Google Maps (click to zoom in)<br /></div><br />Then using paint, I delineated the area of interest from the rest and the result was:<br /><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhs9qlfICJ04H5kwXijoDDIw5P95OSFL9xHIJLHZiujX9nuPdfuyuDQ4xndXG_A3XGvHa7j-GO0mS9f63ghrxDqMgMHFB_sTeNps6E-kbq9NkPOuLaPGriHQ5oBrzpPbMv7cGKVVAaky1Y/s1600/map_bw.bmp"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 111px; height: 122px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhs9qlfICJ04H5kwXijoDDIw5P95OSFL9xHIJLHZiujX9nuPdfuyuDQ4xndXG_A3XGvHa7j-GO0mS9f63ghrxDqMgMHFB_sTeNps6E-kbq9NkPOuLaPGriHQ5oBrzpPbMv7cGKVVAaky1Y/s320/map_bw.bmp" alt="" id="BLOGGER_PHOTO_ID_5487425221598204802" border="0" /></a>Area of interest with the edge delineated<br /></div><div style="text-align: left;"><br /></div>Now using the same procedure as done above, I got the answer of <span style="font-weight: bold; color: rgb(204, 0, 0);">50, 549.5 pixels</span>. In order to convert this into square meters, I use the technique in Activity 1 to determine the conversion factor from pixels to meters from the scale in Google maps.<br /><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEij8DQvN9akQzimp-VLbo0HrbDV5W4r6XvHbaNXPh-opW2pyZ4uPUn4_6DUWwDU6Hi2cPT4ZX5imRWin3VMYvSDSVl1CiBfFnM_BoY2QQHOOreJ40LfSOvBrtE4-KuIYOJMl0hbdwlaGtc/s1600/scale.bmp"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 382px; height: 186px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEij8DQvN9akQzimp-VLbo0HrbDV5W4r6XvHbaNXPh-opW2pyZ4uPUn4_6DUWwDU6Hi2cPT4ZX5imRWin3VMYvSDSVl1CiBfFnM_BoY2QQHOOreJ40LfSOvBrtE4-KuIYOJMl0hbdwlaGtc/s320/scale.bmp" alt="" id="BLOGGER_PHOTO_ID_5487432599672947426" border="0" /></a>scale bar on the bottom left corner (click to zoom in)<br /></div><br />I have determined that <span style="font-weight: bold;">87 pixels = 200 meters</span> (lengthwise). So that means 1 lengthwise pixel = 2.299 meters and <span style="font-weight: bold;">1 (square) pixel = 5.285 sq meters</span>. Therefore 50, 549.5 pixels would be equivalent to:<br /><span style="font-weight: bold;"></span><blockquote style="color: rgb(204, 0, 0);"><span style="font-weight: bold;">267, 139.65 sq meters</span></blockquote>Now's let's try to compute for the error. Since the scale bars take up two pixels:<br /><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGxsycCwsBI4O8CxDRKF4ffSJj5mxWMswhnzUpsH367HUJWAYVH7IvBWP97YfQM1UdwPl5jS5ZNHyZZeb8woZoyRn2extR0RUJmoNnW9IBKkSMVG83CUmNQx1d06qW5hfrCSP_nvXMx7Y/s1600/scale_zoom.bmp"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 299px; height: 95px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGxsycCwsBI4O8CxDRKF4ffSJj5mxWMswhnzUpsH367HUJWAYVH7IvBWP97YfQM1UdwPl5jS5ZNHyZZeb8woZoyRn2extR0RUJmoNnW9IBKkSMVG83CUmNQx1d06qW5hfrCSP_nvXMx7Y/s320/scale_zoom.bmp" alt="" id="BLOGGER_PHOTO_ID_5488054025382076018" border="0" /></a>scale bar<br /><br /><div style="text-align: left;">This means that the error would be plus/minus 1 pixel (lengthwise), which would translate to: (using error propagation)<br /><br />(200/87) * (1/87) = 0.0264 meters.<br /><br />Therefore the error in area per pixel would be:<br /><br />(200/87)*(2)*(0.0264)*(87/200) = 0.121 sq meters<br /><br />Multiplying this with our answer with 50, 469 pixels, we get the error of:<br /><blockquote>6106.75 sq meters<br /></blockquote>which is 2.29% of the result.<br /><br />So the final answer is:<br /><span style="color: rgb(102, 0, 0);"></span><blockquote><span style="color: rgb(204, 0, 0); font-weight: bold;">267, 139.65 +- 6106.75 sq meters</span><br /></blockquote>Finally I have to compare this with the actual value. Sadly, I can't find the area of the region inside the elliptical road on the internet so Joseph Bunao and I used Google Earth to determine the semi-major and semi-minor axis of the ellipse.<br /><br /><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8Xl-8OgPnQxYlENgdlGY5QD6l7kv9PPx1FEOIRtJSKRd9MO_CP7GMmXm6nrNXivrJvdywVW9zMN8l6mO89gPRFH1dTdV48ytU-6s4Cfy0cjm93YupWD4bWlZGW54q_QzKsUNp4XUvKm0/s1600/ellipse2.bmp"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 170px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8Xl-8OgPnQxYlENgdlGY5QD6l7kv9PPx1FEOIRtJSKRd9MO_CP7GMmXm6nrNXivrJvdywVW9zMN8l6mO89gPRFH1dTdV48ytU-6s4Cfy0cjm93YupWD4bWlZGW54q_QzKsUNp4XUvKm0/s320/ellipse2.bmp" alt="" id="BLOGGER_PHOTO_ID_5488121959633378482" border="0" /> </a><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjoGsx4vxzm7cnx4A8WIjcLbSg93FuFTwsX-3YMReSTaVYLbLiSrsPCMQZYNaqCehqU3UyCbAVltahmB9-8iLWH6w8Tis2rCJGJvhaLKlgNTqb0KRKHTGWcXRnSJHXLB0Au-biCd5NvKU/s1600/ellipse1.bmp"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 171px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjoGsx4vxzm7cnx4A8WIjcLbSg93FuFTwsX-3YMReSTaVYLbLiSrsPCMQZYNaqCehqU3UyCbAVltahmB9-8iLWH6w8Tis2rCJGJvhaLKlgNTqb0KRKHTGWcXRnSJHXLB0Au-biCd5NvKU/s320/ellipse1.bmp" alt="" id="BLOGGER_PHOTO_ID_5488121950850202386" border="0" /></a>Finding the length of semi-major and of semi-minor axis<br /></div><br />And we have determined 328.37 m and 259.65 m to be the lengths of the semi-major axis and semi-minor axis respectively. Using the formula for the area of an ellipse, we get the value:<br /><blockquote style="color: rgb(204, 0, 0); font-weight: bold;">267, 856.18 sq meters</blockquote>Wow! The estimated area is very close to this value and has an error of <span style="font-weight: bold; color: rgb(204, 0, 0);">0.27%</span>. This shows that the technique is accurate when dealing with images with defined edges since this will determine the contour that is used in Green's theorem.<br /></div></div><br /><blockquote><span style="font-weight: bold;"><blockquote></blockquote><blockquote></blockquote><blockquote></blockquote></span></blockquote>And with that, I give myself a 10/10 for producing the requirements and understanding the lesson. The images are clear and of good quality.<br /><br /><span style="font-weight: bold;">Score: 10/10</span><br /><br />Lastly I would like to thank Dr. Soriano for always entertaining my questions and Joseph Bunao for helping me find the lengths of the axes of the elliptical road.<br /><br />- Dennis<br /><br />References:<br />1. M. Soriano, "A4 - Area Estimation"<br />2. Google Mapsdennisivan89http://www.blogger.com/profile/04476991777095665795noreply@blogger.com0tag:blogger.com,1999:blog-7345763871585817117.post-31656796300423808862010-06-24T18:10:00.000-07:002010-09-23T08:45:25.292-07:00AP 186 Activity 3: Image Types and FormatsThis time, we'll be exploring different image types and formats such as jpg, png, gif and tiff.<br /><br />This activity also requires us to show examples of basic image file types as well as advanced image file types:<br /><br />Basic types:<br /><br /><div style="text-align: center;">1. Binary images<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-0489lRia-CBdSLiHAGD0kNOmAuIi0syzGOPpZsulcd4knG0ZT1bQHxP6l9CVV2EWY_wfe2usBvyj2Z9agXVsowkT9YID_CEa8XfMPNsMban4BZf8N32DqTc9CJhsS_lCbcbWAvnHZPc/s1600/rot6.gif"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 139px; height: 139px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-0489lRia-CBdSLiHAGD0kNOmAuIi0syzGOPpZsulcd4knG0ZT1bQHxP6l9CVV2EWY_wfe2usBvyj2Z9agXVsowkT9YID_CEa8XfMPNsMban4BZf8N32DqTc9CJhsS_lCbcbWAvnHZPc/s320/rot6.gif" alt="" id="BLOGGER_PHOTO_ID_5486516491369983330" border="0" /> </a><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgFiR5m0vhMzbfc1lTFxkexO4mzvwjpV46Re9VmnNHlVEzUc0NHzD7nMrOfmX9qC3SRAAhDD33lF7o5NUAxSMJTOWK1_SxFO0RLJz-XlQiRUgNUXuSkVOijD1vMtTPFD5_dyRcUwGD46MA/s1600/binary.JPG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 217px; height: 211px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgFiR5m0vhMzbfc1lTFxkexO4mzvwjpV46Re9VmnNHlVEzUc0NHzD7nMrOfmX9qC3SRAAhDD33lF7o5NUAxSMJTOWK1_SxFO0RLJz-XlQiRUgNUXuSkVOijD1vMtTPFD5_dyRcUwGD46MA/s320/binary.JPG" alt="" id="BLOGGER_PHOTO_ID_5486522204062446850" border="0" /></a><span style="font-size:78%;">taken from http://emis.math.ecnu.edu.cn/journals/EJC/Surveys/ds5/gifs/rot6.gif</span><br /></div><br />2. Grayscale images<br /><div style="text-align: center;">3. Indexed images<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJZ9ogS1XCTD4olepiNiSNAPAaxTqN_8DftI4fUvQZWrWYpOLQOXuaYnGl_fKOMKSAGZtuuDnQcuu-iX4cHKsn_nZj4cYNL1UC1TMrSCn1BjchOvWCRCAt8aAKpXkMYKXxWNDoBZQ_RpE/s1600/Old+Image.jpg"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 125px; height: 188px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJZ9ogS1XCTD4olepiNiSNAPAaxTqN_8DftI4fUvQZWrWYpOLQOXuaYnGl_fKOMKSAGZtuuDnQcuu-iX4cHKsn_nZj4cYNL1UC1TMrSCn1BjchOvWCRCAt8aAKpXkMYKXxWNDoBZQ_RpE/s320/Old+Image.jpg" alt="" id="BLOGGER_PHOTO_ID_5486516503523171618" border="0" /> </a><span style="font-size:78%;">taken from sample pictures of Adobe Photoshop CS3</span><br /><span style="font-size:78%;">this one is both a grayscale image and an indexed image</span><br /></div><div style="text-align: center;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhRScWIdrGUrjrctQg4N3W7kIsmQyOsAJ154xoQM8PhWlN83YupbhToAxLl_hgaooPh0q_hbEqHIAbNPtZWL4XSxbykB11fIAhxljDQBQTvkk4s9TmBPHFSC2C54uZ4ytZfFpHcP74ImNM/s1600/index+and+grayscale.JPG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 237px; height: 202px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhRScWIdrGUrjrctQg4N3W7kIsmQyOsAJ154xoQM8PhWlN83YupbhToAxLl_hgaooPh0q_hbEqHIAbNPtZWL4XSxbykB11fIAhxljDQBQTvkk4s9TmBPHFSC2C54uZ4ytZfFpHcP74ImNM/s320/index+and+grayscale.JPG" alt="" id="BLOGGER_PHOTO_ID_5486522208747947154" border="0" /></a>4. Truecolor images<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEigQdqYVvCMuwmKvDoYe50D9vE6PpQ7rqnz7o9cOqXErGMsQlDd4PBoCpfYRApmuYG6fFmTV1VnBUW6kPfq2zlt8FlgVzf7GdAYsOoDyXosQlBqePT7-0JdRYg0Kqj1y98KtqmBvwj47v4/s1600/snickers1.jpg"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 212px; height: 160px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEigQdqYVvCMuwmKvDoYe50D9vE6PpQ7rqnz7o9cOqXErGMsQlDd4PBoCpfYRApmuYG6fFmTV1VnBUW6kPfq2zlt8FlgVzf7GdAYsOoDyXosQlBqePT7-0JdRYg0Kqj1y98KtqmBvwj47v4/s320/snickers1.jpg" alt="" id="BLOGGER_PHOTO_ID_5486516513787608482" border="0" /> </a><span style="font-size:78%;">photo by Denille Teh of her dog<br /><br /></span><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8-UOK9ZVY_DG0fLguY7_Lx4RHvy9FpR_8oaFn5baLpHHE-vwXFYL_9TH4RU3BtiAsEr9FpcrW4-YDeQS-aT0XqlzPpBHH1V-ElY4HkMMg79IecBGJzMaAYFKDeRA4b4ISjfFKWjTeeY0/s1600/truecolor.JPG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 192px; height: 163px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8-UOK9ZVY_DG0fLguY7_Lx4RHvy9FpR_8oaFn5baLpHHE-vwXFYL_9TH4RU3BtiAsEr9FpcrW4-YDeQS-aT0XqlzPpBHH1V-ElY4HkMMg79IecBGJzMaAYFKDeRA4b4ISjfFKWjTeeY0/s320/truecolor.JPG" alt="" id="BLOGGER_PHOTO_ID_5486522219873180834" border="0" /></a><br /><br /><div style="text-align: left;">Advanced image file formats:<br /><br />1. High dynamic range (HDR) images<span style="font-size:78%;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhRgZkrL9EE5No55qZIRdsL7nJwUKqwL2SNNI_B9MEy1j40EypzaplNYbkRH63_eF5_9iEEZFp42Yg_eaz3_KgBgjzZtfumIqkfABkQwTDKUDqKKWl84EYcqnICpTzNC9lOx5TiadTHlfU/s1600/HDR.jpg"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 249px; height: 166px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhRgZkrL9EE5No55qZIRdsL7nJwUKqwL2SNNI_B9MEy1j40EypzaplNYbkRH63_eF5_9iEEZFp42Yg_eaz3_KgBgjzZtfumIqkfABkQwTDKUDqKKWl84EYcqnICpTzNC9lOx5TiadTHlfU/s320/HDR.jpg" alt="" id="BLOGGER_PHOTO_ID_5486526495193497714" border="0" /></a></span><span style="font-size:78%;">taken from http://studioshadowlight.com/images/uploads/HDR.jpg</span><br /><br /><div style="text-align: center;">2. Multi or hyperspectral image<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxgQqZGwzB7UhIg_DjAbIZd0J2RkCRNvGXIc_CSqMMG-M6Bbd_NdvgMGaPkIb8mj4JdKL_dPp5uANzovFjA2cMREOVF32qZYADozO6T0OXLN-yGS87DzBGbg1jmSKJ1UJi52Dw1y-aLi0/s1600/ik_beijing_c_big.jpg"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 249px; height: 249px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxgQqZGwzB7UhIg_DjAbIZd0J2RkCRNvGXIc_CSqMMG-M6Bbd_NdvgMGaPkIb8mj4JdKL_dPp5uANzovFjA2cMREOVF32qZYADozO6T0OXLN-yGS87DzBGbg1jmSKJ1UJi52Dw1y-aLi0/s320/ik_beijing_c_big.jpg" alt="" id="BLOGGER_PHOTO_ID_5486529064121253762" border="0" /></a><span style="font-size:78%;">taken from http://gdsc.nlr.nl/gdsc/sites/default/files/images/multispectral/ik_beijing_c_big.jpg</span><br /></div><br /><div style="text-align: center;">3. 3D images<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-_lw7K9H0HrwlVR5643y9VJ7yCwjcyyHYCWR2PyD0wWjivqIagm5b1SqcNTXDG5IW00QOuFQvguez9EdYHvVXggIcZlzBE1I3PvlXB3HngycYt6rYVZfOpEg2EdAZcbyjXYOwXfmTjzs/s1600/corpseplant.jpg"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 201px; height: 179px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-_lw7K9H0HrwlVR5643y9VJ7yCwjcyyHYCWR2PyD0wWjivqIagm5b1SqcNTXDG5IW00QOuFQvguez9EdYHvVXggIcZlzBE1I3PvlXB3HngycYt6rYVZfOpEg2EdAZcbyjXYOwXfmTjzs/s320/corpseplant.jpg" alt="" id="BLOGGER_PHOTO_ID_5486534270208411090" border="0" /></a><span style="font-size:78%;">taken from http://www.callipygian.com/3D/corpseplant.jpg</span><br /></div><br />4. Temporal images or Videos<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEho1USEEWcLrkkgo-A3xLx3mbZz3x_ffBSpArac7I2w7viWrwfiBPvNn4FX_GnL8ytnl6EjUCX_dYalO-Z5kOdahRs_o4K-e_xeoHFe39_oNs8AbhMvJ_NPBis4oCPoNrM6mjDynWxzkv8/s1600/seven_segment_display-animated.gif"><br /></a></div></div><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8-UOK9ZVY_DG0fLguY7_Lx4RHvy9FpR_8oaFn5baLpHHE-vwXFYL_9TH4RU3BtiAsEr9FpcrW4-YDeQS-aT0XqlzPpBHH1V-ElY4HkMMg79IecBGJzMaAYFKDeRA4b4ISjfFKWjTeeY0/s1600/truecolor.JPG"> </a><div style="text-align: center;"><iframe allowfullscreen='allowfullscreen' webkitallowfullscreen='webkitallowfullscreen' mozallowfullscreen='mozallowfullscreen' width='320' height='266' src='https://www.blogger.com/video.g?token=AD6v5dzXJhLXZvE0pAvtsAVrUNuI8TFpTevUVsPyI2xaDJoIKQzHAF7ODBowkzUrUYXTOpltkgKBH8aN-rLvSgrHOw' class='b-hbp-video b-uploaded' frameborder='0'></iframe><br /><span style="font-size:78%;">taken from R.T. Hanlon, A.C. Watson and A. Barbosa in "A 'Mimic' Octopus' in the Atlantic: Flatfish Mimicry and Camouflage by Macrotritopus defilippi"</span> <span style="font-size:78%;">published in Biol. Bull. 218: 15–24.(February2010)</span><br /><br /><div style="text-align: left;">Now let's see what kind of image is the scanned figure from Activity 1:<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJKm-zTG2JziyXqvZPKsxXUkBOcnl1i9IzUBICZ3-LgcTOBcyNmcd19IvMPJoEa3YVVs6uw_KQWGdWiRZq9gojYscoKQTPRsd8lgPBbOfGfM6h_KtvlQ0jOuwLsqb4Dnc-9z1e6tizOr4/s1600/pic1.JPG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 70px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJKm-zTG2JziyXqvZPKsxXUkBOcnl1i9IzUBICZ3-LgcTOBcyNmcd19IvMPJoEa3YVVs6uw_KQWGdWiRZq9gojYscoKQTPRsd8lgPBbOfGfM6h_KtvlQ0jOuwLsqb4Dnc-9z1e6tizOr4/s320/pic1.JPG" alt="" id="BLOGGER_PHOTO_ID_5486644450589452834" border="0" /></a>But oops, I had to increase the stack size of scilab first with the command:<br /><br /><blockquote style="color: rgb(0, 51, 0);">stacksize(10000000);</blockquote>once that's done,<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrzUjIAldrU_LZAoLVuPMlshCz67EHXhVysiagQQNNRSS_bQhhZnrgX1xhRxAFIN1x9L6wBi1Mp3jxP2x7214QZdZuIwUEAb4YpjMOyFYzt3H1eqRznMb6r4FBbGPHlBm5SoAC70qE6MA/s1600/pic2.JPG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 310px; height: 66px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrzUjIAldrU_LZAoLVuPMlshCz67EHXhVysiagQQNNRSS_bQhhZnrgX1xhRxAFIN1x9L6wBi1Mp3jxP2x7214QZdZuIwUEAb4YpjMOyFYzt3H1eqRznMb6r4FBbGPHlBm5SoAC70qE6MA/s320/pic2.JPG" alt="" id="BLOGGER_PHOTO_ID_5486644455716061106" border="0" /></a><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-GyOIHUVzbrFRYnieLSHG-xP4DEOcs1Gkno4VOGa13xpw_xCjJtOKEz4ydyFQRUwbvEqgTQF1oNVRGursGIvMNHfhEPTCVtiMmc5V-wQzQpCe5rFiWYp9TkoGSYL57WJMUo86lyqJQ4M/s1600/pic3.JPG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 244px; height: 81px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-GyOIHUVzbrFRYnieLSHG-xP4DEOcs1Gkno4VOGa13xpw_xCjJtOKEz4ydyFQRUwbvEqgTQF1oNVRGursGIvMNHfhEPTCVtiMmc5V-wQzQpCe5rFiWYp9TkoGSYL57WJMUo86lyqJQ4M/s320/pic3.JPG" alt="" id="BLOGGER_PHOTO_ID_5486644464699236258" border="0" /></a><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh9uTmltZurIorGtD0chqMUFJytTEj2I2wtr1dKOopF2m6IjgEPEnDQevB8UWerMqW5UxMHqxf8tcg1PPri4XoyPnLsHT44V8T6Jy5dyFjDeV45F7DcIXFowXEqqQlKbkoRPEUB0o5enKw/s1600/pic4.JPG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 263px; height: 136px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh9uTmltZurIorGtD0chqMUFJytTEj2I2wtr1dKOopF2m6IjgEPEnDQevB8UWerMqW5UxMHqxf8tcg1PPri4XoyPnLsHT44V8T6Jy5dyFjDeV45F7DcIXFowXEqqQlKbkoRPEUB0o5enKw/s320/pic4.JPG" alt="" id="BLOGGER_PHOTO_ID_5486644476197778034" border="0" /></a>based on the matrix size, the scanned figure is saved as a truecolor image.<br /><br />Now let's convert a truecolor image into grayscale and black and white :)<br /><div style="text-align: left;">We'll use this truecolor image.<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsF8U_T7RDiS8L50MZSl2ZPnIGMhNXAT3L2sok4JynwBJunimN7DbT8qqQbXy6lktxeCwvVnve51a8fKiEmkAlADUsFln9DfQigJEDz9m6C2uOi1W8v_8MfUPUjb3iw19mZagPjS-xE9Q/s1600/test1.jpg"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 189px; height: 142px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsF8U_T7RDiS8L50MZSl2ZPnIGMhNXAT3L2sok4JynwBJunimN7DbT8qqQbXy6lktxeCwvVnve51a8fKiEmkAlADUsFln9DfQigJEDz9m6C2uOi1W8v_8MfUPUjb3iw19mZagPjS-xE9Q/s320/test1.jpg" alt="" id="BLOGGER_PHOTO_ID_5486648697224553954" border="0" /></a><br /><div style="text-align: center;">540 x 720 x 3<br /></div></div>Using the code:<br /><blockquote>I = imread("C:\image1.jpg");<br />J = im2gray(I);<br />imshow(J)<br /></blockquote>and<br /><blockquote>I = imread("C:\image1.jpg");<br />J = im2bw(I, 0.5);<br />imshow(J)<br /></blockquote>(0.5 is the threshold level; the fate of the pixel turning black or white depends if it exceeds this value)<br /><br />we get:<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkGEMHCwnYos-tQr9ehIBkwChF4-6kRTqUcZWW81xKuuNfQMdf54AkpebeMzgJ8ncxCQPsqSfh3Hv_GMAT9Ba_iQC2PqRQ9JohnKMA1Lyr8qB4tBodcD7dY4O0ujQuNXQ4BVwukebKdzc/s1600/test1convert2gray.jpg"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 186px; height: 139px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkGEMHCwnYos-tQr9ehIBkwChF4-6kRTqUcZWW81xKuuNfQMdf54AkpebeMzgJ8ncxCQPsqSfh3Hv_GMAT9Ba_iQC2PqRQ9JohnKMA1Lyr8qB4tBodcD7dY4O0ujQuNXQ4BVwukebKdzc/s320/test1convert2gray.jpg" alt="" id="BLOGGER_PHOTO_ID_5486648706567825570" border="0" /></a><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjoVIefJH2TSKZlPHIxMNt55O08p6QpwTIxuRfl6rdzdTPnRksQ-4Err6bVAL-2MBHpGHvfxf2TegUSXXORBBoitufIOMj5UwnHItXtsHEyWFZzdhLyW0DSXVSvpFKLOTdNo24IX6pYivc/s1600/test1convert2bw.jpg"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 188px; height: 140px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjoVIefJH2TSKZlPHIxMNt55O08p6QpwTIxuRfl6rdzdTPnRksQ-4Err6bVAL-2MBHpGHvfxf2TegUSXXORBBoitufIOMj5UwnHItXtsHEyWFZzdhLyW0DSXVSvpFKLOTdNo24IX6pYivc/s320/test1convert2bw.jpg" alt="" id="BLOGGER_PHOTO_ID_5486648708162760978" border="0" /></a>and their matrix sizes are both<br /><br /><blockquote>540 rows by 720 columns</blockquote>note that the third channel (for RGB) disappeared.<br /><br />The next part of the activity is to use the histogram to set the threshold for the conversion of the scanned graph into black and white.<br /><br />However, I keep getting the error:<br /><blockquote>!--error 17<br />stack size exceeded! (Use stacksize function to increase it)</blockquote>even though I set the stacksize to a big value and resized my picture into a lower resolution. So I asked Cheryl Abundo to grayscale it for me. (Thank you!)<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiNeHVRP3wsEr0Pf2yllQbLjIHS2Ol_WrHH_2GMxA_xzAaM-gSPYVDuj_eHsYWI15r_Wqg_hyphenhyphen7OnNmihyphenhyphenQqSTFy_Jypj0D3e8zw_UoAEWUjutK6e6n0_bGFQM_X7jxt7fNU0KvV_UfcvF0/s1600/gs.jpg"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 154px; height: 200px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiNeHVRP3wsEr0Pf2yllQbLjIHS2Ol_WrHH_2GMxA_xzAaM-gSPYVDuj_eHsYWI15r_Wqg_hyphenhyphen7OnNmihyphenhyphenQqSTFy_Jypj0D3e8zw_UoAEWUjutK6e6n0_bGFQM_X7jxt7fNU0KvV_UfcvF0/s320/gs.jpg" alt="" id="BLOGGER_PHOTO_ID_5486672408717068210" border="0" /></a>Using the histplot function:<br /><blockquote><br />histplot(256, I)<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEheul9kebsm2q0ir6KDzR2NINwIvYwKTn7bIS1XpTcBTec2w7Kyk1e6LroK2WBDgjMOjeydouM9UmOXdZSDlFi5lZAYHdl7PTrVlrxXbw5rsO46l2iBNDUoxOxrPsxA2j-_iRcVvYIn2TE/s1600/histplot.PNG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 238px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEheul9kebsm2q0ir6KDzR2NINwIvYwKTn7bIS1XpTcBTec2w7Kyk1e6LroK2WBDgjMOjeydouM9UmOXdZSDlFi5lZAYHdl7PTrVlrxXbw5rsO46l2iBNDUoxOxrPsxA2j-_iRcVvYIn2TE/s320/histplot.PNG" alt="" id="BLOGGER_PHOTO_ID_5486672416125610834" border="0" /></a></blockquote>I chose the threshold to be 220/256 = 0.859375 and converted it to black and white...<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjpibCSHNfUiXXUC0GGKEqB3ZXGQzjgOjoyUJVd2zUejQCatBrL4h_BfNGKwcZHKhpy0-cFjGVY316HnagAEyygeQkAStfkLGEjVgnIrfxqS6xmRGYkZhiksCgLBoAboVwZoP2wBbgvaLM/s1600/bwpalpak.jpg"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 185px; height: 241px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjpibCSHNfUiXXUC0GGKEqB3ZXGQzjgOjoyUJVd2zUejQCatBrL4h_BfNGKwcZHKhpy0-cFjGVY316HnagAEyygeQkAStfkLGEjVgnIrfxqS6xmRGYkZhiksCgLBoAboVwZoP2wBbgvaLM/s320/bwpalpak.jpg" alt="" id="BLOGGER_PHOTO_ID_5486676899114688306" border="0" /></a>The lines have been separated from the background but there's this huge black blob at the left side due to the quality of the scan. The dark part at the left side is as the lines so they also appear even though a threshold has been applied.<br /><br />This activity also requires us to research about the different image file formats so here goes...<br /><br />Let's start with...<br /><br />JPEG - Joint Photographic Experts Group<br />This is one of the most famous and used image file formats because of it's ability to compress the file. However, it uses lossy compression most of the time meaning some information is lost due to compression. Most digital cameras also save in this format. JPEG or JPG is advantageous in applications where image size is more valued than quality. JPEG supports 8 bits per color (for R, G and B) for a total of 24 bits. It also supports grayscale of 8 bits.<br /><br />GIF - Graphics Interchange Format<br />This format supports up to 8 bits of color for a total of 256 colors. This format is suitable for small images with only a few colors such as logos. Also, most animated pictures are saved in this format. GIF uses lossless LZW compression. This file format was introduced by CompuServe to display 8 bit color images online.<br /><br />PNG - Portable Network Graphics<br /><span style="text-decoration: underline;"><span style="font-weight: bold;"></span></span>Basically, this format is developed to replace the GIF. It is free and open source and supports truecolor (16 million colors). PNG files are typically bigger than JPG files since it uses lossless ZIP compression. Also like GIF, PNG is more effective in images with big solid colors and slowly varying colors.<br /><br />TIFF - Tagged Image File Format<br />This format can support 8 bits per color (24 bits) as well as 16 bits per color (48 bits). It's compression can by either lossy or lossless. This format is preferred in saving documents for archiving. It also uses LZW lossless compression. LZW is the acronym for Lempel-Ziv-Welch, named after Israeli researchers Abraham Lempel and Jacob Zif. Because of it's lossless compression and quality, it has a high file size. This is also used in medical images.<br /><br />BMP - BMP file format<br />This format is also called bitmap and is developed for storing images and graphics in the Windows operating system hence they are easily recognizable in Windows.<br /><br />References:<br />1. M. Soriano, "A3 - Image Types and Formats"<br />2. Wikipedia - Image file formats<span style="font-size:78%;"> <span style="font-size:100%;">(http://en.wikipedia.org/wiki/Image_file_formats#JPEG.2FJFIF)</span></span><br /><br />3. http://www.scantips.com/basics09.html<br /><br /><br /><br />Lastly, I'll grade myself a score of 10/10 for being able to produce the requirements and understand the lesson. No bonus points for me this time :(<br /><br /><span style="font-weight: bold;">Score: 10/10<br /><br /></span>I would like to once again acknowledge Dr. Soriano for her guidance and Cheryl Abundo for converting the scanned graph into grayscale for me.<br /><br />- Dennis<br /><span style="font-weight: bold;"></span><blockquote></blockquote></div></div>dennisivan89http://www.blogger.com/profile/04476991777095665795noreply@blogger.com0tag:blogger.com,1999:blog-7345763871585817117.post-67441379770131285902010-06-22T01:39:00.000-07:002010-09-23T08:42:25.242-07:00AP 186 Activity 1: Digital Scanning*Transferred from Facebook notes to here*<br /><br />This blog is for one of our major subjects: Applied Physics 186 which requires us to write blog reports about our activity. So if you're reading this to find out what my favorite food is or what crazy things I did today, you're not gonna find it. =p<br /><br />So let's start:<br /><h1><span style="font-size:130%;">Activity 1 - Digital Scanning</span></h1> <br />Basically the objective of this activity is to get any hand-drawn graph from any journal article (which means the journal has to be old, since they use computers to graph nowadays), scan it, then reproduce the graph in Microsoft Excel using ratio and proportion of the pixels and their corresponding physical value. We get bonus points if we are able to overlap the two graphs together for a better comparison.<br /><br /> I found this nice looking graph in the CS lib from the article:<br /><h3><span style="font-size:100%;">The Photographic Processes in Spectrum Analysis by B. H. Carroll<br />Applied Spectroscopy, Vol. 1, Issue 4, pp. 1-15 (1946)</span></h3> I chose the graph because:<br /><ol><li>It's big.</li><li>It's smooth.</li><li>It's not in log scale and</li><li>It has two curves in it. :)</li></ol><br />I don't have a scanner so I asked my friend Millicent Singson to scan it for me. (Thank you!) The scanned picture has the dimensions 1700 x 2200 pixels.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgihft57uJR7ks3RJRsZutN0aDv4n3Id0syWeG7xoJpqTJ5S04_B5MdrpB1_M33R75w6WSufv5vfidoSUtM8rJUAf23exHXeZCh6SB_pPwyBLWKcFm7zCngkc35n_Qo3DMWs-r5cS-qWxQ/s1600/scan0001.jpg"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 247px; height: 320px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgihft57uJR7ks3RJRsZutN0aDv4n3Id0syWeG7xoJpqTJ5S04_B5MdrpB1_M33R75w6WSufv5vfidoSUtM8rJUAf23exHXeZCh6SB_pPwyBLWKcFm7zCngkc35n_Qo3DMWs-r5cS-qWxQ/s320/scan0001.jpg" alt="" id="BLOGGER_PHOTO_ID_5485517277999036610" border="0" /></a><br />The picture is a bit tilted so I used Adobe Photoshop to rotate it.<br /><br />In order to reproduce the graph, I have to find an equation relating pixel location to physical values. So for the x and y axes, I got the pixel location of the start and end values of axes. Then the "multiplier" would be:<br /><br /><b>(End value - Start value)/(End Pixel - Start Pixel)</b><br /><br />which we will denote as <b><big>M</big><small>x</small></b> and <b><big>M</big><small>y</small></b> for the x and y axis repectively.<br /><br />Then you just have to multiply this to the pixel location and you would get the value. However, since i didn't crop the picture before i started counting the pixels, the pixel locations would not start at 0. Therefore I would have to subtract this "pixel offset" first before multiplying it with the above equation.<br /><br />Another problem is that the origin (0, 0) doesn't start at the bottom left corner but rather at the top left corner. But this can be easily solved. :)<br /><br />Another thing to keep in mind is to add the initial starting value of the axis after you convert from pixel to value. In this case, I added 200 to the values in the x axis.<br /><br />So the equation is:<br /><br /><b>(x pixel location - x pixel offset) * Mx + x value offset</b><br /><br />for the x axis and<br /><br /><b>(y pixel location - y pixel offset) * My + y value offset</b><br /><br />for the y axis<br /><br />I got plenty of sample points (17 for the blue curve and 20 for the red curve) and reconstructed it. After overlaying the image with the graph, there's a discrepancy between the tick marks of the two. Eventually I found out that the value "4" on the y-axis isn't really 4 so I used 3 instead. Computations are as follows:<br /><br />For the x-axis:<br /><br />End value = 400<br />Start value = 200<br /><br />End Pixel = 1466<br />Start Pixel = 174<br /><br />value offset = 200<br />pixel offset = 174<br /><br />and Mx is computed to be 0.1548<br /><br />Then the equation would be:<br /><br /><b>(x pixel location - 174) * 0.1548 + 200</b><br /><br />For the y-axis:<br /><br />End value = 3<br />Start value = 0<br /><br />End Pixel = 293<br />Start Pixel = 1305<br /><br />value offset = 3<br />pixel offset = 293<br /><br />and My is computed to be - 0.00296<br /><br />Then the equation would be:<br /><br /><b>(y pixel location - 293) * (- 0.00296) + 3</b><br /><br />The negative sign of My and 3 being the value offset is because the origin starts at the top left corner.<br /><br />So now I just have to plug in the x and y pixel locations of the sample points.<br /><br />Finally, the result (*whew*):<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgk7lrES85prJEiF24F5F6JqQKgPsqnyOWm5pBHBwF-v1uahTAO-wXCoCZk6M1td8lqwSb0fsatvXS2_MU4nMg8gC_1gs9adYVQkb77v_DeqfFsJEusAq-V4Dii15YSPMgAY1HNtwq7qP8/s1600/result.JPG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 210px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgk7lrES85prJEiF24F5F6JqQKgPsqnyOWm5pBHBwF-v1uahTAO-wXCoCZk6M1td8lqwSb0fsatvXS2_MU4nMg8gC_1gs9adYVQkb77v_DeqfFsJEusAq-V4Dii15YSPMgAY1HNtwq7qP8/s320/result.JPG" alt="" id="BLOGGER_PHOTO_ID_5485517286496156066" border="0" /></a><br />The blue and red curves are the reconstruction and they show good agreement with the original graph; Swak.<br />If you look closer there's a little difference in the first tick mark which is due to the graph being hand-drawn. :)<br /><br />Grading myself, I'd give it a 10/10 for being able to accurately reconstruct the graph with captions and another 2 bonus points for being able to overlay the image onto the graph. :) So that makes it:<br /><br /><b>Score: 12/10</b><br /><br />Finally I would like to thank Dr. Soriano in helping me troubleshoot and Millicent Singson for scanning the graph for me. :)<br /><br />- Dennis<br /><br />References:<br />1. M. Soriano, "A1 - Digital Scanning"dennisivan89http://www.blogger.com/profile/04476991777095665795noreply@blogger.com0tag:blogger.com,1999:blog-7345763871585817117.post-71127331841456353382010-06-21T20:04:00.000-07:002010-06-22T01:37:14.914-07:00AP 186 Activity 2: Scilab BasicsThis "blog" is once again for activity 2 of one of my majors, AP186.<br /><br />Activity 2: Scilab Basics<br /><br />Basically this activity aims to familiarize us with some capabilities of Scilab and it's SIP toolbox. The goal of this activity is to create synthetic images for:<br /><ol><li>centered square aperture</li><li>sinusoid along the x-direction (corrugated roof)</li><li>grating along the x-direction</li><li>annulus</li><li>circular aperture with graded transparency (gaussian transparency)</li></ol>Firstly, I have to install Scilab and SIP toolbox (I'm using windows btw). Unfortunately SIP toolbox doesn't work with Scilab 5.2.2. And I tried fixing it by typing:<br /><span style="color: rgb(0, 102, 0);font-size:85%;" ><span style="font-family:arial;"><span style="font-weight: bold;font-size:100%;" ></span></span></span><blockquote><span style="color: rgb(0, 102, 0);font-size:85%;" ><span style="font-family:arial;"><span style="font-weight: bold;font-size:100%;" >chdir(ImageMagickPath);</span></span><span style="font-weight: bold;font-size:100%;" ><br /><span style="font-family:arial;"> link('CORE_RL_magick_.dll');</span></span></span></blockquote>from http://www.scilab.org/contrib/index_contrib.php?page=displayContribution&fileID=146<br /><br />and reloading the toolbox but it still won't work.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiiBPPwmJDLmZ4XyJXpf6lX9t8qJhGm7tcfq0ysLzX2lMU1m6BNonM_nqhjNVnUs19h-OU0Ug7gbP-DDpeWFGDF3eocekLjJ8XQ66VCbWN_AbAKfEnHT65AdXGZJxSWUSq8E1_EPEdlQ2I/s1600/pic1.JPG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 270px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiiBPPwmJDLmZ4XyJXpf6lX9t8qJhGm7tcfq0ysLzX2lMU1m6BNonM_nqhjNVnUs19h-OU0Ug7gbP-DDpeWFGDF3eocekLjJ8XQ66VCbWN_AbAKfEnHT65AdXGZJxSWUSq8E1_EPEdlQ2I/s320/pic1.JPG" alt="" id="BLOGGER_PHOTO_ID_5485450114898786546" border="0" /></a> So I have to revert back to the older version of Scilab 4.1.2 (Thanks Aya for finding the download link!) After installing the SIP toolbox on that version of scilab the same problem arose but this can by solved by typing in the code mentioned above and reloading the SIP toolbox.<br /><br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgoJG0tFXHk4hxsFuUcXvGup9vLGLUhSJXdXZACIlcdUdxhY0ZH6GF9fedqeHb0WF53mZnOI9mkUOmU4ZUoWjSjcOPEmT7YenYr5uz2iZOfkLOQhH_SiHX98rU06vAUyj6PC6KKWJWP4wM/s1600/pic2.JPG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 178px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgoJG0tFXHk4hxsFuUcXvGup9vLGLUhSJXdXZACIlcdUdxhY0ZH6GF9fedqeHb0WF53mZnOI9mkUOmU4ZUoWjSjcOPEmT7YenYr5uz2iZOfkLOQhH_SiHX98rU06vAUyj6PC6KKWJWP4wM/s320/pic2.JPG" alt="" id="BLOGGER_PHOTO_ID_5485451377751257906" border="0" /></a>Now, it's time to make some synthetic images!<br /><br />Following Dr. Soriano's example code for make a circular aperture:<br /><br /><blockquote style="color: rgb(0, 102, 0);">nx = 100; ny = 100; //defines the number of elements along x and y<br /><br />x = linspace(-1,1,nx); //defines the range<br />y = linspace(-1,1,ny);<br />[X,Y] = ndgrid(x,y); //creates two 2-D arrays of x and y coordinates<br /><br />r= sqrt(X.^2 + Y.^2); //note element-per-element squaring of X and Y<br />A = zeros (nx,ny);<br />A (find(r < 0.7) ) = 1;<br />imshow (A, []);</blockquote><br />I get:<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJ6weRXPb24uYOIEjkLfaNwkbhLQ4dw96302sj72hSMn_Tb32uNJXyWzfhsl_uudWaMXKyYnTmdYEWYOrOak2wp-DQpcWiw55nZb6zWnpI5mWklefLqzcZ4zMjwoop_DyTWTbXLoM4Qss/s1600/pinhole.jpg"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 100px; height: 100px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJ6weRXPb24uYOIEjkLfaNwkbhLQ4dw96302sj72hSMn_Tb32uNJXyWzfhsl_uudWaMXKyYnTmdYEWYOrOak2wp-DQpcWiw55nZb6zWnpI5mWklefLqzcZ4zMjwoop_DyTWTbXLoM4Qss/s320/pinhole.jpg" alt="" id="BLOGGER_PHOTO_ID_5485452600257763154" border="0" /></a>The edges of the circle are a bit rough since I only used 100 by 100 pixels.<br /><br />Now it's my turn to do...<br /><ol><li> centered square aperture: <a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjSYRPsO7hyphenhyphenhGsL9nxNzlgzUnNd1GjuIsZsQ-m1MYN3jr-tiaHEEM7eqa-1lBSjsUOVTLDuekmXe893hZx_X51sigvimBoMx5vlhDr37qFvgsZGiFTUHqAQIKZETOWAmjNkDnpIGXFLl6Q/s1600/centered_square_aperture.jpg"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 100px; height: 100px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjSYRPsO7hyphenhyphenhGsL9nxNzlgzUnNd1GjuIsZsQ-m1MYN3jr-tiaHEEM7eqa-1lBSjsUOVTLDuekmXe893hZx_X51sigvimBoMx5vlhDr37qFvgsZGiFTUHqAQIKZETOWAmjNkDnpIGXFLl6Q/s320/centered_square_aperture.jpg" alt="" id="BLOGGER_PHOTO_ID_5485453780911867570" border="0" /><br /></a></li><li>sinusoid along the x-direction (corrugated roof):<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMIeaAwROQvfsGKLJJBfvCK004qfd7y55LVY5-52-oD7Zr0djKfReB2y2Mi3yIyq33LDiK3hox0Qq0cgc-D-BSP1B24XUp1JF6MVxxi7aGxaeYrecVoZwOvyLkkaj-Bmwdmw_gtbA4A8c/s1600/sinusoid+x.jpg"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 167px; height: 167px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMIeaAwROQvfsGKLJJBfvCK004qfd7y55LVY5-52-oD7Zr0djKfReB2y2Mi3yIyq33LDiK3hox0Qq0cgc-D-BSP1B24XUp1JF6MVxxi7aGxaeYrecVoZwOvyLkkaj-Bmwdmw_gtbA4A8c/s320/sinusoid+x.jpg" alt="" id="BLOGGER_PHOTO_ID_5485453786043687282" border="0" /><br /></a></li><li>grating along the x-direction:<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUZJniMswMQHUFY6cqVX-5XwuHYUVXjeC209pxn-xlrs_aezJIKSO5FTUJGyx5xgUJoQS9Z2Kecgqcq94V14FzprKJW_6dHB9yo3FVkofqipJVQY5IAZaf5IJe1g9G8G1f8HMmL8xzVoc/s1600/grating+x.jpg"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 167px; height: 167px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUZJniMswMQHUFY6cqVX-5XwuHYUVXjeC209pxn-xlrs_aezJIKSO5FTUJGyx5xgUJoQS9Z2Kecgqcq94V14FzprKJW_6dHB9yo3FVkofqipJVQY5IAZaf5IJe1g9G8G1f8HMmL8xzVoc/s320/grating+x.jpg" alt="" id="BLOGGER_PHOTO_ID_5485453793900597714" border="0" /><br /></a></li><li>annulus: (from here onwards I used 256 by 256 pixels)<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgW7bqRd2meVn49eR1vDjx80JjA3u7LnCxpmHA2_p5JhhRsYy6mrRBY-59YUKahyphenhyphenuyhzSGZXPc41dIokGd8ngs-K3Nj6qKS9u3ElDB-641jbFBwtk5H1tudzMO4HxsmKm6T1DlipgxQ4Yo/s1600/annulus.jpg"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 156px; height: 156px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgW7bqRd2meVn49eR1vDjx80JjA3u7LnCxpmHA2_p5JhhRsYy6mrRBY-59YUKahyphenhyphenuyhzSGZXPc41dIokGd8ngs-K3Nj6qKS9u3ElDB-641jbFBwtk5H1tudzMO4HxsmKm6T1DlipgxQ4Yo/s320/annulus.jpg" alt="" id="BLOGGER_PHOTO_ID_5485453796235835938" border="0" /><br /></a></li><li style="text-align: left;">circular aperture with graded transparency (gaussian transparency):<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwiEfmhWNUImLmNAeSODq55m3s9psd9aRb2O85peGmftFDQXl_1j-BwDUMlktBg9iQccbiWU0FdpezRaN8eIDqnYRQSe6m7sjOlmQIaIWHGClpiTkpC990_PD1f2JjjWJJzvnqbzTWreo/s1600/circ+graded+transparency.jpg"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 178px; height: 178px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwiEfmhWNUImLmNAeSODq55m3s9psd9aRb2O85peGmftFDQXl_1j-BwDUMlktBg9iQccbiWU0FdpezRaN8eIDqnYRQSe6m7sjOlmQIaIWHGClpiTkpC990_PD1f2JjjWJJzvnqbzTWreo/s320/circ+graded+transparency.jpg" alt="" id="BLOGGER_PHOTO_ID_5485453803033173922" border="0" /> </a></li></ol>And aside from these required patterns, I've made some more patterns:<br /><br /><ol><li>Cross<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgxT83yO_NFcjyVpf9H9zyyDZNBfEVgpiTuR_gU8IbIrH96s3P7tMv8Q1AEAq8suFK6Nu3lkqDDC9K85vrowRz1WUtNnCxZy44pWGAkPj7Xf56INYDQYxNfXalMTJngmCaWZ-XbysVdQVI/s1600/cross.jpg"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 102px; height: 102px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgxT83yO_NFcjyVpf9H9zyyDZNBfEVgpiTuR_gU8IbIrH96s3P7tMv8Q1AEAq8suFK6Nu3lkqDDC9K85vrowRz1WUtNnCxZy44pWGAkPj7Xf56INYDQYxNfXalMTJngmCaWZ-XbysVdQVI/s320/cross.jpg" alt="" id="BLOGGER_PHOTO_ID_5485495150934848354" border="0" /><br /></a></li><li>Double slit<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiAN2-cZa-xWx9dHk64V9VtILPaFQYx2t9Fr0eCTF3hTzZicsMYKi9YwF17rGOBM9nCJEiyzO5U0eDAF_bv7K4hCQYy0_4ER88CtqGdvuss1NZDSMwPZ0lpj1B6l8xipvgTCRZUtMyPq9k/s1600/double+slit.jpg"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 109px; height: 109px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiAN2-cZa-xWx9dHk64V9VtILPaFQYx2t9Fr0eCTF3hTzZicsMYKi9YwF17rGOBM9nCJEiyzO5U0eDAF_bv7K4hCQYy0_4ER88CtqGdvuss1NZDSMwPZ0lpj1B6l8xipvgTCRZUtMyPq9k/s320/double+slit.jpg" alt="" id="BLOGGER_PHOTO_ID_5485495156153620226" border="0" /><br /></a></li><li>Half moon<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjDQnBZC_d5_ybMmp0ejDWo308F_GnuMG3cMmD4gDMhvnV-I73cfSoiJkVn8J4T3O1TnKgvdBf6qvZ09mhv3jHWGpZ0Pm4Zo4Q96SqY4pqzXhMDkhMuRBsi13HOy8ZcC36Io-Waac9wdh0/s1600/half+moon.jpg"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 124px; height: 124px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjDQnBZC_d5_ybMmp0ejDWo308F_GnuMG3cMmD4gDMhvnV-I73cfSoiJkVn8J4T3O1TnKgvdBf6qvZ09mhv3jHWGpZ0Pm4Zo4Q96SqY4pqzXhMDkhMuRBsi13HOy8ZcC36Io-Waac9wdh0/s320/half+moon.jpg" alt="" id="BLOGGER_PHOTO_ID_5485495157180814802" border="0" /><br /></a></li><li>Smiley<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjpGUKDNcc0obz3BZVdRlZnORjE7wj1LUTZPNNEJeaI_vV030yrDd_wvV1sod3lvMEDrMqkcxW24F480lD1SE3l2OBE6kD5yje3_ZJEerrBSnP3c6e6yGD1PaXOs8NOYt8qOFeI8CSXb3E/s1600/smiley.jpg"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 141px; height: 141px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjpGUKDNcc0obz3BZVdRlZnORjE7wj1LUTZPNNEJeaI_vV030yrDd_wvV1sod3lvMEDrMqkcxW24F480lD1SE3l2OBE6kD5yje3_ZJEerrBSnP3c6e6yGD1PaXOs8NOYt8qOFeI8CSXb3E/s320/smiley.jpg" alt="" id="BLOGGER_PHOTO_ID_5485500623988105362" border="0" /><br /></a></li></ol>The code for all these is:<br /><br /><span style="color: rgb(0, 102, 0);"></span><blockquote><span style="color: rgb(0, 102, 0);">nx = 256; ny = 256; //defines the number of elements along x and y</span><br /><br /><span style="color: rgb(0, 102, 0);">x = linspace(-1,1,nx); //defines the range</span><br /><span style="color: rgb(0, 102, 0);">y = linspace(-1,1,ny);</span><br /><span style="color: rgb(0, 102, 0);">[X,Y] = ndgrid(x,y); //creates two 2-D arrays of x and y coordinates</span><br /><br /><span style="color: rgb(0, 102, 0);">Pinhole</span><br /><span style="color: rgb(0, 102, 0);">r= sqrt(X.^2 + Y.^2); //note element-per-element squaring of X and Y</span><br /><span style="color: rgb(0, 102, 0);">A = zeros (nx,ny);</span><br /><span style="color: rgb(0, 102, 0);">A (find(r < 0.7)) = 1;<br /><br /><span style="color: rgb(0, 102, 0);"> Centered Square Aperture</span><br /><span style="color: rgb(0, 102, 0);">A = ones (nx,ny);</span><br /><span style="color: rgb(0, 102, 0);">A(find(abs(X) > 0.4)) = 0;</span><br /><span style="color: rgb(0, 102, 0);">A(find(abs(Y) > 0.4)) = 0;</span><br /><br /><span style="color: rgb(0, 102, 0);">Sinusoid along the x-direction (corrugated roof)</span><br /><span style="color: rgb(0, 102, 0);">A = ones (nx,ny);</span><br /><span style="color: rgb(0, 102, 0);">x = 2 * 2 * %pi * linspace(-1, 1, nx);</span><br /><span style="color: rgb(0, 102, 0);">[X,Y] = ndgrid(x,y);</span><span style="color: rgb(0, 102, 0);"></span><br /><span style="color: rgb(0, 102, 0);">A = sin(X)</span><br /><span style="color: rgb(0, 102, 0);">minimum = min(A)</span><br /><span style="color: rgb(0, 102, 0);">A = (A - minimum)</span><br /><span style="color: rgb(0, 102, 0);">maximum = max(A)</span><br /><span style="color: rgb(0, 102, 0);">A = A/maximum</span></span><br /><br /><span style="color: rgb(0, 102, 0);">Grating along the x-direction<br />A = ones (nx,ny);<br />A(find(abs(X) < 1.1)) = 0;<br />A(find(abs(X) < 0.9)) = 1;<br />A(find(abs(X) < 0.7)) = 0;<br />A(find(abs(X) < 0.5)) = 1;<br />A(find(abs(X) < 0.3)) = 0;<br />A(find(abs(X) < 0.1)) = 1;<br /><br />Annulus<br />r= sqrt(X.^2 + Y.^2); //note element-per-element squaring of X and Y<br />A = zeros (nx,ny);<br />A (find(r < 0.7) ) = 1;<br />A (find(r < 0.3) ) = 0;<br /><br />Circular aperture with graded transparency (gaussian transparency)<br />r= sqrt(X.^2 + Y.^2);<br />A = exp(-r.^2/0.15)<br />A(find(r > 0.6)) = 0;<br /><br />Cross<br />A = zeros (nx,ny);<br />A(find(abs(X) < 0.15)) = 1;<br />A(find(abs(Y) < 0.15)) =1;<br /><br />Double slit along y<br />A = zeros (nx,ny);<br />A(find(abs(Y)<0.25)) = 1;<br />A(find(abs(Y)<0.15)) = 0;<br /><br />Half moon<br />r= sqrt(X.^2 + Y.^2);<br />A = zeros (nx,ny);<br />A(find(r < 0.6)) = 1;<br />A(find(Y > 0)) = 0;<br /><br />Smiley<br />r= sqrt(X.^2 + Y.^2);<br />A = zeros (nx,ny);<br />A(find(r < 0.5)) =1;<br />A(find(X < 0)) = 0;<br />A(find(((X+0.4).^2 + (Y+0.4).^2) < 0.01)) = 1;<br />A(find(((X+0.4).^2 + (Y-0.4).^2) < 0.01)) = 1;<br /><br />imshow (A, []);<br />imwrite(A, 'pinhole.jpg');<br />imwrite(A, 'centered_square_aperture.jpg');<br />imwrite(A, 'annulus.jpg');<br />imwrite(A, 'sinusoid x.jpg');<br />imwrite(A, 'grating x.jpg');<br />imwrite(A, 'circ graded transparency.jpg');<br />imwrite(A, 'cross.jpg');<br />imwrite(A, "double slit.jpg");<br />imwrite(A, 'half moon.jpg');<br />imwrite(A, 'smiley.jpg');</span><br /></blockquote><br />Just comment out segments of the code to produce specific patterns. Grading myself, I would give it a score of perfect 10/10 for being able to produce all the required patterns, for understanding the lesson and presenting the images with proper labels. Plus, a bonus of two points for going beyond the requirements and trying it out with other patterns.<br /><br /><span style="font-weight: bold;">Score: 12/10</span><br /><br />Lastly, I want to thank Dr. Soriano, Bayosa Aya Carino and Aivin Solatorio for giving insights and helping me with this activity.<br /><br /><br />- Dennis Diazdennisivan89http://www.blogger.com/profile/04476991777095665795noreply@blogger.com0