NestedLoops-Mod7-part61 Two-Dimensional Arrays and Nested Loops – part 6 Enlarge Barb Ericson Georgia Institute of Technology August 2005.

Slides:



Advertisements
Similar presentations
ManipulatingPictures-Mod6-part21 Manipulating Pictures, Arrays, and Loops part 2 Barb Ericson Georgia Institute of Technology.
Advertisements

Computer Science 1620 Multi-Dimensional Arrays. we used arrays to store a set of data of the same type e.g. store the assignment grades for a particular.
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.
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.
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.
Copyright 2008 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-3: Loop Figures and Constants reading: self-checks: 27 exercises:
Visual Basic.net Loops. Used to do multiple executions of the same block of code Do while loops Do until loops For next loops.
UsingSoundRanges-part21 Processing Sound Ranges part 2 Barb Ericson Georgia Institute of Technology Oct 2009.
Lec 20 More Arrays--Algorithms. Agenda Array algorithms (section 7.5 in the book) – An algorithm is a well-defined specification for solving a problem.
TOPIC 11 RETURNING VALUES FROM METHODS PICTURE TRANSFORMATIONS 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach.
Georgia Institute of Technology Manipulating Pictures, Arrays, and Loops Barb Ericson Georgia Institute of Technology August 2005.
TOPIC 6 MODIFYING PICTURES USING LOOPS 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and.
1 CS 177 Week 5 Recitation Slides Mirroring and copying images, Using for Loop, if statement, and range.
CS 101: Introduction to Computing Rotating and Blurring Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified by Robert H. Sloan,
NestedLoops-Mod7-part31 Two-Dimensional Arrays and Nested Loops – part 3 Bugs in the garden Originally by Barb Ericson Georgia Institute of Technology.
ManipulatingPictures-Mod6-part61 Manipulating Pictures, Arrays, and Loops: Eliminating color, Inversion, grey scale and adjusting for luminance Barb Ericson.
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.
Georgia Institute of Technology More on Creating Classes part 2 Barb Ericson Georgia Institute of Technology Oct 2005.
CPSC1301 Computer Science 1 Chapter 4 Manipulating Pictures, Arrays, and Loops part 5.
Conditionals-part41 Conditionals – part 4 Barb Ericson Georgia Institute of Technology Dec 2009.
Georgia Institute of Technology Speed part 4 Barb Ericson Georgia Institute of Technology May 2006.
1 BUILDING JAVA PROGRAMS CHAPTER 2 PRIMITIVE DATA AND DEFINITE LOOPS.
NestedLoops-part21 Nested Loops – part 2 Barb Ericson Georgia Institute of Technology Nov 2009.
CS1315: Introduction to Media Computation Transforming pictures by index number.
ManipulatingPictures-part31 Manipulating Pictures, Arrays, and Loops part 3 Barb Ericson Georgia Institute of Technology Nov 2009.
Copyright 2008 by Pearson Education 1 Nested loops reading: 2.3 self-check: exercises: videos: Ch. 2 #4.
04-ManipulatingPictures-part21 Manipulating Pictures, Arrays, and Loops part 2 Barb Ericson Georgia Institute of Technology June 2008.
Georgia Institute of Technology Two-Dimensional Arrays and Nested Loops – part 2 Barb Ericson Georgia Institute of Technology August 2005.
Georgia Institute of Technology Two-Dimensional Arrays and Nested Loops – part 4 Barb Ericson Georgia Institute of Technology August 2005.
Topic 9 Modifying Pixels in a Matrix: Copying, Cropping
Manipulating Pictures, Arrays, and Loops part 2
Manipulating Pictures, Arrays, and Loops part 3
CSCI 161 – Introduction to Programming I William Killian
Processing Sound Ranges part 3
Workshop for Programming And Systems Management Teachers
Chapter 5 Repetition.
Manipulating Pictures, Arrays, and Loops part 2
Manipulating Pictures, Arrays, and Loops part 2
Working with ranges in pictures
Manipulating Pictures, Arrays, and Loops
Two-Dimensional Arrays and Nested Loops – part 1
Manipulating Pictures, Arrays, and Loops part 5
Two-Dimensional Arrays and Nested Loops – part 2
Two-Dimensional Arrays and Nested Loops – part 5
Two-Dimensional Arrays and Nested Loops – part 1
Building Java Programs
Manipulating Pictures, Arrays, and Loops part 3
Introduction to Processing Digital Sounds part 3
Two-Dimensional Arrays and Nested Loops – part 4
Two-Dimensional Arrays and Nested Loops – part 3
Two-Dimensional Arrays and Nested Loops – part 6
Two-Dimensional Arrays and Nested Loops – part 2
Manipulating Pictures, Arrays, and Loops
Manipulating Pictures, Arrays, and Loops
Two-Dimensional Arrays and Nested Loops – part 6
Manipulating Pictures, Arrays, and Loops
Building Java Programs
Processing Sound Ranges part 2
CSC1401 Viewing a picture as a 2D image - 2
Two-Dimensional Arrays and Nested Loops – part 6
Manipulating Pictures, Arrays, and Loops
Processing Sound Ranges part 3
Manipulating Pictures, Arrays, and Loops part 6
Presentation transcript:

