190 likes | 619 Views
Example Two-Dimensional Arrays. Maps That street is in D-5 Battleship Try I-5 Hit or miss Chairs at a theater or game Row C seat 20. What is a two-dimensional array?. x. y. The pixels in a picture are really stored in a two-dimensional array
E N D
Example Two-Dimensional Arrays • Maps • That street is in D-5 • Battleship • Try I-5 • Hit or miss • Chairs at a theater or game • Row C seat 20 Georgia Institute of Technology
What is a two-dimensional array? x y • The pixels in a picture are really stored in a two-dimensional array • Each pixel has a x value (horizontal location) • Each pixel has a y value (vertical location) • pictureObj.getPixel(x,y) returns the pixel at that location Georgia Institute of Technology
Pixels • A pixel (abbr. for picture element) is the smallest unit of an image. • Therefore, a 640x480 image is a matrix of 640 columns and 480 rows, each element of this matrix is called an image pixel. Pixel
RGB and Grayscale • In RGB format, each Pixel has 3 color components: Red,Green, and Blue. • A grayscale pictures has values from 0 to 255 that produce a black and white image in those ranges of gray. So it has one color ranging from 0 to 255 creating different scales of white to black (grayscale). RGB Gray
GrayImage FreeResponse Instance Variables to use: public static final int BLACK = 0; public static final int WHITE = 255; 2D Array to use private int [][] pixelValues private int pixelValues[][] = {{255,184,178,84,135}, {84, 255, 255, 130, 84}, {78, 255, 0, 0, 78}, {84, 130, 255, 130, 84}}; Grayscale picture with 4 rows and 5 columns Georgia Institute of Technology
Methods to create public int countWhitePixels() (return method) { This method will loop through the 2D array of pixels in row-major order (row first then column) And return the number of pixels in the image that contain the value WHITE. Return an int } It should return 5 since there are 5 pixel values with WHITE (255) Georgia Institute of Technology
processImage() public void processImage() (void method performs an action) { It will modify the image by chaing in the values in the instance variable pixelValues [][] by the following: • Pixel value at position row col is decreased by the value at position [row+2] [col +2] if the row+2 and col + 2 position exist • If the subtraction results in < 0 change the pixel value at the position to BLACK. } Georgia Institute of Technology
Work on Free Response today. (Let’s get finished) • Work on multiple choice questions. These should be finished and turned in first thing Friday. I will grade these. • If you need help come see me Thursday during IF once you have looked over them and tried them. Georgia Institute of Technology