Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Sections 5.1 – 5.2 Digital Image Processing Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.

Similar presentations


Presentation on theme: "1 Sections 5.1 – 5.2 Digital Image Processing Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne."— Presentation transcript:

1 1 Sections 5.1 – 5.2 Digital Image Processing Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne

2 22 Introduction to Digital Image Processing The Essential Properties of Images: When an image is loaded in a program, the bits map into a rectangle of colored dots (pixels). The coordinates of the grid range from: – (0,0) at the upper-left corner to (Width -1, Height -1) at the lower-right corner. – Width and height are the dimensions in pixels. – X-coordinates increase positively to the right, y- coordinates increase positively to the bottom. 2

3 33 Introduction to Digital Image Processing (continued) The Essential Properties of Images (cont): An image consists of a width, height, and a set of pixels. Each pixel is accessible by its (x,y) coordinates. A pixel contains integer values that represent color in terms if red, green, and blue (RGB). 3

4 44 Introduction to Digital Image Processing (continued) The Essential Properties of Images (cont): The pixel at the upper- left corner is at (0,0) and has RGB components 206, 224, and 122. 4 An image with a width of 300 pixels and a height of 225 pixels

5 55 The images Package The images package defines classes that allow the programmer to: – Load an image from a file. – View the image in a window. – Examine and manipulate an image’s pixels. – Update the window with changes. – Save the image back to a file. 5

6 66 The images Package (continued) The APImage and Pixel Classes: The two most important classes in the images package. APImage methods include: – Creating an image from a file, or a blank image. – Returning image’s height and width. – Saving the image. 6

7 77 The images Package (continued) The APImage and Pixel Classes (cont): The Pixel class represents a pixel. – An object of this class contains three integer values to represent RGB. – Methods include: Creating a pixel and specifying RGB values. Returning and resetting the red, green, or blue values. Returning a copy of the pixel. Returning a string representation of the pixel (RGB values). 7

8 88 The images Package (continued) The Structure of a Simple Image- Processing Program: A program that loads an image (smokey.jpg) from its file and draws it in a window: 8

9 99 The images Package (continued) Interfaces, Object Instantiation, and Object- Based Programming: Object-based programming uses existing classes, objects, and methods to solve problems. To use an object, the programmer must know its interface (the set of methods it recognizes). 9

10 10 The images Package (continued) Interfaces, Object Instantiation, and Object- Based Programming (cont): An interface contains the headers of methods and supporting comments about their use. – Including methods’ names, types of parameters they expect, and types of values they return, if any. – No information about how methods work. Application programming interface (API): the set of interfaces in a package or language. 10

11 11 The images Package (continued) Interfaces, Object Instantiation, and Object- Based Programming (cont): Mutators: methods that do not return a value. – Used to modify the internal contents of an object. – setPixel and setRed Accesors: methods that return values. – Allow users to examine part of an object’s contents. – toString( ) returns a strong representation of the data contained in an object. 11

12 12 The images Package (continued) Interfaces, Object Instantiation, and Object- Based Programming (cont): Constructors have no return type. – A constructor is called when a new object of a given class is created or instantiated. – Some constructors can receive information in the form of parameters from the caller. 12

13 13 The images Package (continued) Examining the Attributes of an Image or a Pixel: getWidth and getHeight return the width and height of an image. A simple way to print the string representation of the image: 13

14 14 The images Package (continued) Modifying the Attributes of an Image or a Pixel: You can use the setPixel method to replace an RGB value at a given position in an image. 14

15 15 The images Package (continued) Using an Enhanced for Loop to Visit Pixels: An enhanced for loop or for-each loop: – Assumes you want to visit each element in the data structure for some purpose. – On each pass, the loop variable picks up the next available element in the data structure. 15

16 16


Download ppt "1 Sections 5.1 – 5.2 Digital Image Processing Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne."

Similar presentations


Ads by Google