CSE 8A Lecture 8 Reading for next class: None Prepare for In-term exam 2 PSA4: Collage and Picture Flip, DON’T WAIT (it’s longer than the previous PSAs)

Slides:



Advertisements
Similar presentations
A Media Computation Cookbook Manipulating Images and Sounds for Use in Alice Part 1: Image Manipulations Part 2: Advanced Image Manipulations, e.g., changing.
Advertisements

ManipulatingPictures-Mod6-part21 Manipulating Pictures, Arrays, and Loops part 2 Barb Ericson Georgia Institute of Technology.
Manipulating 2D arrays in Java
Manipulating Pictures CS1316: Representing Structure and Behavior.
Georgia Institute of Technology Two-Dimensional Arrays and Nested Loops – part 6 Barb Ericson Georgia Institute of Technology August 2005.
TOPIC 9 MODIFYING PIXELS IN A MATRIX: COPYING, CROPPING 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach.
Copying and Transforming Pictures. First, finding the min or max… Next homework asks you to write a function to find the darkest and lightest shade of.
NestedLoops-part31 Nested Loops – part 3 Barb Ericson Georgia Institute of Technology Nov 2009.
UML Basics & Access Modifier
How to use the Java class libraries Brief documentation of how to do this all with Java.
TOPIC 7 MODIFYING PIXELS IN A MATRIX NESTED FOR LOOPS 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by.
Chapter 6: Modifying Pixels by Position. Chapter Learning Goals.
NestedLoops-part11 Nested Loops – part 1 Barb Ericson Georgia Institute of Technology Nov 2009.
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
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.
02-RangesInPictures1 Barb Ericson Georgia Institute of Technology Oct 2010 Working with ranges in pictures.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 7 The Game Loop and Animation Starting Out with Games & Graphics.
CSE8A Lecture3 TODO: –Finish PSA1 individually (no partner!) and turn it in with the bundlePSA1 command GET AN INTERVIEW for PSA1 from a tutor See tutor.
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
IReport Demo Spring 2008 OEDSA Conference. Report Properties.
TOPIC 11 RETURNING VALUES FROM METHODS PICTURE TRANSFORMATIONS 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach.
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
CSE 8A Lecture 8 Reading for next class: PSA4: Collage and Picture Flip, DON’T WAIT (it’s longer than the previous PSAs)
1 CS 177 Week 5 Recitation Slides Mirroring and copying images, Using for Loop, if statement, and range.
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
NestedLoops-Mod7-part31 Two-Dimensional Arrays and Nested Loops – part 3 Bugs in the garden Originally by Barb Ericson Georgia Institute of Technology.
Chapter 4: Modifying Pixels in a Range (partial slide deck)
Introduction to Computing and Programming in Python: A Multimedia Approach Chapter 4: Modifying Pixels in a Range.
Georgia Institute of Technology Two-Dimensional Arrays and Nested Loops – part 5 Barb Ericson Georgia Institute of Technology August 2005.
NestedLoops-part41 Nested Loops – part 4 Barb Ericson Georgia Institute of Technology Nov 2009.
NestedLoops-Mody7-part51 Two-Dimensional Arrays and Nested Loops – part 5 Rotations Barb Ericson Georgia Institute of Technology May 2007.
February ,  2/16: Exam 1 Makeup Papers Available  2/20: Exam 2 Review Sheet Available in Lecture  2/27: Lab 2 due by 11:59:59pm  3/2:
CSE 110 Review Session Hans Hovanitz, Kate Kincade, and Ian Nall.
NestedLoops-part21 Nested Loops – part 2 Barb Ericson Georgia Institute of Technology Nov 2009.
Copyright © Curt Hill Further Picture Manipulation Considering position.
CSE 8A Lecture 14 Reading for next class: None (INTERM EXAM #3) Today’s topics: –More Sounds! PSA 6 due tonight PSA 7 (sounds) due next Monday (11/19)
CS1315: Introduction to Media Computation Transforming pictures by index number.
CSE8A Lecture 5 TODO: –FINISH PSA2 WITH YOUR PARTNER! Read next class: Section 5.1. PLAY WITH CODE! –Get stuck, then figure out how to get unstuck – it’s.
04-ManipulatingPictures-part21 Manipulating Pictures, Arrays, and Loops part 2 Barb Ericson Georgia Institute of Technology June 2008.
1 Sections 5.1 – 5.2 Digital Image Processing Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
NestedLoops-Mod7-part61 Two-Dimensional Arrays and Nested Loops – part 6 Enlarge Barb Ericson Georgia Institute of Technology August 2005.
CompSci 4 Java 4 Apr 14, 2009 Prof. Susan Rodger.
Georgia Institute of Technology Two-Dimensional Arrays and Nested Loops – part 4 Barb Ericson Georgia Institute of Technology August 2005.
Pixels, Colors and Shapes
Topic 9 Modifying Pixels in a Matrix: Copying, Cropping
Manipulating Pictures, Arrays, and Loops part 2
Manipulating Pictures, Arrays, and Loops part 2
CSE 8A Lecture 17 Reading for next class: None (interm exam 4)
Creative Commons Attribution Non-Commercial Share Alike License
Workshop for Programming And Systems Management Teachers
Manipulating Pictures
Manipulating Pictures, Arrays, and Loops part 2
Two-Dimensional Arrays and Nested Loops – part 5
CSE 8A Lecture 6 Reading for next class:
Gray Scale picture def pixBW(pixel): # given a pixel, change to BW
Manipulating Pictures
Two-Dimensional Arrays and Nested Loops – part 4
Two-Dimensional Arrays and Nested Loops – part 3
Two-Dimensional Arrays and Nested Loops – part 6
Manipulating Pictures, Arrays, and Loops
Two-Dimensional Arrays and Nested Loops – part 6
Creative Commons Attribution Non-Commercial Share Alike License
CSC1401 Viewing a picture as a 2D image - 2
February , 2009 CSE 113 B.
Creative Commons Attribution Non-Commercial Share Alike License
Two-Dimensional Arrays and Nested Loops – part 6
IPC144 Introduction to Programming Using C Week 4 – Lesson 2
Manipulating Pictures, Arrays, and Loops
Presentation transcript:

CSE 8A Lecture 8 Reading for next class: None Prepare for In-term exam 2 PSA4: Collage and Picture Flip, DON’T WAIT (it’s longer than the previous PSAs) How missed classes are calculated… PSA3 Interview, deadline tomorrow! CLICKERS OUT!

1. If this is the header to a function defined in Picture.java: public Picture scaleUp(int numTimes) {.... } What should the method call look like if I call it on a Picture object named pictObj and I wanted to use the Picture object that it returns? READING QUIZ – NO TALKING – CORRECTNESS MATTERS A. Picture pictReturned = scaleUp(2); B. Picture pictReturned = pictObj.scaleUp(2); C. String pictReturned = pictObj.scaleUp(2); D. Picture = pictObj.scaleUp(2);

2.To scale a picture smaller by 2 (to make a copy of the picture that is half the size of the source) what should go in the blanks public void copySmaller() { Picture pictObj = new Picture(FileChooser.pickAFile()); Pixel sourcePixel = null; Pixel targetPixel = null; //loop through the columns for(int sourceX=0, targetX=0; sourceX < pictObj.getWidth(); ____1_____, targetX++) { //loop through the rows for(int sourceY=0; targetY=0; soruceY < pictObj.getHeight(); ____2____, targetY++) { sourcePixel = pictObj.getPixel(sourceX, sourceY); targetPixel = this.getPixel(targetX,targetY); targetPixel.setColor(sourcePixel.getColor()); } } } A. 1. sourceX++ 2. sourceY+=2 B. 1. sourceX+=2 2. sourceY+=2 C. 1. sourceX+=2 2. sourceY++ D. 1. sourceX++ 2. sourceY++ READING QUIZ – NO TALKING – CORRECTNESS MATTERS

3. How do I blend two picture objects with 50% of one picture and 50% of another picture? A. By multiplying their colors together and by 0.5 B. By adding them together C. By multiplying their colors by 0.5 and then adding them READING QUIZ – NO TALKING – CORRECTNESS MATTERS

4. Imagine that you have a method copyPictureTo, whose header is below, defined in Picture.java. This method copies the source Picture ( sourcePic ) and places its top left corner at ( xStart, yStart ) of the Picture that called the copyPictureTo method. public void copyPictureTo(Picture sourcePic, int xStart, int yStart) Assume you have already created two Picture objects: sourcePic and pictObj, and you make the following call: pictObj.copyPictureTo(sourcePict, pictObj.getWidth()/2, 0); Which position below best represents where the sourcePic will be located in picObj after the call? Assume that sourcePic is much smaller than pictObj. READING QUIZ – NO TALKING – CORRECTNESS MATTERS picObj AB CD Arrows indicate half the target picture width and height

Mirroring Even Width versus Odd Width int mirrorPt = getWidth() / 2;... for (int x = 0; x < mirrorPt; x++)

Mirroring Odd-width Pictures What happens when this code attempts to mirror a Picture around the vertical axis when the Picture’s width is odd (e.g. 101)? 1)Solo: (30 sec) 2)Discuss: (2min) 3)Group: (30 sec) int mirrorPt = getWidth()/2; Pixel leftP, rightP; for (int y = 0; y < getHeight(); y++) { for (int x = 0; x < mirrorPt; x++) { leftP = getPixel(x,y); rightP = getPixel(getWidth()-1-x,y); rightP.setColor(leftP.getColor()); } A.It will work fine B.It will run, but it won’t mirror correctly C.I won’t run, there will be an index out of bounds exception D.It won’t even compile if getWidth() is odd

Mirroring Odd-width Pictures What happens when this code attempts to mirror a Picture around the vertical axis when the Picture’s width is odd (e.g. 101)? 1)Solo: (30 sec) 2)Discuss: (2min) 3)Group: (30 sec) int mirrorPt = getWidth()/2; Pixel leftP, rightP; for (int y = 0; y < getHeight(); y++) { for (int x = 0; x < mirrorPt; x++) { leftP = getPixel(x,y); rightP = getPixel(getWidth()-1-x,y); rightP.setColor(leftP.getColor()); } A.It will work fine B.It will run, but it won’t mirror correctly C.I won’t run, there will be an index out of bounds exception D.It won’t even compile if getWidth() is odd

What are the first (x,y) coords for topP and bottomP to mirror around horizontal axis? topP bottomP A. (0,0) (0,3) (0,1) (0,2) (1,0) (1,3) B. (0,0) (0,3) (1,0) (1,3) (2,0) (2,3) 1)Solo: (30 sec) 2)Discuss (1 min) 3)Group C. either A or B will work D. none of the above

