cs026_7_Part2

cs026_7_Part2 - Topic 6 Modifying Pixels in a Matrix Part 2...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Topic 6 Modifying Pixels in a Matrix Part 2 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson, and instructor materials prepared by B. Ericson.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Example of Useful Mirroring • The Temple of Hephaistos in Athens, Greece has a damaged pediment. Can we “fix” the temple by mirroring the good part onto the broken part?
Background image of page 2
3 Example of Useful Mirroring • Why can’t we just mirror the left half onto the right? • What pixels do we want to mirror? • How can we accomplish this? • Choose a point to mirror around vertically • Start with the row of pixels at the top of the pediment • End with the row of pixels at the bottom of the pediment
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 Example of Useful Mirroring
Background image of page 4
5 Example of Useful Mirroring • Before and after: how can you tell that the picture has been digitally manipulated?
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 Copying and Transforming Pictures • We can copy pictures by getting pixels from a source image and setting pixels in a target image • Actually, we don’t copy the pixels, but rather simply make the pixels in the target image the same color as the ones in the source image • We can not only copy an image, but we can also transform it in the process • Cropping it, scaling it, rotating it, and so on
Background image of page 6
7 Copying Pictures • We need to keep track of • the source picture’s x and y • the target picture’s x and y • We can use a blank picture as the target picture • Several blank pictures are already available: • 640x480.jpg • 7inX95in.jpg (1,1) (0,1) (1,2) (0,2) (1,0) (0,0) (1,2) (0,2) (1,1) (0,1) (1,0) (0,0)
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
8 Copy Picture Method • We will write a method to copy a picture (the source picture) to the current picture (the target picture) • The picture to copy will be passed as a parameter • The method header will be public void copyPicture (Picture sourcePicture) • Copy algorithm : • 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
Background image of page 8
9 Copy Picture Algorithm to Code • Loop through the source picture pixels: // loop through the columns for (int sourceX = 0, targetX = 0; sourceX < sourcePicture.getWidth(); sourceX++, targetX++) { // loop through the rows for (int sourceY = 0, targetY = 0; sourceY < sourcePicture.getHeight(); sourceY++, targetY++) { (to be continued)
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/20/2009 for the course COMP SCI 026 taught by Professor Unknown during the Spring '07 term at UWO.

Page1 / 31

cs026_7_Part2 - Topic 6 Modifying Pixels in a Matrix Part 2...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online