2D Arrays in Java. Interfaces  Separating What from How  Phones: Dial  Cars Gas, Break, Steer.

Slides:



Advertisements
Similar presentations
Image Processing … computing with and about data, … where "data" includes the values and relative locations of the colors that make up an image.
Advertisements

Graphics You draw on a Graphics object The Graphics object cannot directly be created by your code, instead one is generated when the method paintComponent.
TOPIC 5 INTRODUCTION TO PICTURES 1 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B.
The Binary Numbering Systems
Point Processing Image Arithmetic. Arithmetic Image Operations (blending) 2  Two source images can be added, multiplied, one subtracted from the other.
Digital Images in Java The structure of code and concept
CS 61C L02 Number Representation (1)Harvey / Wawrzynek Fall 2003 © UCB 8/27/2003  Brian Harvey ( John Wawrzynek  (Warznek) (
1 Integral Data Types in C. 2 First lecture response sent out Lots of good questions Some questions will be punted to reading when appropriate 3 statements.
CS 61C L02 Number Representation (1) Garcia, Spring 2004 © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c CS61C.
24/06/2015CSE1303 Part B lecture notes 1 Words, bits and pieces Lecture B05 Lecture notes section B05.
Vision January 10, Today's Agenda ● Some general notes on vision ● Colorspaces ● Numbers and Java ● Feature detection ● Rigid body motion.
Computer ArchitectureFall 2008 © August 25, CS 447 – Computer Architecture Lecture 3 Computer Arithmetic (1)
First Bytes - LabVIEW. Today’s Session Introduction to LabVIEW Colors and computers Lab to create a color picker Lab to manipulate an image Visual ProgrammingImage.
Manipulating 2D arrays in Java
Professor Jennifer Rexford COS 217
CS 4731: Computer Graphics Lecture 21: Raster Graphics Part 2 Emmanuel Agu.
5. 1 JPEG “ JPEG ” is Joint Photographic Experts Group. compresses pictures which don't have sharp changes e.g. landscape pictures. May lose some of the.
PowerPoint: Tables Computer Information Technology Section 5-11 Some text and examples used with permission from: Note: We are.
Binary Arithmetic Math For Computers.
Week 4-5 Java Programming. Loops What is a loop? Loop is code that repeats itself a certain number of times There are two types of loops: For loop Used.
Mathcad Variable Names A string of characters (including numbers and some “special” characters (e.g. #, %, _, and a few more) Cannot start with a number.
CENG 311 Machine Representation/Numbers
Click to edit Master title style Click to edit Master text styles –Second level Third level –Fourth level »Fifth level 1 Today’s Topics How information.
Tools for Raster Displays CVGLab Goals of the Chapter To describe pixmaps and useful operations on them. To develop tools for copying, scaling, and rotating.
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.
ImageJ EE4H, M.Sc Computer Vision Dr. Mike Spann
IT253: Computer Organization Lecture 3: Memory and Bit Operations Tonga Institute of Higher Education.
Bits and Bytes. BITWISE OPERATORS Recall boolean logical operators in Java… boolean logical operators: &, |, ^ not: ! Show truth tables.
Computer Science 112 Fundamentals of Programming II Graphics Programming.
Using the JImageViewer classes. JImageViewer classes JImageViewer class JImageViewer class ImagePanel class ImagePanel class Image class Image class.
ManipulatingPictures-part11 Manipulating Pictures, Arrays, and Loops part 1 Barb Ericson Georgia Institute of Technology Nov 2009.
Lecture 4 Pixels, Images and Image Files 1. In this Lecture, you will learn the following concepts: Image files (in particular, the BMP file format) How.
Java is an object oriented programming language In this model of programming all entities are objects that have methods and fields Methods perform tasks.
CSC 270 – Survey of Programming Languages C Lecture 5 – Bitwise Operations and Operations Miscellany.
Lecture12. Outline Binary representation of integer numbers Operations on bits –The Bitwise AND Operator –The Bitwise Inclusive-OR Operator –The Bitwise.
Computer Organization and Assembly Language Bitwise Operators.
SIMD Image Processor Eric Liskay Andrew Northy Neraj Kumar 1.
1 ball, 2 ball, red ball, blue ball By Melissa Dalis Professor Susan Rodger Duke University June 2011.
ManipulatingPictures-Mod6-part61 Manipulating Pictures, Arrays, and Loops: Eliminating color, Inversion, grey scale and adjusting for luminance Barb Ericson.
Picture Lab. Manipulating Pictures Discussion and activities with java.awt.Color introduce students to megapixels, pixels, the RGB color model, binary.
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:
CS 5JA Introduction to Java Graphics One of the powerful things about Java is that there is.
CSE 351 Number Representation. Number Bases Any numerical value can be represented as a linear combination of powers of n, where n is an integer greater.
Copyright © Curt Hill Further Picture Manipulation Considering position.
Data Structures Arrays and Lists Part 2 More List Operations.
Recursion in Java The answer to life’s greatest mysteries are on the last slide.
1 Sections 5.1 – 5.2 Digital Image Processing Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
1 Manipulating Information (1). 2 Outline Bit-level operations Suggested reading –2.1.7~
CMSC 202 Lesson 26 Miscellaneous Topics. Warmup Decide which of the following are legal statements: int a = 7; const int b = 6; int * const p1 = & a;
CompSci From bits to bytes to ints  At some level everything is stored as either a zero or a one  A bit is a binary digit a byte is a binary.
AP CSP: Pixelation – B&W/Color Images
Bitwise Operations C includes operators that permit working with the bit-level representation of a value. You can: - shift the bits of a value to the left.
From bits to bytes to ints
Pixels, Colors and Shapes
Week 3 - Friday CS222.
Reading Netpbm Images.
Bitfields and Logic Basics
2D Arrays in Java Image Manipulation.
CS 240 – Lecture 8 Bitwise Operations, Bit Manipulation, Type Conversion, Conditional Expression.
EE/CSE 576 HW 1 Notes.
Bitwise Operations and Bitfields
CSE 8A Lecture 6 Reading for next class:
Bitwise Operations C includes operators that permit working with the bit-level representation of a value. You can: - shift the bits of a value to the left.
EE/CSE 576 HW 1 Notes.
Multidimensional Arrays
Transformations Dilations Translations Reflections Rotations.
靜夜思 床前明月光, 疑是地上霜。 舉頭望明月, 低頭思故鄉。 ~ 李白 李商隱.
ECE/CSE 576 HW 1 Notes.
Bit Manipulations CS212.
Presentation transcript:

2D Arrays in Java

Interfaces  Separating What from How  Phones: Dial  Cars Gas, Break, Steer

DigitalPicture Interface  public String getFileName(); // get the file name that the picture came from  public String getTitle(); // get the title of the picture  public void setTitle(String title); // set the title of the picture  public int getWidth(); // get the width of the picture in pixels  public int getHeight(); // get the height of the picture in pixels  public Image getImage(); // get the image from the picture  public BufferedImage getBufferedImage(); // get the buffered image  public int getBasicPixel(int x, int y); // get the pixel information as an int  public void setBasicPixel(int x, int y, int rgb); // set the pixel information  public Pixel getPixel(int x, int y); // get the pixel information as an object  public Pixel[] getPixels(); // get all pixels in row-major order  public Pixel[][] getPixels2D(); // get 2-D array of pixels in row-major order  public void load(Image image); // load the image into the picture  public boolean load(String fileName); // load the picture from a file  public void show(); // show the picture  public void explore(); // explore the picture  public boolean write(String fileName); // write out a file

Interfaces  Interfaces (usually) contain only public abstract methods Methods with a declaration (signature) But no definition (body)  The implementer is left to define the method bodies  In this way you can talk on any phone you like… You don’t need to rebuild the entire phone system every time a new one is added

Interfaces  Cannot be initiated DigitalPicture p = new DigitalPicture();  Can be a reference to an implementing class DigitalPicture p = new SimplePicture();  Java allows for abstract methods in classes Class must be declared abstract ○ public abstract class Shape ○ Cannot initiate abstract classes must use a subclass that is not abstract Method also must be declared abstract ○ public abstract void draw(); A subclass must either implement the abstract methods or itself be declared abstract

Image Manipulation Demo  Goal: Write a method that will set the red channel of all pixels to zero Write a method that will set the green channel of all pixels to zero Write a method that will set the blue channel of all pixels to zero

A Magic Trick ABCDE

Bitwise logic  1 = true, 0 = false  And 1 & 1 = 1 0 & X = 0  Or 0 | 0 = 0 1 | X = 1  Xor – exclusive or (one but not both) 1 ^ 0 = 1, 0 ^ 1 = 1 1 ^ 1 = 0, 0 ^ 0 = 0  Not ~1 = 0 ~0 = 1

Pixels = 32 bits in RGB bits in memory = 1 int Red = 23-16Green = Blue = 7 - 0Alpha = Bitwise operators in java can give us much faster and more general purpose Access to the RGBA values: Zero red = ( ) & (pixel’s int value) Zero blue = ( ) & (pixel’s int value) Zero green = ( ) & (pixel’s int value) Similarly, Full red = ( ) | (pixel’s int value) Full blue = ( ) | (pixel’s int value) Full green = ( ) | (pixel’s int value)

How do you get binary numbers?  Base 10: 123 = 1x x10 + 3x1 123 = 1x x x10 0  Base 2: 1010 = 1x8 + 0x4 + 1x2 + 0x = 1x x x x2 0 In base: = 10  Problem: We aren`t using just a few bits, we`re using 32 or 64 at a time in most cases

Hexidecimal  Programmers usually write binary values in hexidecimal for short hand. Each value = 4 bits  In Java you can write hex values by using the 0x preface: short onesThenZeros = 0xf0;//8 bits int allOnes = 0xffffffff;//32 bits long alternates = 0x ;//64 bits 0 = = = = = = = = = = 1001a = 1010b = 1011 c = 1100d = 1101e = 1110f = 1111

AP style questions  How many unsigned values can be represented with 16 bits?  How many signed values can be represented with 32 bits?  How many colors are possible with 8 bits for each of RGB?

Signed integers  The fact that integers are both positive and negative gives us one more challenge.  int test = 0x a;  System.out.println(test); 10 is printed  int test = 0xffffffff;  System.out.println(test); -1 is printed

2`s complement  Later in CS you`ll learn about how positives and negatives are stored in the computer using 2`s complement Leading bit: ○ 1  negative value is stored ○ 0  positive value is stored 1`s complement: 1100  ’s complement: ○ 1’s complement and add 1 ○ 1100   0100 (–4)  For our purposes you can just use hex for your masks and not worry too much about what integer is being stored Hex values are loaded in as they appear

Image masks  Let’s have a look at how we can use the bitwise AND operator, &, to manipulate the pixels  Other bitwise operators NOT: ~ OR: | XOR: ^  We can do a lot more than just zero out the channel now with a single method

Your Turn… (Choose 3)  Create a method to: Apply a bitwise mask (pick one of the masks below) ○ OR mask to each pixel’s int value using the | operator ○ XOR mask to each pixel’s int value using the ^ operator Negate the color of a pixel ○ This is done by taking the (value) in each channel and replacing it by (255 – value) Lighten (or Darken) the image by a given value ○ Positive values will lighten the image, negatives will darken it ○ Add the value given to each RGB value in the pixel Make a grayscale image ○ set the RGB value of each pixel to be the average RGB value ○ RGB(0,10,80)  RGB(30, 30, 30) Replace the pixel by the largest RGB value ○ Zero out the other channels for that pixel ○ RGB(72, 58, 9)  RGB(72, 0, 0); Scramble the RGB values at each pixel ○ Randomly move them so that RGB  GBR or BRG or… ○ RGB(1,2,3)  RGB(3,2,1) or RGB(2,1,3) or …

Vertical Mirror  Task:  Java…

Horizontal Mirror  Task:  Java…

Your Turn…  Flip Vertically  Flip Horizontally  Rotate 90 degrees counter clockwise ○ Row[n] becomes columns[n] This may change the dimensions of the new picture… be careful Hint: This is very similar to something you’ve already done called transposing

Transitions  Changing from one image/slide to next  Many forms are possible to try  Let’s take a look at public interface ImageBlender public class Dissolve public class TransitionMaker  Quick math: Absolute Position = row*columns + column

Your Turn…  In the final demonstration you will have to implement 2 transitions  The slides that follow show you some example transitions  You may assume the image sizes will be the same when making transitions In practice, the smaller image is padded with pixels until it is the same size as the larger image

Push Upcoming ImageOriginal Image

Uncover  You can complete EITHER cover or uncover but not both Upcoming ImageOriginal Image

Cover  You can complete EITHER cover or uncover but not both Original ImageUpcoming Image

Clock  It’s not as scary as it looks but it does take a bit of math  The center of the image is at: (Cx = Width/2, Cy = Height/2)  For the point at location (x = column, y = row) dx = x – Cx dy = y – Cy  The angle between is: Math.toDegrees(Math.atan2(dy, dx)) Range will be from -180 to 180 so you will want to shift it Math.toDegrees(Math.atan2(dy, dx)) + 180;//0 to 360  As you loop through the frames you are allowing more of the pixels from the upcoming image based on what angle they make  For example if you need 10 frames then the angle cut offs are: 360/10 = 36 36, 72, 108, …, 360  If angleTo(row, column) < cutoff Use upcoming image  Else Use original image

Squares Upcoming Image

Random Bars  Each frame will have it’s own bar filled from the upcoming image 2 seconds = 60 frames = 60 bars  Create an array {0,1,2,…,59}  Shuffle the values in the array use Math.random() swap two random indexes  Now you can loop through the array and know who’s turn it is to draw the bar Upcoming Image

Curtains (Reveal)  You can complete EITHER reveal or hide but not both Upcoming ImageOriginalImage

Curtains (Hide)  You can complete EITHER reveal or hide but not both Original ImageImageUpcoming

Fade  This slide did the Fade transition  Original RGB makes changes into the upcoming RGB at each pixel  One way to calculate the new pixel is by using a parameterized equation P’ = upcoming pixel P = original pixel Transition pixel = P’*t + P*(1 – t) ○ For each RGB channel t  [0,1], think about it like the percentage of time elapsed If the transition has 25 frames, and we are processing the 10 th, then t = 10/25 or 0.40

Upcoming Image Original Image Upcoming Image Shrink/Expand