Challenge: Complete the code that mirrors in the order specified by answer B topP bottomP B. (0,0) (0,3) (1,0) (1,3) (2,0) (2,3) int height = getHeight(); int width = getWidth(); int mid = height/2; Pixel topP, botP; for ( ){ topP = getPixel( ); botP = getPixel( ); botP.setColor(topP.getColor()); }

Order of copying pixels When mirroring, we need to copy certain pixels to certain other pixels It doesn’t matter what order we copy in, as long as when we are done, pixels have been copied correctly Two most common orders: Row major order: copy all the pixels in one row, then go on to the next row Column major order: copy all the pixels in one column, then go on to the next column

Mirroring around horizontal axis topP botP A. (0,0) (0,3) (0,1) (0,2) (1,0) (1,3) … … int height = getHeight(); int width = getWidth(); int mid = height/2; Pixel topP, botP; for(int y=0; y<mid; y++) { for(int x=0; x<width; x++) { topP = getPixel(x,y); botP = getPixel(x,height-1-y); // copy one to the other… } int height = getHeight(); int width = getWidth(); int mid = height/2; Pixel topP, botP; for(int x=0; x<width; x++) { for(int y=0; y<mid; y++) { topP = getPixel(x,y); botP = getPixel(x,height-1-y); // copy one to the other… } column-major order row-major order topP botP B. (0,0) (0,3) (1,0) (1,3) (2,0) (2,3) … …

Challenge: What does this code do? Hint: trace some of the getPixel index values. int magic = getWidth()/2; Pixel foo, bar; for(int y = 0; y < getHeight(); y++) { int countingDown = getWidth()-1; for(int x = 0; x < magic; x++) { foo = getPixel(x,y); bar = getPixel(countingDown,y); bar.setColor(foo.getColor()); countingDown--; } A.Copies top half into bottom half not mirrored. B.Copies left half into right half not mirrored. C.Mirrors around vertical axis, left into right D.Mirrors around horizontal axis, top into bottom E.Some other bizarre transformation 1)Solo: (1 min) 2)Discuss: (2 min) 3)Group: (30 sec)

