RU beehive logo ITEC dept promo banner
ITEC 120
2010fall
ibarland

homeinfolectslabsexamshws
tutor/PIsbreeze (snow day)
Object120 + its docsjava.lang docsjava.util docs

lab14a
2-D arrays
processing pictures I

We will:

This is a two-session lab; We will continue working on picture-processing methods next Thu as well.

Methods on 2-D arrays

Group Task Write a method which takes any 2-D array of ints, and calculates the average value (that is, it adds them all up, and divides by the length×width).
To add up all the values in the array, you can either use a helper method ( something like addOneRow( int[][] nums, int rowNum)), or you can use a nested loop.

Your Task Write a method which takes any 2-D array of ints, and finds the maximum value.
You can either use a helper method (findMaxInRow( int[][] nums, int rowNum)), or you can use a nested loop.

Your Task Write a method moveEachToward(int[][] nums, int target) which takes any 2-D array of ints, and replaces each number n with1 (n+target)/2. That is, moveEachHalfwayTo(0) ends up halving each item in the array, and moveEachHalfwayTo(256) makes each item “twice as close” to 256.
You can either use a helper method (something like moveEachInRowToward( int[][] nums, int target, int rowNum)), or you can use a nested loop.

Pictures!

We have provided a class (documentation and source code). with two helpful static methods:

See further documentation on this class. You can also look at and run the main method of that class. You can put your methods in a separate class; just be sure to call the provided (static?!) methods by using their class-name: Pict.methodName.

Task, together: Write a method which creates a 500x500 array, then initializes location i,j is initialized to i % 256. What do you think this will look like, as a picture? Display it, and find out. example code.

Task: Now, tweak the above method to try different formulas. (For each one, you're encouraged to predict the result first.)

Effects

Choose one effect from the following list, and implement it! To figure out what you should do, work a small test case by hand (say, the 3x4 array data1 shown above).

There are also plenty of other photo effects you could do, instead of the above.


1 Hey, for once integer division is what we want, since we're storing the result back into an int. Note that any number in [0,256), when average with 256, is still in [0,256). That's because (255+256)/2 is 255, by integer division. This will be important below.      

homeinfolectslabsexamshws
tutor/PIsbreeze (snow day)
Object120 + its docsjava.lang docsjava.util docs


©2010, Ian Barland, Radford University
Last modified 2010.Dec.07 (Tue)
Please mail any suggestions
(incl. typos, broken links)
to iba�rlandrad�ford.edu
Powered by PLT Scheme