NestedLoops-Mod7-part61 Two-Dimensional Arrays and Nested Loops – part 6 Enlarge Barb Ericson Georgia Institute of Technology August 2005

NestedLoops-Mod7-part62 Thinking Through Scaling Up Copy each pixel in the source multiple times to the target –Source (0,0) Target (0,0) –Source (0,0) Target(1,0) –Source (1,0) Target(2,0) –Source (1,0) Target(3,0) –Source (2,0) Target(4,0) –Source (2,0) Target(5,0) –Source (0,0) Target(0,1) –Source (0,0) Target(1,1)

NestedLoops-Mod7-part63 Idea If you move through the source picture half as fast as the target picture, you’ll get 2 pixels in the target for each 1 in the source

NestedLoops-Mod7-part64 Scaling Up Algorithm Create the source picture Create a new target picture double the height and width of the source –Loop with source x starting at 0 and target x starting at 0 as long as source x< source width Increment the source x by 0.5 each time through the loop, increment the target x by 1 Loop with source y starting at 0 and target y starting at 0 as long as < source height –Increment the source y by 0.5 each time through the loop, increment the target y by 1 »Copy the color from the source to target pixel

NestedLoops-Mod7-part65 Can you get a pixel at position (0.5,1)? –No –You can only get pixels at whole number positions Can you increment the index number by 0.5? –int index = 0; –index = index + 0.5; –ERROR! Loss of precision, the equation on the right is now a double, it won’t fit into the variable on the left.

NestedLoops-Mod7-part66 How to solve the ½ pixel problem Can you do this? int index = 0; index = (int)index + 0.5; –NO –That just casts index into an integer, which it already is, then adds 0.5 so now the answer on the right is still a double

NestedLoops-Mod7-part67 Solving the ½ pixel problem How about: int index = 0; index = (int)(index + 0.5) –Nice idea, but that adds index+0.5 and then chops the.5 right off again. How about: double counter = 0.0; index = (int)(counter + 0.5); –OK, that works, but how to use it in a loop?

NestedLoops-Mod7-part68 Here’s a loop that uses a double for(double d=0; d<2; d+=0.5){ System.out.println(d); } What prints? –0.0 –0.5 –1.0 –1.5

NestedLoops-Mod7-part69 Here’s a loop that uses 2 doubles for(double d=0, i=0; d<2; d+=0.5, i++){ System.out.println(d+” “+i); } What prints? – – – –

NestedLoops-Mod7-part610 Looping by halves –The counters are doubles: countSx, countSy, countTx, countTy –Loop with countSx starting at 0 and countTx starting at 0 as long as countSx < source width Increment the countSx by 0.5 each time through the loop, increment the countTx by 1 Loop with countSy starting at 0 and countTy starting at 0 as long as countSy < source height –Increment the counters y by 0.5 each time through the loop, increment the countTy by 1 »sourcex = (int) countSx ; targetx = (int) countTx; »sourcey = (int) countSy ; targety = (int) countTy; »Copy the color from the source to target pixel

NestedLoops-Mod7-part611 Scaling Up Exercise Write a method copyBigger to scale up the picture flower1.jpg when you copy it. You need 2 methods in your copy/duplicate class: public static void testBigger(){ –// makes the 2 pictures, the source and target –// calls copyBigger –// displays the target picture } public static void copyBigger (Picture smallPic, Picture copied){ –// makes the copy –}

NestedLoops-Mod7-part612 Summary You can scale a picture up –By copying the source pixels more than one time You can increment the source index by 0.5 and then cast it to integer Look at your code to shrink pictures for help with the syntax and coding. Put these methods in the same class as your copy method.