Challenge: What does this code do? Hint: trace some of the getPixel index values. int magic = getWidth()/2; Pixel foo, bar; for(int y = 0; y < getHeight(); y++) { int countingDown = getWidth()-1; for(int x = 0; x < magic; x++) { foo = getPixel(x,y); bar = getPixel(countingDown,y); bar.setColor(foo.getColor()); countingDown--; } 1)Solo: (1 min) 2)Discuss: (2 min) 3)Group: (30 sec) x y countingDown foo bar

By what variable name do we refer to collage inside makeC in Picture.java? A.collage B.callingObject C.Object D.Picture E.this public class Lab4 { public static void main(String[] args) { Picture collage = new Picture("blank.jpg"); Picture p = new Picture("bird1.jpg"); Picture q = new Picture("bird2.jpg"); collage.makeC(p,q); } public class Picture { public void makeC(Picture p1, Picture p2) { Pixel[] targetPixels = _______.getPixels(); // … more code }

Match the scenario to the constructor call (we’ll vote for each scenario) Scenario 1)Create a picture from a specific file 2)Create a picture that is a copy of another picture 3)Create a picture of a given width and height 4)Create a picture of the same width and height as another picture Call A.Picture p = new Picture(); B.Picture p = new Picture("filename.jpg"); C.Picture p = new Picture(other); D.Picture p = new Picture(aNum,bNum);

