1 / 8

Example Two-Dimensional Arrays

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

randy
Télécharger la présentation

Example Two-Dimensional Arrays

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

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

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

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

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

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

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

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

More Related