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

Slides:



Advertisements
Similar presentations
Georgia Institute of Technology Drawing in Java – part 2 Barb Ericson Georgia Institute of Technology September 2005.
Advertisements

Conditionals-part31 Conditionals – part 3 Barb Ericson Georgia Institute of Technology Nov 2009.
TOPIC 9 MODIFYING PIXELS IN A MATRIX: COPYING, CROPPING 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach.
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)
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.
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.
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.
ManipulatingPictures-part11 Manipulating Pictures, Arrays, and Loops part 1 Barb Ericson Georgia Institute of Technology Nov 2009.
UsingSoundRanges-part21 Processing Sound Ranges part 2 Barb Ericson Georgia Institute of Technology Oct 2009.
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.
1 CS 177 Week 5 Recitation Slides Mirroring and copying images, Using for Loop, if statement, and range.
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.
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.
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.
Conditionals-Mod8-part41 Conditionals – part 4 Replace background Barb Ericson Georgia Institute of Technology May 2007.
Conditionals-part21 Conditionals – part 2 Barb Ericson Georgia Institute of Technology Nov 2009.
Georgia Institute of Technology Drawing in Java – part 3 Barb Ericson Georgia Institute of Technology September 2006.
Georgia Institute of Technology Conditionals – part 2 Barb Ericson Georgia Institute of Technology August 2005.
NestedLoops-part21 Nested Loops – part 2 Barb Ericson Georgia Institute of Technology Nov 2009.
Copyright © Curt Hill Further Picture Manipulation Considering position.
CSC 112Introduction to Media Computation 1 Rotating Images.
Conditionals-Mod8-part21 Conditionals – part 2 Edge Detection Barb Ericson Georgia Institute of Technology May 2007.
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.
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.
NestedLoops-Mod7-part61 Two-Dimensional Arrays and Nested Loops – part 6 Enlarge Barb Ericson Georgia Institute of Technology August 2005.
Georgia Institute of Technology Drawing in Java – part 2 Dr Usman Saeed Assistant Professor Faculty of Computing and Information Technology North Jeddah.
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
Barb Ericson Georgia Institute of Technology Dec 2009
Picture Functions ppp =makePicture(pickAFile())
Barb Ericson Georgia Institute of Technology August 2005
Workshop for Programming And Systems Management Teachers
Barb Ericson Georgia Institute of Technology August 2005
Working with ranges in pictures
Manipulating Pictures, Arrays, and Loops
Barb Ericson Georgia Institute of Technology August 2005
Two-Dimensional Arrays and Nested Loops – part 1
Barb Ericson Georgia Institute of Technology August 2005
Two-Dimensional Arrays and Nested Loops – part 2
Two-Dimensional Arrays and Nested Loops – part 5
Two-Dimensional Arrays and Nested Loops – part 1
Georgia Institute of Technology
Gray Scale picture def pixBW(pixel): # given a pixel, change to BW
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
Two-Dimensional Arrays and Nested Loops – part 6
Georgia Institute of Technology
Manipulating Pictures, Arrays, and Loops
Processing Sound Ranges part 2
Manipulating Pictures, Arrays, and Loops part 6
CSC1401 Viewing a picture as a 2D image - 2
Two-Dimensional Arrays and Nested Loops – part 6
Processing Sound Ranges part 3
Manipulating Pictures, Arrays, and Loops part 6
Presentation transcript:

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

Georgia Institute of Technology Learning Goals Understand at a conceptual and practical level –How can you make a picture smaller Scale it down –How can you make a picture bigger Scale it up –How do you create a collage?

Georgia Institute of Technology Scaling You can make a picture smaller –Faster to download on the web Increment the source x and y by a number larger than 1 –Don’t use all the source pixels in target You can make a picture larger –Show more detail Copy the same source x and y to more than one target x and y –Use source pixels more than once in target

Georgia Institute of Technology Scaling Down a Picture passionFlower.jpg is 640pixels wide and 480 pixels high If we copy every other pixel we will have a new picture with width (640 / 2 = 320) and height (480 / 2 = 240)

Georgia Institute of Technology Scaling Down Algorithm Create the target picture Invoke the method on the target picture –Create the source picture –Loop with source x starting at 0 and target x starting at 0 as long as < source width Increment the source x by 2 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 2 each time through the loop, increment the target y by 1 »Copy the color from the source to target pixel