What does this code do? Makes red box of width height 1)Solo: (1 min) 2)Discuss: (2 min) 3)Group: (30 sec) Pixel foo; for(int y = 40; y < 50; y++) { for(int x = 1 ; x < 5; x++) { foo = getPixel(x,y); foo.setColor(Color.RED); }

What does this code do? Makes red box of width height 1)Solo: (1 min) 2)Discuss: (2 min) 3)Group: (30 sec) Pixel foo; for(int y = 40; y < 50; y++) { for(int x = 1 ; x <= 5; x++) { foo = getPixel(x,y); foo.setColor(Color.RED); }

What are correct loops to make a black box of width x and height y? public void foo(int x, int y) { Pixel foo; >>> { foo = getPixel(w,h); foo.setColor(Color.BLACK); } 1)Solo: (1 min) 2)Discuss: (2 min) 3)Group: (30 sec) A) for (int w = 0; w <= x; w++) for (int h = 0; h <= y; h++) B) for (int w = 10; w < x+10; w++) for (int h = 20; h < y+20; h++) C) for (int w = 0; w < y; w++) for (int h = 0; h < x; h++) D) for(int w = 10; w <= x+10; w++) for(int h = 20; h <= y+20; h++)

From the book: Cropping A Picture (page ) – we’ll change a bit Example of: –Working with both the calling object and a parameter object in a method Extra information is passed to methods through parameters. The calling object is something like an extra parameter, named this –Doing something to a subset of the possible pixels in a picture

What part of Katie are we copying? (slight mod from the book) public void copyKatiesXXX(Picture sourcePic) { Pixel sPixel = null, tPixel = null; for (int sX = 40, tX = 100; sX < 110; sX++, tX++) { for (int sY = 350, tY = 100; sY < 400; sy++, tY++) { sPixel = sourcePic.getPixel(sX,sY); tPixel = this.getPixel(tX,tY); tPixel.setColor(sPixel.getColor(); } 1)Solo: (1 min) 2)Discuss: (2 min) 3)Group: (30 sec) A.Feet B.Part of dress C.Hands D.Part of Couch E.Face

Parameters: getting information in to methods It’s nice to have code that is “user controllable”… We have been hard-coding constants (40, 3, 100, for example) a lot, but we can write more flexible code using PARAMETERS This lets us write code to do things like “cropping and pasting into a blank canvas”, but letting the user specify what part of the source picture to crop, and where to place it in the canvas.

Underline the values you would change into parameters and write a new method header public void copyKatiesXXX( ) { Pixel sPixel, tPixel = null; for (int sX = 40, tX = 100; sX < 110; sX++, tX++) { for (int sY = 350, tY = 100; sY < 400; sy++, tY++) { sPixel = sourcePic.getPixel(sX,sY); tPixel = this.getPixel(tX,tY); tPixel.setColor(sPixel.getColor(); }

TODO Study for In-term Exam 2 Start PSA4: Collage and Picture Flip Don’t forget your PSA3 interview!