{"id":183,"date":"2014-06-02T14:22:26","date_gmt":"2014-06-02T18:22:26","guid":{"rendered":"http:\/\/josephpcohen.com\/cs210-summer2014\/?p=183"},"modified":"2014-06-02T14:22:26","modified_gmt":"2014-06-02T18:22:26","slug":"project-1","status":"publish","type":"post","link":"https:\/\/josephpcohen.com\/teaching\/cs210\/project-1\/","title":{"rendered":"Project 1 : Gallery"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p>Due: Monday 6\/16\/14 @5:30pm<\/p>\n<p><strong>Purpose:<\/strong><\/p>\n<p>This project\u00a0gives you experience working with images, object inheritance, implementing interfaces, sorting, and using external libraries.<\/p>\n<p><strong>Activities:<\/strong><\/p>\n<p>1. Implement the API for <a href=\"http:\/\/docs.oracle.com\/javase\/7\/docs\/api\/java\/lang\/Iterable.html\" target=\"_blank\">Iterable<\/a> on the Gallery object that will allow images to be iterated in order. You will have to sort the images using the\u00a0compareTo method you will implement. The images will be presented in order from more interesting to less interesting.<\/p>\n<p>2. Implement the API for\u00a0<a href=\"http:\/\/docs.oracle.com\/javase\/7\/docs\/api\/java\/lang\/Comparable.html\" target=\"_blank\">Comparable<\/a>\u00a0on the ComparableBufferedImage object.\u00a0ComparableBufferedImage extends BufferedImage so it can be used with the rest of the Java APIs for images. For your\u00a0constructor you must call one from the super class.<\/p>\n<p>3. Write an interestingness method for ComparableBufferedImage. We will define &#8220;more\u00a0interesting&#8221; this as an\u00a0image\u00a0a ratio of red to green and blue more similar to 2\/3. You compute this by taking the mean values of red green and blue and then computing their ratio. The lower this number the more interesting the image.<\/p>\n<p>4. When implementing the\u00a0compareTo function you\u00a0will compare the images based on &#8220;interestingness.&#8221; The one with less\u00a0difference is ranked more interesting.<\/p>\n<p>5. Write a file memo.txt that discusses the challenges you faced, how to solved them or not, and what you learned from the assignment.<\/p>\n<p><strong>Notes:<\/strong><\/p>\n<p>To compute the mean of the pixels use the <a href=\"http:\/\/commons.apache.org\/proper\/commons-math\/\" target=\"_blank\">The Apache Commons Mathematics Library<\/a>.\u00a0Download the file commons-math3-3.3-bin.zip; inside is a jar file &#8220;commons-math3-3.3.jar&#8221; to put in your classpath.<\/p>\n<pre>\/\/ import\nimport org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;\n\/\/ make\nDescriptiveStatistics stats = new DescriptiveStatistics();\n\/\/ add values\nstats.addValue(0.234);\nstats.addValue(0.123);\n\/\/ get mean\ndouble mean = stats.getMean();\n\/\/ get variance\ndouble var = stats.getVariance();\n<\/pre>\n<p>To use <a href=\"http:\/\/docs.oracle.com\/javase\/7\/docs\/api\/java\/awt\/image\/BufferedImage.html\" target=\"_blank\">BufferedImage<\/a> this is the basic API:<\/p>\n<pre>\/\/ Read an image\nBufferedImage img = ImageIO.read(new File(\"image.png\"));\n\n\/\/ Get the RGB value of a pixel at x,y\nint rgb = img.getRGB(x, y);\n\n\/\/ Get the red, green, or blue value between 0 and 255\nint r = (rgb &amp; 0xFF0000) &gt;&gt; 16;\nint g = (rgb &amp; 0x00FF00) &gt;&gt; 8;\nint b = (rgb &amp; 0x0000FF);\n\n\/\/ Write an image\nImageIO.write(img, \"png\", new File(\"newimage.png\"));\n<\/pre>\n<p>&nbsp;<\/p>\n<p>When running java you may get errors about heap space. Run from the command line as follows or edit your eclipse run configuration to include the argument:<\/p>\n<pre>\/\/ for 2gb\njava -Xmx2g ...\n\/\/ for 4gb\njava -Xmx4g ...\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Download images:<\/strong><br \/>\n<a href=\"http:\/\/labelme.csail.mit.edu\/Release3.0\/Images\/30may05_static_street_cambridge\/\" target=\"_blank\">http:\/\/labelme.csail.mit.edu\/Release3.0\/Images\/30may05_static_street_cambridge\/<\/a><br \/>\nHere are some calculated interestingness values:<\/p>\n<pre>\np1010678.jpg, 0.16700066933931207\np1010679.jpg, 0.17559584884369817\np1010680.jpg, 0.14617362006676016\np1010681.jpg, 0.10359834711788407\np1010682.jpg, 0.1746764655425997\np1010683.jpg, 0.1683047491764929\np1010684.jpg, 0.16691526326326583\np1010685.jpg, 0.170844477661928\np1010686.jpg, 0.1837666654504827\np1010687.jpg, 0.1524582105220499\np1010688.jpg, 0.17672164124695722\np1010689.jpg, 0.17306680484213788\np1010690.jpg, 0.15932314129512437\np1010691.jpg, 0.16294507981806428\np1010692.jpg, 0.14207289685446112\np1010693.jpg, 0.17237432249767481\np1010694.jpg, 0.16419763574670776\np1010695.jpg, 0.18653306003349335\np1010696.jpg, 0.16723899551292332\np1010697.jpg, 0.1768260143794811\np1010698.jpg, 0.16788710450825517\np1010699.jpg, 0.15926748937077506\np1010700.jpg, 0.17105565282446394\np1010701.jpg, 0.16821211350780724\np1010702.jpg, 0.19201612339948176\np1010703.jpg, 0.1655359170156845\np1010704.jpg, 0.15511423790348156\np1010705.jpg, 0.1944620896080953\np1010706.jpg, 0.1506185911113288\np1010707.jpg, 0.124733437133969\np1010708.jpg, 0.21465251973819932\np1010709.jpg, 0.19221852131758854\np1010710.jpg, 0.23195608737316548\np1010711.jpg, 0.2240089710435832\np1010712.jpg, 0.1763883037583578\np1010713.jpg, 0.170161745107675\np1010714.jpg, 0.14615287586255643\np1010715.jpg, 0.23177632776033075\np1010716.jpg, 0.16113876646916792\np1010717.jpg, 0.17984604967601764\np1010718.jpg, 0.12027983339205373\np1010719.jpg, 0.17579939040374865\np1010720.jpg, 0.18668858759208173\np1010721.jpg, 0.17111686638259532\np1010722.jpg, 0.15039660511325437\np1010723.jpg, 0.17278198232809067\np1010724.jpg, 0.10703907540817659\np1010725.jpg, 0.17499899213337444\np1010726.jpg, 0.18185884674874586\np1010727.jpg, 0.1667638679180004\np1010728.jpg, 0.16739450735341405\np1010729.jpg, 0.17482380150084742\np1010730.jpg, 0.1679279248928195\np1010731.jpg, 0.1702262017398518\np1010732.jpg, 0.1689230862340047\np1010733.jpg, 0.1706925715235902\np1010734.jpg, 0.17644484193821725\np1010735.jpg, 0.1649210056609205\n<\/pre>\n<p><strong>Download the code needed:<\/strong>\u00a0<a href=\"http:\/\/josephpcohen.com\/cs210-summer2014\/wp-content\/uploads\/project1.zip\">project1<\/a><\/p>\n<p><strong>To Deliver:<\/strong><\/p>\n<p>On the UNIX system in a folder called &#8216;project1&#8217; put the following files (or more):<\/p>\n<p>ComparableBufferedImage.java, Gallery.java, Run.java, memo.txt<\/p>\n<p>These files can also be in an &#8216;src&#8217; folder so that you can use the folder as an eclipse project.<\/p>\n<p><strong>Grading (total 25 points):<\/strong><\/p>\n<p>5 points: Implement Iterable by writing an Iterator object<\/p>\n<p>5 points: Implement Comparable that called the interestingness method<\/p>\n<p>5 points: Correctly implement the interestingness method<\/p>\n<p>5 points: Implement a sorting algorithm for the iterator (don&#8217;t use Arrays.sort)<\/p>\n<p>5 points: memo.txt and how easy the assignment is to grade<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Due: Monday 6\/16\/14 @5:30pm Purpose: This project\u00a0gives you experience working with images, object inheritance, implementing interfaces, sorting, and using external libraries. Activities: 1. Implement the API for Iterable on the Gallery object that will allow images to be iterated in order. You will have to sort the images using the\u00a0compareTo method you will implement&#8230;.  <a href=\"https:\/\/josephpcohen.com\/teaching\/cs210\/project-1\/\" class=\"more-link\" title=\"Read Project 1 : Gallery\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,1],"tags":[],"_links":{"self":[{"href":"https:\/\/josephpcohen.com\/teaching\/cs210\/wp-json\/wp\/v2\/posts\/183"}],"collection":[{"href":"https:\/\/josephpcohen.com\/teaching\/cs210\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/josephpcohen.com\/teaching\/cs210\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/josephpcohen.com\/teaching\/cs210\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/josephpcohen.com\/teaching\/cs210\/wp-json\/wp\/v2\/comments?post=183"}],"version-history":[{"count":0,"href":"https:\/\/josephpcohen.com\/teaching\/cs210\/wp-json\/wp\/v2\/posts\/183\/revisions"}],"wp:attachment":[{"href":"https:\/\/josephpcohen.com\/teaching\/cs210\/wp-json\/wp\/v2\/media?parent=183"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/josephpcohen.com\/teaching\/cs210\/wp-json\/wp\/v2\/categories?post=183"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/josephpcohen.com\/teaching\/cs210\/wp-json\/wp\/v2\/tags?post=183"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}