CSC1401 Manipulating Pictures. What we have done to date We have modified pictures by writing on top of them Using Turtles and using Graphics Drawing.

Slides:



Advertisements
Similar presentations
Python: Modifying Pictures Using Loops. Review JES command area – program area Defining/using functions specifying a sequence of steps for what the function.
Advertisements

TOPIC 5 INTRODUCTION TO PICTURES 1 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B.
ManipulatingPictures-Mod6-part21 Manipulating Pictures, Arrays, and Loops part 2 Barb Ericson Georgia Institute of Technology.
Georgia Institute of Technology Manipulating Pictures, Arrays, and Loops part 1.
© 2004 Pearson Addison-Wesley. All rights reserved2-1 Introduction to Graphics The last few sections of each chapter of the textbook focus on graphics.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Java Applets What is an Applet? How do you create.
Georgia Institute of Technology Manipulating Pictures, Arrays, and Loops part 1 Barb Ericson Georgia Institute of Technology August 2005.
A Simple Applet. Applets and applications An applet is a Java program that runs on a web page –Applets can be run from: Internet Explorer Netscape Navigator.
Chapter 5 Graphics. Topics Applets Classes used for graphics –Graphics –Point –Dimension –Color.
Java Review Structure of a graphics program. Computer Graphics and User Interfaces Java is Object-Oriented A program uses objects to model the solution.
Java Programs u 1 project file –with an extension of.mcp –contains information that CodeWarrior needs to run the program u >= 1 source files –have an extension.
How Images are Represented Bitmap images (Dots used to draw the image) Monochrome images 8 bit grey scale images 24 bit colour Colour lookup tables Vector.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Java Applets What is an Applet? How do you create.
CHAPTER 4 Images XNA Game Studio 4.0. Objectives Find out how the Content Manager lets you add pictures to Microsoft XNA games. Discover how pictures.
Georgia Institute of Technology Introduction to Media Computation Barb Ericson Georgia Institute of Technology May 2006.
TOPIC 4 INTRODUCTION TO MEDIA COMPUTATION: DIGITAL PICTURES Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach.
How to use the Java class libraries Brief documentation of how to do this all with Java.
NestedLoops-part11 Nested Loops – part 1 Barb Ericson Georgia Institute of Technology Nov 2009.
Copyright © 2009 Curt Hill The Picture Object Getting and displaying.
CSC1401 Viewing a picture as a 2D image - 1. Review from the last week We used a getPixels() to get all of the pixels of a picture But this has been somewhat.
Image Representation. Objectives  Bitmaps: resolution, colour depth and simple bitmap file calculations.  Vector graphics: drawing list – objects and.
ManipulatingPictures-part11 Manipulating Pictures, Arrays, and Loops part 1 Barb Ericson Georgia Institute of Technology Nov 2009.
1 Ethics of Computing MONT 113G, Spring 2012 Session 10 HTML Tables Graphics on the Web.
Georgia Institute of Technology Movies part 5 Barb Ericson Georgia Institute of Technology April 2006.
Jeopardy Heading1Heading2Heading3Heading4 Heading5 Q $100 Q $200 Q $300 Q $400 Q $500 Q $100 Q $200 Q $300 Q $400 Q $500 Final Jeopardy.
Two –Dimensional Arrays Mrs. C. Furman Java Programming November 19, 2008.
Applets Applet is java program that can be embedded into HTML pages. Java applets runs on the java enabled web browsers such as mozilla and internet explorer.
Chapter 2: Color and Applets Coming up: Introduction to Graphics.
CSC1401. Learning Goals Understand at a conceptual level What is media computation? How does color vision work? How can you make colors with red, green,
TOPIC 11 RETURNING VALUES FROM METHODS PICTURE TRANSFORMATIONS 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach.
Digital Pictures Represented by pixels –With a red, green, and blue value stored for each pixel (each has a range from 0 to 255) Stored in.jpg (JPEG) files.
ManipulatingPictures-Mod6-part11 Manipulating Pictures, Arrays, and Loops part 1 Barb Ericson Georgia Institute of Technology.
TOPIC 6 MODIFYING PICTURES USING LOOPS 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Introduction to Android (Part.
TOPIC 5 INTRODUCTION TO PICTURES 1 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B.
1 Computer Science 631 Multimedia Systems Prof. Ramin Zabih Computer Science Department CORNELL UNIVERSITY.
Classes Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Image File Formats. What is an Image File Format? Image file formats are standard way of organizing and storing of image files. Image files are composed.
Classes. Preparation Scene so far has been background material and experience –Computing systems and problem solving –Variables –Types –Input and output.
GUI Components. The Swing package has numerous GUI components that can be added to a window. The Swing package has numerous GUI components that can be.
Georgia Institute of Technology Manipulating Pictures, Arrays, and Loops Barb Ericson Georgia Institute of Technology August 2005.
Image File Formats By Dr. Rajeev Srivastava 1. Image File Formats Header and Image data. A typical image file format contains two fields namely Dr. Rajeev.
Aquarium Lab Series Developed by Alyce BradyAlyce Brady of Kalamazoo CollegeKalamazoo College.
TOPIC 4 INTRODUCTION TO MEDIA COMPUTATION: DIGITAL PICTURES Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach.
04-ManipulatingPictures-part21 Manipulating Pictures, Arrays, and Loops part 2 Barb Ericson Georgia Institute of Technology June 2008.
Information Systems Design and Development Media Types Computing Science.
CompSci 4 Java 4 Apr 14, 2009 Prof. Susan Rodger.
Intro to Graphics from Chapter 2 of Java Software Solutions
Getting and displaying
Manipulating Pictures, Arrays, and Loops part 1
Computer Science Higher
Object Oriented Programming
Digital Pictures Represented by pixels Stored in .jpg (JPEG) files
Week 13 - Monday CS 121.
Manipulating Pictures, Arrays, and Loops part 2
File Formats V
Two-Dimensional Arrays and Nested Loops – part 1
Workshop for Programming And Systems Management Teachers
Representing Images 2.6 – Data Representation.
Two-Dimensional Arrays and Nested Loops – part 1
CSE 8A Lecture 6 Reading for next class:
Manipulating Pictures, Arrays, and Loops
Manipulating Pictures, Arrays, and Loops part 1
COMS 161 Introduction to Computing
COMS 161 Introduction to Computing
Digital Pictures Represented by pixels Stored in .jpg (JPEG) files
CS 177 Week 3 Recitation Slides
Digital Pictures Represented by pixels Stored in .jpg (JPEG) files
CSC1401 Manipulating Pictures 2
Presentation transcript:

CSC1401 Manipulating Pictures

What we have done to date We have modified pictures by writing on top of them Using Turtles and using Graphics Drawing lines, shapes and text, as well as inserting a picture into another picture

What would be nice to do Changing colors on the pictures Red-eye reduction Blending pictures Doing other fancy Adobe Photoshop-like transformations But this would be almost impossible to do by simply drawing on top of the existing picture

The Goal Develop an easier approach to modifying our pictures by changing the pictures themselves rather than writing on top of them

Digital Pictures Represented by pixels With a red, green, and blue value stored for each pixel Stored in.jpg (JPEG) files International standard With lossy compression Lossy means not all data is stored But what is lost isn’t that important Compression means made smaller Other formats for storing digital pictures are GIF and BMP

Manipulating a Picture To manipulate a picture we need to manipulate the pixels that make up the picture Change the red, green, or blue values at the pixel Pixel is a class created at Georgia Tech Each pixel object has a red, green, and blue value

Pictures have lots of Pixels How can we refer to each pixel? pixel1, pixel2, pixel3, pixel4, pixel5, … Do we really want to name each one? On a 640 x 480 picture, there are 640 x 480 = 307,200 pixels

How do we change a Pixel? Pixel first; first = stevepicture.getPixel(10,120); // 10 refers to the row and 120 to the column first.setColor(Color.black); /* The book writes the code as: stevepicture.getPixel(10,100).setColor(Color.black); */ Note that if you have already shown the picture, by invoking: stevepicture.show(); You can cause the picture to be updated by: stevepicture.repaint();

Pictures have lots of Pixels How do we deal with lots of data of the same type? Use an array

What is an Array? Storage for a sequence of items Of the same type You can access items by using an index The index starts at 0 The first item is at index 0 The last item is at index (length – 1) Arrays know their length (have a public length field) arrayObj.length

But how does an array help us? If we wish to change lots of pictures, we can use a loop!

Recall from Alice In this example, each time through the loop, the bunny hopped Note that the index variable changes from 0 to 1 to 2 to … each time through the loop. And we can take advantage of that when working with arrays!

In Java Use a loop to access an array of pixels The first time through the loop we access pixelArray[0] The second time through the loop we access pixelArray[1] …

What Data does a Picture Object Have? A picture object has an array of pixel objects That it read from the.JPG file It knows the picture width pictureObj.getWidth() It knows the picture height pictureObj.getHeight() It knows how to return an array of pixels Pixel[] pixelArray = pictureObj.getPixels()

Pixel Objects Each pixel has a red, green, and blue value getRed(), getGreen(), getBlue() setRed(v), setGreen(v), setBlue(v) Each pixel knows the location it was in the picture object getX(), getY() You can also get and set the color at the pixel getColor(), setColor(color)

Turning all of the pixels in our picture to red – using a loop Notes: 1)We have created a counter that starts at 0, and goes up to the number of pixels in the picture 2)Each pixel has its color set to red! 3)How would this code have looked had it been written as a method inside of the Picture class?

