cs026_7_Part2

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

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

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.

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

View Full Document
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?
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

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

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

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

View Full Document
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
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)

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

View Full Document
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
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)

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• 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.

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

• 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.

Dana University of Pennsylvania ‘17, Course Hero Intern

• 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.

Jill Tulane University ‘16, Course Hero Intern