RU beehive logo ITEC dept promo banner
ITEC 120
2012fall
dbraffitt
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.

Pictures!

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

Initializing 2-D arrays

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.)

Methods on 2-D arrays

methods that return a value

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.

methods that modify array-contents

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, moveEachToward(0) ends up halving each item in the array, and moveEachToward(256) makes each item “twice as close” to 256.
You can either use a helper method (something like moveOneRowToward( int[][] nums, int target, int rowNum)), or you can use a nested loop.

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


©2012, Ian Barland, Radford University
Last modified 2012.Dec.04 (Tue)
Please mail any suggestions
(incl. typos, broken links)
to ibarlandradford.edu
Powered by PLT Scheme