Project 1 : Gallery

 

Due: Monday 6/16/14 @5:30pm

Purpose:

This project gives 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 compareTo method you will implement. The images will be presented in order from more interesting to less interesting.

2. Implement the API for Comparable on the ComparableBufferedImage object. ComparableBufferedImage extends BufferedImage so it can be used with the rest of the Java APIs for images. For your constructor you must call one from the super class.

3. Write an interestingness method for ComparableBufferedImage. We will define “more interesting” this as an image a 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.

4. When implementing the compareTo function you will compare the images based on “interestingness.” The one with less difference is ranked more interesting.

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.

Notes:

To compute the mean of the pixels use the The Apache Commons Mathematics Library. Download the file commons-math3-3.3-bin.zip; inside is a jar file “commons-math3-3.3.jar” to put in your classpath.

// import
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
// make
DescriptiveStatistics stats = new DescriptiveStatistics();
// add values
stats.addValue(0.234);
stats.addValue(0.123);
// get mean
double mean = stats.getMean();
// get variance
double var = stats.getVariance();

To use BufferedImage this is the basic API:

// Read an image
BufferedImage img = ImageIO.read(new File("image.png"));

// Get the RGB value of a pixel at x,y
int rgb = img.getRGB(x, y);

// Get the red, green, or blue value between 0 and 255
int r = (rgb & 0xFF0000) >> 16;
int g = (rgb & 0x00FF00) >> 8;
int b = (rgb & 0x0000FF);

// Write an image
ImageIO.write(img, "png", new File("newimage.png"));

 

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:

// for 2gb
java -Xmx2g ...
// for 4gb
java -Xmx4g ...

 

Download images:
http://labelme.csail.mit.edu/Release3.0/Images/30may05_static_street_cambridge/
Here are some calculated interestingness values:

p1010678.jpg, 0.16700066933931207
p1010679.jpg, 0.17559584884369817
p1010680.jpg, 0.14617362006676016
p1010681.jpg, 0.10359834711788407
p1010682.jpg, 0.1746764655425997
p1010683.jpg, 0.1683047491764929
p1010684.jpg, 0.16691526326326583
p1010685.jpg, 0.170844477661928
p1010686.jpg, 0.1837666654504827
p1010687.jpg, 0.1524582105220499
p1010688.jpg, 0.17672164124695722
p1010689.jpg, 0.17306680484213788
p1010690.jpg, 0.15932314129512437
p1010691.jpg, 0.16294507981806428
p1010692.jpg, 0.14207289685446112
p1010693.jpg, 0.17237432249767481
p1010694.jpg, 0.16419763574670776
p1010695.jpg, 0.18653306003349335
p1010696.jpg, 0.16723899551292332
p1010697.jpg, 0.1768260143794811
p1010698.jpg, 0.16788710450825517
p1010699.jpg, 0.15926748937077506
p1010700.jpg, 0.17105565282446394
p1010701.jpg, 0.16821211350780724
p1010702.jpg, 0.19201612339948176
p1010703.jpg, 0.1655359170156845
p1010704.jpg, 0.15511423790348156
p1010705.jpg, 0.1944620896080953
p1010706.jpg, 0.1506185911113288
p1010707.jpg, 0.124733437133969
p1010708.jpg, 0.21465251973819932
p1010709.jpg, 0.19221852131758854
p1010710.jpg, 0.23195608737316548
p1010711.jpg, 0.2240089710435832
p1010712.jpg, 0.1763883037583578
p1010713.jpg, 0.170161745107675
p1010714.jpg, 0.14615287586255643
p1010715.jpg, 0.23177632776033075
p1010716.jpg, 0.16113876646916792
p1010717.jpg, 0.17984604967601764
p1010718.jpg, 0.12027983339205373
p1010719.jpg, 0.17579939040374865
p1010720.jpg, 0.18668858759208173
p1010721.jpg, 0.17111686638259532
p1010722.jpg, 0.15039660511325437
p1010723.jpg, 0.17278198232809067
p1010724.jpg, 0.10703907540817659
p1010725.jpg, 0.17499899213337444
p1010726.jpg, 0.18185884674874586
p1010727.jpg, 0.1667638679180004
p1010728.jpg, 0.16739450735341405
p1010729.jpg, 0.17482380150084742
p1010730.jpg, 0.1679279248928195
p1010731.jpg, 0.1702262017398518
p1010732.jpg, 0.1689230862340047
p1010733.jpg, 0.1706925715235902
p1010734.jpg, 0.17644484193821725
p1010735.jpg, 0.1649210056609205

Download the code needed: project1

To Deliver:

On the UNIX system in a folder called ‘project1’ put the following files (or more):

ComparableBufferedImage.java, Gallery.java, Run.java, memo.txt

These files can also be in an ‘src’ folder so that you can use the folder as an eclipse project.

Grading (total 25 points):

5 points: Implement Iterable by writing an Iterator object

5 points: Implement Comparable that called the interestingness method

5 points: Correctly implement the interestingness method

5 points: Implement a sorting algorithm for the iterator (don’t use Arrays.sort)

5 points: memo.txt and how easy the assignment is to grade