A note on Color You can either set the red, green and blue amounts individually, or all together using mypixel.setColor(someColor) You can create a color object by giving the red, green, and blue values for it Color colorObj = new Color(255,10,125);

Predefined Colors The Color class has defined class constants for many colors Color.red, Color.green, Color.blue, Color.black, Color.white, Color.yellow, Color.gray, Color.orange, Color.pink, Color.cyan, Color.magenta Or you can use all uppercase names Color.RED, Color.BLUE, Color.BLACK, …

Getting and Setting Pixel Colors To get a pixel’s color as a color object Color color1 = pixelObj.getColor(); int red = color1.getRed(); int green = color1.getGreen(); int blue = color1.getBlue(); To set a pixel’s color using a new color object red = 20; green = 30; blue = 100; Color color2 = new Color(red,green,blue); pixelObj.setColor(color2);

Changing Pixel Colors There are two ways to change the color of a pixel in a picture Set the red, green, and blue values individually pixelObj.setRed(value), pixelObj.setGreen(value), pixelObj.setBlue(value), Or set the color pixelObj.setColor(colorObj) But, you won’t see any change in the picture Until you ask it to repaint: pictureObj.repaint(); Or you invoke the show method

Summary Pictures have pixels You can change the picture by changing the color of the pixels Arrays let you store and retrieve values of the same type using an index You can ask a picture for it’s width, height, and an array of pixels You can get and set the color of a pixel

Assignment Read Media Computation Chapter 4 – we’ll be covering while loops and for- each loops next week