![]() |
![]() |
|
Due 2019-Dec-06 (Fri) 23:59 on D2L; Bring hardcopy to following meeting (the final exam). You only need submit/print FX.java — not the provided files.
This homework builds on our color-images lab. It teaches 2-D array handling, including:
, and@author yourUserName
.@see http://www.radford.edu/itec120/2019fall-ibarland/Homeworks/arrays2d-images/
andimport java.awt.Color;
. (These lines should come beforeimport java.util.Arrays;
Your unit-tests for this function should ensure that you are mutating the array:
in addition to copying the same
(For full credit,
also compare an entire row/array before and after the call using
Write a function which compares the running-time of the previous two reflect-top-bottom functions:
create a very large array (perhaps via
How to time something:
Write function
| 30 | 30 | 90 | 90 |
| 30 | 30 | 90 | 90 |
| 90 | 90 | 90 | 90 |
| 90 | 90 | 90 | 90 |
| 0 | 40 | 0 | ?? |
| 40 | 60 | 0 | ?? |
| 0 | 0 | 0 | ?? |
| ?? | ?? | ?? | ?? |
pro-tip: I recomend writing a methodsafeLookup( int[][] arr, int r, int c, int default ) which simply returnsarr[r][c] , except that if those aren't valid indices forarr , then returndefault instead.This method factors out the many
if -statements you'd otherwise have sprinkled through your loops, and helps reduce lots of code dealing with processing elements at/near the edges of your array.
In special effects, “green screening” means combining two images into a new one,
where
the result is just like the
We will implement this special-effect. It is, of course, a function:
given two images (and a reference-color key), return a new composited image:
You must write a helper-function which just tells whether two single pixels are
One way to
decide whether two
2-3 unit tests should suffice, for this helper function.
(And, the function
For fun:
If you want to make good use of this function yourself,
you can take a photo of yourself in front of a uniform-color background,
and crop it to the size as some other background photo.
To get the rgb value to use as a suitable key,
you might simply grab a picture from your photo's background (e.g.
For each of the functions you write, be sure to write test-cases.
You can use
You may assume all arrays are non-empty (are at least 1x1), and are rectangular; for extra-credit allow for arrays with 0 rows or 0 columns.
Here are some arrays you can use, to help with your tests:
/* Be sure you've `import`ed java.awt.Color java.util.Arrays near the top of your file (*before* `class FX { … }`.) */
// first, some colors to help us build (test-)2D-arrays
Color red11 = new Color( 11, 0, 0);
Color red99 = new Color( 99, 0, 0);
Color red199 = new Color(199, 0, 0);
Color green11 = new Color( 0, 11, 0);
Color green99 = new Color( 0, 99, 0);
Color green199 = new Color( 0,199, 0);
Color blue11 = new Color( 0, 0, 11);
Color blue99 = new Color( 0, 0, 99);
Color blue199 = new Color( 0, 0,199);
Color gray11 = new Color( 11, 11, 11);
Color gray99 = new Color( 99, 99, 99);
Color gray199 = new Color(199,199,199);
// BETTER, in retrospect: I should make an array 'pallette', and use *loops* to generate the colors above.
// next, some arrays to help us build (test-)2D-arrays
Color[] row0 = new Color[]{ red99, blue11, green99, gray199 };
Color[] row1 = new Color[]{ red199, blue11, blue99, Color.MAGENTA };
Color[] row2 = new Color[]{ blue199, gray99, blue99, tint(gray99) };
// NOW finally make some 2-D arrays.
// A 3x4 array (three rows, each with four columns):
Color[][] grid34 = new Color[][]{ row0
, row1
, row2
};
// A small 1x1 array
Color[][] grid11 = new Color[][]{ new Color[](50,40,130) };
// Some 1xn arrays:
Color[][] grid41 = new Color[][]{ Arrays.copyOf(row1,row1.length) }; // make a copy of row1, so that any functions that *change* an array tested on `grid34` won't affect `grid41` (!)
Color[][] grid14 = new Color[][]{ new Color[]{ green99 }
, new Color[]{ Color.RED }
, new Color[]{ gray199 }
, new Color[]{ blue199 }
};
|
/** Return a Color very-close-to `src`, but slightly different (or perhaps even the same, occasionally). */
Color tint(Color src) { return new Color( Math.min(src.getRed()+2,255), Math.max(src.getGreen()-3,0), src.getBlue() ); }
|
This page licensed CC-BY 4.0 Ian Barland Page last generated | Please mail any suggestions (incl. typos, broken links) to ibarland |