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

Info icon This 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.
Image of page 1

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

View Full Document Right 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?
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
Image of page 3

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

View Full Document Right Arrow Icon
4 Example of Useful Mirroring
Image of page 4
5 Example of Useful Mirroring Before and after: how can you tell that the picture has been digitally manipulated?
Image of page 5

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

View Full Document Right 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
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)
Image of page 7

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

View Full Document Right 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
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)
Image of page 9

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern