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.

Slides:



Advertisements
Similar presentations
Use Tables for Layout Control Day 7. You will learn to: Understand Tables Create a Simple Table Modify Your Tables Appearance Create Page Layouts with.
Advertisements

Two-Dimensional Arrays Chapter What is a two-dimensional array? A two-dimensional array has “rows” and “columns,” and can be thought of as a series.
Introduction to Computers and Programming Lecture 10: For Loops Professor: Evan Korth New York University.
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.
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.
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.
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.
CS 112 Introduction to Programming Variable Scoping; Nested Loops; Parameterized Methods Yang (Richard) Yang Computer Science Department Yale University.
Week 5 - Monday.  What did we talk about last time?  Linked list implementations  Stacks  Queues.
02-RangesInPictures1 Barb Ericson Georgia Institute of Technology Oct 2010 Working with ranges in pictures.
CS1315: Introduction to Media Computation Referencing pixels directly by index number.
ManipulatingPictures-part11 Manipulating Pictures, Arrays, and Loops part 1 Barb Ericson Georgia Institute of Technology Nov 2009.
HTML Lesson 3 Hyper Text Markup Language. Assignment Part 2  Set the file name as “FirstName2.htm”  Set the title as “FirstName LastName First Web Site”
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.
NestedLoops-Mod7-part31 Two-Dimensional Arrays and Nested Loops – part 3 Bugs in the garden Originally by Barb Ericson Georgia Institute of Technology.
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.
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.
CSC508 Convolution Operators. CSC508 Convolution Arguably the most fundamental operation of computer vision It’s a neighborhood operator –Similar to the.
Georgia Institute of Technology Introduction to Media Computation Barb Ericson Georgia Institute of Technology May 2006.
CPSC1301 Computer Science 1 Chapter 4 Manipulating Pictures, Arrays, and Loops part 5.
Lookup Function (Think of a Book Index).  Need to fill based on what is in the these fields Array table.
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.
Conditionals-part21 Conditionals – part 2 Barb Ericson Georgia Institute of Technology Nov 2009.
TOPIC 10 THE IF STATEMENT 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson,
1 Arrays of Arrays An array can represent a collection of any type of object - including other arrays! The world is filled with examples Monthly magazine:
NestedLoops-part21 Nested Loops – part 2 Barb Ericson Georgia Institute of Technology Nov 2009.
Copyright © Curt Hill Further Picture Manipulation Considering position.
Programming for Art: Arrays – 2D ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 16 Fall 2010.
1 BUILDING JAVA PROGRAMS CHAPTER 2 PRIMITIVE DATA AND DEFINITE LOOPS.
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.
CS 115 Lecture 17 2-D Lists Taken from notes by Dr. Neil Moore.
NestedLoops-Mod7-part61 Two-Dimensional Arrays and Nested Loops – part 6 Enlarge Barb Ericson Georgia Institute of Technology August 2005.
Web Design. How to link the robot How to turn on the robot Sec Getting Started What is python Programming in python How to move the robot How to.
Barbara Ericson Georgia Tech Sept 2005
Topic 9 Modifying Pixels in a Matrix: Copying, Cropping
Barb Ericson Georgia Institute of Technology Dec 2009
CS150 Introduction to Computer Science 1
Workshop for Programming And Systems Management Teachers
Working with ranges in pictures
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
Gray Scale picture def pixBW(pixel): # given a pixel, change to BW
CSc 110, Spring 2017 Lecture 4: Nested Loops and Loop Figures
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
CS150 Introduction to Computer Science 1
Georgia Institute of Technology
Processing Sound Ranges part 2
CSC1401 Viewing a picture as a 2D image - 2
Two-Dimensional Arrays and Nested Loops – part 6
Building Java Programs
Nested Loops Circles inside Circles
Patrick Cozzi University of Pennsylvania CIS Spring 2011
Nested Loops Circles inside Circles
CSC1401 Manipulating Pictures 2
Presentation transcript:

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 misleading: The pixels are in a 2-dimensional array Getting the pixels has been placing them into a 1-dimensional list

What is a two-dimensional array? The pixels in a picture are really stored in a two-dimensional array Each pixel has a x value (horizontal location) Each pixel has a y value (vertical location) pictureObj.getPixel(x,y) returns the pixel at that location x y

Example Two-Dimensional Arrays Maps That street is in D-5 Battleship Try I-5 Hit or miss Chairs at a theater or game Row C seat 20

Nested Loop How would you get all the pixels in a picture using their x and y values First row: x=0 and y=0, x=1 and y=0, x=2 and y=0, … Second row: x=0 and y=1, x=1 and y=1, x=2 and y=1, … Third row: x=0 and y=2, x=1 and y=2, x=2 and y=2, … We need to have one loop inside another The outer loop counts y from 0 to height - 1 The inner loop counts x from 0 to width – 1 We could also nest the loops the other way around

Recall Alice

Nested Loop Template // loop through the rows for (int y = 0; y < this.getHeight(); y++) { // loop through the columns for (int x = 0; x < this.getWidth(); x++) { // get the current pixel pixelObj = this.getPixel(x,y); // do something to the color // set the new color pixelObj.setColor(colorObj); }

Mirroring What if we want to pretend to place a mirror in the middle of the picture We would see the left side of the picture mirrored on the right side

Mirroring If we just think of a number at each x and y location instead of a color The mirroring would look like this: Can you find the algorithm to do this?

What is the Mirror for this? Try the solve the problem for small samples If you can’t solve it on a small sample You can’t write a program to solve it

Mirror Algorithm Loop through all the rows (y starts at 0, increments by 1, and is less than the picture height) Loop with x starting at 0 and x less than the midpoint (mirror point) value Get the left pixel at x and y Get the right pixel at width – 1 - x Set the color for the right pixel to be the color of the left pixel

Mirror Algorithm to Code We are going to need the midpoint int midpoint = this.getWidth() / 2; Loop through the rows (y values) for (int y = 0; y < this.getHeight(); y++) { Loop through x values (starting at 1) for (int x = 0; x < midpoint; x++) { Set right pixel color to left pixel color Pixel leftPixel = this.getPixel(x, y); Pixel rightPixel = this.getPixel(this.getWidth() x, y); rightPixel.setColor(leftPixel.getColor());

Mirror Method public void mirrorVertical() { int mirrorPoint = this.getWidth() / 2; Pixel leftPixel = null; Pixel rightPixel = null; // loop through the rows for (int y = 0; y < this.getHeight(); y++) { // loop from 0 to just before the mirror point for (int x = 0; x < mirrorPoint; x++) {

Mirror Method - Continued leftPixel = this.getPixel(x, y); rightPixel = this.getPixel(this.getWidth() – 1 – x, y); rightPixel.setColor(leftPixel.getColor()); }

Mirroring in the other direction What about mirroring around a mirror held horizontally in the vertical center of the picture? Like a reflection in a lake?

Mirror Horizontal Exercise Write the method to mirror the top half of the picture to the bottom half. This is a motorcycle redMotorcycle.jpg How about mirroring bottom to top?

Summary 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++) {

Assignment Review Media Computation Chapter 5, Section 1