CSC1401 Viewing a picture as a 2D image - 2

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

CSC1401 Drawing in Java - 2. Reminder from last class How do you save your modified picture? String filename = …; Picture stevePicture = new Picture(filename);
CIS101 Introduction to Computing Week 12. Agenda Your questions Solutions to practice text Final HTML/JavaScript Project Copy and paste assignment JavaScript:
CIS101 Introduction to Computing Week 07. Agenda Your questions Resume project Review Project Two HTML Project Three This week online Next class.
CSE 113 Week 5 February , Announcements  Module 2 due 2/15  Exam 3 is on 2/15  Module 3 due 2/22  Exam 4 is on 2/25  Module 4 due 2/29.
Conditionals-part11 Barb Ericson Georgia Institute of Technology Nov 2009.
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.
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.
Alice and Media Computation: Goals for this session Show interesting things you can do combining Alice and Media Computation. Provides a story-telling.
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.
CS2984: Introduction to Media Computation Using Loops for Pictures Conditionals Copying images.
Resizing Images CS 268. Where to start? Pictures (of course)  Need to down size them for the web.  Pictures taken with a 10 mega pixel camera are usually.
TOPIC 11 RETURNING VALUES FROM METHODS PICTURE TRANSFORMATIONS 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach.
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.
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.
Conditionals-part41 Conditionals – part 4 Barb Ericson Georgia Institute of Technology Dec 2009.
CSC1401 Using Decisions in Java - 1. Recall from Alice We only wanted to shoot a lightning bolt at a philosopher So, we used the If statement.
Georgia Institute of Technology Drawing in Java – part 3 Barb Ericson Georgia Institute of Technology September 2006.
NestedLoops-part21 Nested Loops – part 2 Barb Ericson Georgia Institute of Technology Nov 2009.
1 2/22/05CS120 The Information Era Chapter 4 Basic Web Page Construction TOPICS: Images and placing pages on the server.
Copyright © Curt Hill Further Picture Manipulation Considering position.
CSC 112Introduction to Media Computation 1 Rotating Images.
CS1315: Introduction to Media Computation Transforming pictures by index number.
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 Two-Dimensional Arrays and Nested Loops – part 4 Barb Ericson Georgia Institute of Technology August 2005.
CIS101 Introduction to Computing Week 07 Spring 2004.
Test 2 on Wed, 11/9 On image processing
Barbara Ericson Georgia Tech Sept 2005
Topic 9 Modifying Pixels in a Matrix: Copying, Cropping
Barb Ericson Georgia Institute of Technology Dec 2009
Manipulating Pictures, Arrays, and Loops part 3
Picture Functions ppp =makePicture(pickAFile())
Workshop for Programming And Systems Management Teachers
Two-Dimensional Arrays
Georgia Institute of Technology
Working with ranges in pictures
Barb Ericson Georgia Institute of Technology August 2005
Two-Dimensional Arrays and Nested Loops – part 1
Barb Ericson Georgia Institute of Technology August 2005
Test 2 on Wed, 11/9 On image processing
Two-Dimensional Arrays and Nested Loops – part 2
Two-Dimensional Arrays and Nested Loops – part 5
Two-Dimensional Arrays and Nested Loops – part 1
Gray Scale picture def pixBW(pixel): # given a pixel, change to BW
Manipulating Pictures, Arrays, and Loops 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
Georgia Institute of Technology
Scale Factor and the relationship to area and volume
Two-Dimensional Arrays and Nested Loops – part 6
Barb Ericson Georgia Institute of Technology May 2006
CSC1401 Manipulating Pictures 2
Presentation transcript:

CSC1401 Viewing a picture as a 2D image - 2

Review from the last week We treated a picture as a 2 dimensional array, and used the getPixel(x,y) method to access each of the pixels Since there were 2 dimensions (x and y), we needed a nested loop to access all of the pixels

Review A two-dimensional array has columns and rows Use nested loops to work with 2-d arrays One loop for the x direction and one for the y for (int x = 0; x < this.getWidth(); x++) { // loop through the rows (y direction) for (int y = 0; y < this.getHeight(); y++)

Learning Goals Understand at a conceptual and practical level How to copy pixels from one picture to another How to copy pixels from one picture to a specified location in another picture How to create larger or smaller pictures

Copying Pixels to a New Picture Need to track the source picture x and y And the target picture x and y 1 2 3 4 1 2 3 4

Copying Pixels to a New Picture 1 What if we want to copy the target to a different location in the source Than 0,0 Say startX and startY What is an algorithm that will do this? 1 2 3 4 1 1 2 3 1 2 3 4 1 2 3

Copy Picture Algorithm Copy a picture into another picture Create the picture objects Invoke the method on the target picture Loop through the source picture pixels Get the source and target pixels Set the color of the target pixel to the color of the source pixel

Copy Algorithm to Code Loop through the source pixels // loop through the columns for (x = 0; x < insertedPicture.getWidth(); x++) { // loop through the rows for (y = 0; y < insertedPicture.getHeight(); y++)

Copy Algorithm to Code – Cont Get the source and target pixels copyPixel = insertPicture.getPixel(x,y); targetX = ???; targetY = ???; targetPixel = this.getPixel(targetX,targetY); Set the color of the target pixel to the color of the source pixel targetPixel.setColor(copyPixel.getColor());

Creating a method What parameters are needed?

Copy Method

Trying out our method Copying Katie onto the beach I found an x value of 247 and a y value of 125 was a good location to copy her onto the beach (using the explore)

Scaling You can make a picture smaller You can make a picture larger 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

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) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 2 8 10

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

Scaling Down Method

Invoking the method Picture smaller = stevepicture.decreasePicture (2);

Thinking Through Scaling Up 1 2 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) 1 2 3 4 5 6 1 1 2 3 4 5 1 2 3 4 5 6 1 What could we add to source x and source y so that it is 0 twice, then 1 twice, then 2 twice, etc. Remember that 0.5 is 0 when you cast to integer. 2 3

Scaling Up Algorithm Create the target picture Invoke the method on the target picture Loop with source x starting at 0 as long as < source width Loop with source y starting at 0 as long as < source height Loop another x from 0 up to the factor of multiplication Loop another y from 0 up to the factor of multiplication Copy the color from the source to target pixel The source x and y will need to be double variables. Cast them to int to lose the fractional part to get the pixel x and y.

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”);

Summary To copy pixels from one picture to another Keep track of the sourceX, sourceY and targetX and targetY To copy one picture to a location in another Just keep track of the values for targetX and targetY

Assignment Review Media Computation Chapter 5, Section 2