Georgia Institute of Technology Scaling Down Method public void copyFlowerSmaller() { Picture flowerPicture = new Picture( FileChooser.getMediaPath(“passionFlower.jpg")); Pixel sourcePixel = null; Pixel targetPixel = null; // loop through the columns for (int sourceX = 0, targetX=0; sourceX < flowerPicture.getWidth(); sourceX+=2, targetX++) {

Georgia Institute of Technology Scaling Down Method - Continued // loop through the rows for (int sourceY=0, targetY=0; sourceY < flowerPicture.getHeight(); sourceY+=2, targetY++) { sourcePixel = flowerPicture.getPixel(sourceX,sourceY); targetPixel = this.getPixel(targetX,targetY); targetPixel.setColor(sourcePixel.getColor()); }

Georgia Institute of Technology Trying Copy Flower Smaller Create a new picture half the size of the original picture (+ 1 if odd size) –Picture p1 = new Picture(320,240); Copy the flower to the new picture –p1.copyFlowerSmaller(); Show the result –p1.show();

Georgia Institute of Technology 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)

Georgia Institute of Technology Scaling Up Algorithm Create the target picture Invoke the method on the target picture –Create the source picture –Loop with source x starting at 0 and target x starting at 0 as long as < 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

Georgia Institute of Technology Scaling Up Exercise Write a method copyFlowerBigger to scale up the picture flower1.jpg when you copy it to 640x480.jpg Save the result to a file using –pictureObj.write(“file”);

Georgia Institute of Technology Create a Collage One of the things that you can do with pictures is create a collage –There are two pictures of flowers flower1.jpg flower2.jpg –Both pictures are 100 pixels wide –The target picture is created from file 640x480.jpg The Picture’s bottom left is at x = 0 y = height - 5

Georgia Institute of Technology Create Collage Algorithm Create the target picture object –Using the 640x480 file Invoke the method on the target picture –Create the flower picture objects using flower1.jpg as source1Picture using flower2.jpg as source2Picture –Set targetBottomY to the targetPicture height – 5 5 pixels from bottom of picture

Georgia Institute of Technology Create Collage Algorithm - Cont –Copy all of source1Picture to the current picture starting at x=0, y=targetBottomY – source1Picture’s height –Copy all of source2Picture to the current picture starting at x=100, y = targetBottomY – source2Picture’s height –Negate source1Picture –Copy all of source1Picture to the current picture starting at x=200, y= targetBottomY – source1Picture’s height –Clear the blue from source2Picture –Copy all of source2Picture to the current picture starting at x=300, y= targetBottomY – source2Picture’s height –Copy all of source1Picture to the current picture starting at x=400, y=targetBottomY – source1Picture’s height

Georgia Institute of Technology Create Flower Collage Method public void createFlowerCollage() { Picture source1Picture = new Picture(FileChooser.getMediaPath("flower1.jpg")); Picture source2Picture = new Picture(FileChooser.getMediaPath("flower2.jpg")); int targetBottomY = this.getHeight() - 5; // copy source1Picture to 0, targetBottomY - height this.copy(source1Picture,0,0, source1Picture.getWidth(), source1Picture.getHeight(), 0,targetBottomY - source1Picture.getHeight()); // copy source2Picture to 100, targetBottomY - height this.copy(source2Picture,0,0, source2Picture.getWidth(), source2Picture.getHeight(), 100,targetBottomY - source2Picture.getHeight());

Georgia Institute of Technology Create Flower Collage Method - Cont // negate the source1Picture source1Picture.negate(); // copy negated source1Picture to 200 this.copy(source1Picture,0,0, source1Picture.getWidth(), source1Picture.getHeight(), 200,targetBottomY - source1Picture.getHeight()); // clear the blue from source 2 picture source2Picture.clearBlue(); // copy source2Picture to 300 this.copy(source2Picture,0,0, source2Picture.getWidth(), source2Picture.getHeight(), 300,targetBottomY - source2Picture.getHeight()); // copy negated source1Picture to 400 this.copy(source1Picture,0,0, source1Picture.getWidth(), source1Picture.getHeight(), 400,targetBottomY - source1Picture.getHeight()); }

Georgia Institute of Technology Testing createFlowerCollage String file = FileChooser.getMediaPath(“640x480.jpg”); Picture p = new Picture(file); p.show(); p.createFlowerCollage(); p.repaint();

Georgia Institute of Technology Create Collage Exercise Try creating a collage –At least 4 copies of an image in it –The original image and 3 changes to the original image Scale, rotate, crop, change colors –Then mirror the whole picture horizontally –Save your collage using pictureObj.write(fileName);

Georgia Institute of Technology Summary You can scale a picture down –By not copying all the pixels Increment the source index by a number > 1 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 You can create an image collage –Using the methods we have written