csc1401 manipulating pictures n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
CSC1401 Manipulating Pictures PowerPoint Presentation
Download Presentation
CSC1401 Manipulating Pictures

Loading in 2 Seconds...

play fullscreen
1 / 22

CSC1401 Manipulating Pictures - PowerPoint PPT Presentation


  • 473 Views
  • Uploaded on

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 lines, shapes and text, as well as inserting a picture into another picture. What would be nice to do. Changing colors on the pictures

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'CSC1401 Manipulating Pictures' - albert


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
what we have done to date
What we have done to date
  • We have modified pictures by writing on top of them
    • Using Turtles and using Graphics
    • Drawing lines, shapes and text, as well as inserting a picture into another picture
what would be nice to do
What would be nice to do
  • Changing colors on the pictures
    • Red-eye reduction
    • Blending pictures
    • Doing other fancy Adobe Photoshop-like transformations
  • But this would be almost impossible to do by simply drawing on top of the existing picture
the goal
The Goal
  • Develop an easier approach to modifying our pictures by changing the pictures themselves rather than writing on top of them
digital pictures
Digital Pictures
  • Represented by pixels
    • With a red, green, and blue value stored for each pixel
  • Stored in .jpg (JPEG) files
    • International standard
    • With lossy compression
      • Lossy means not all data is stored
        • But what is lost isn’t that important
      • Compression means made smaller
  • Other formats for storing digital pictures are GIF and BMP
manipulating a picture
Manipulating a Picture
  • To manipulate a picture we need to manipulate the pixels that make up the picture
    • Change the red, green, or blue values at the pixel
  • Pixel is a class created at Georgia Tech
    • Each pixel object has a red, green, and blue value
pictures have lots of pixels
Pictures have lots of Pixels
  • How can we refer to each pixel?
    • pixel1, pixel2, pixel3, pixel4, pixel5, …
  • Do we really want to name each one?
    • On a 640 x 480 picture, there are 640 x 480 = 307,200 pixels
how do we change a pixel
How do we change a Pixel?

Pixel first;

first = stevepicture.getPixel(10,120);

// 10 refers to the row and 120 to the columnfirst.setColor(Color.black);

/* The book writes the code as:

stevepicture.getPixel(10,100).setColor(Color.black);

*/

Note that if you have already shown the picture, by invoking:

stevepicture.show();

You can cause the picture to be updated by:

stevepicture.repaint();

pictures have lots of pixels1
Pictures have lots of Pixels
  • How do we deal with lots of data of the same type?
    • Use an array
what is an array
What is an Array?

0

1

2

3

4

5

  • Storage for a sequence of items
    • Of the same type
  • You can access items by using an index
  • The index starts at 0
    • The first item is at index 0
    • The last item is at index (length – 1)
  • Arrays know their length (have a public length field)
    • arrayObj.length

3

7

9

2

1

5

0

1

2

3

8

3

2

6

but how does an array help us
But how does an array help us?
  • If we wish to change lots of pictures, we can use a loop!
recall from alice
Recall from Alice

In this example, each time through the loop, the bunny hopped

Note that the index variable changes from 0 to 1 to 2 to … each time through the loop. And we can take advantage of that when working with arrays!

in java
In Java
  • Use a loop to access an array of pixels
  • The first time through the loop we access pixelArray[0]
  • The second time through the loop we access pixelArray[1]
what data does a picture object have
What Data does a Picture Object Have?
  • A picture object has an array of pixel objects
    • That it read from the .JPG file
  • It knows the picture width

pictureObj.getWidth()

  • It knows the picture height

pictureObj.getHeight()

  • It knows how to return an array of pixels

Pixel[] pixelArray = pictureObj.getPixels()

pixel objects
Pixel Objects
  • Each pixel has a red, green, and blue value
    • getRed(), getGreen(), getBlue()
    • setRed(v), setGreen(v), setBlue(v)
  • Each pixel knows the location it was in the picture object
    • getX(), getY()
  • You can also get and set the color at the pixel
    • getColor(), setColor(color)
turning all of the pixels in our picture to red using a loop
Turning all of the pixels in our picture to red – using a loop
  • Notes:
  • We have created a counter that starts at 0, and goes up to the number of pixels in the picture
  • Each pixel has its color set to red!
  • How would this code have looked had it been written as a method inside of the Picture class?
a note on color
A note on Color
  • You can either set the red, green and blue amounts individually, or all together using mypixel.setColor(someColor)
  • You can create a color object by giving the red, green, and blue values for it

Color colorObj = new Color(255,10,125);

predefined colors
Predefined Colors
  • The Color class has defined class constants for many colors
    • Color.red, Color.green, Color.blue, Color.black, Color.white, Color.yellow, Color.gray, Color.orange, Color.pink, Color.cyan, Color.magenta
    • Or you can use all uppercase names
      • Color.RED, Color.BLUE, Color.BLACK, …
getting and setting pixel colors
Getting and Setting Pixel Colors
  • To get a pixel’s color as a color object

Color color1 = pixelObj.getColor();

int red = color1.getRed();

int green = color1.getGreen();

int blue = color1.getBlue();

  • To set a pixel’s color using a new color object

red = 20;

green = 30;

blue = 100;

Color color2 = new Color(red,green,blue);

pixelObj.setColor(color2);

changing pixel colors
Changing Pixel Colors
  • There are two ways to change the color of a pixel in a picture
    • Set the red, green, and blue values individually
      • pixelObj.setRed(value),
      • pixelObj.setGreen(value),
      • pixelObj.setBlue(value),
    • Or set the color
      • pixelObj.setColor(colorObj)
  • But, you won’t see any change in the picture
    • Until you ask it to repaint: pictureObj.repaint();
    • Or you invoke the show method
summary
Summary
  • Pictures have pixels
    • You can change the picture by changing the color of the pixels
  • Arrays let you store and retrieve values of the same type using an index
  • You can ask a picture for it’s width, height, and an array of pixels
  • You can get and set the color of a pixel
assignment
Assignment
  • Read Media Computation Chapter 4 – we’ll be covering while loops and for-each loops next week