Photoshop Lab – Due Tuesday, March 5 (all code) by 11:59pm.
In this lab, you will be using Java to create/modify a program that will manipulate picture files. Everything you need for this lab is in the photoshop project .zip file I have shared with you here (https://drive.google.com/drive/folders/1SopMFW8lud0loPeF6G6t09PXe0N-UQnh?usp=sharing). After you download and unzip the file, it contains a .pdf with a written set of directions provided by the AP writers as well as 2 folders – a folder of .jpg image files named “images” (feel free to add your own appropriate photos) and a folder of code named “classes”.
---------IMPORTANT FILE MANAGEMENT TIPS----------
NOTE: to avoid issues, unzip the entire package into a folder in your g:/ drive. So you should have a folder in your g:/ drive named something like "photoshop project" and inside that folder, you would have separate folders titled "classes" and "images". The code is in the "classes" folder, and the classes and images folder both need to be contained within the same outer folder (the “photoshop project” folder) for this to work. When you bring your work home and back, it may be easiest to upload the entire “photoshop project” folder to google drive. (if this is going slow, you can just upload the "classes" folder and re-download the images folder at home)
We will be doing most of our work in the “classes” folder. Open this folder and double click on the package.blueJ file to open everything in BlueJ. Please feel free to look through any code in this folder (you do not need to understand all of it – some of the classes are pretty complicated) but do not change anything yet. Most of our work will be done in the “Picture” class and the “PictureTester” class, which is the driver for this set of code. The PictureTester has several methods which test individual commands similar to those you will create, as well as a main() method which runs those tester methods.
For this project to work, your "classes" folder must be directly next to the "images" folder. You will not be able to see the photos if these are not next to each other inside the "photoshop project" folder.
If you are having trouble downloading or uploading the project, watch this short video I made: https://www.youtube.com/watch?v=BjYTyiaJQow
-------------------------------------------------------------------
Use this page as a guide for this lab. Many of my instructions will refer to the directions .pdf document (which I will call “directions”) that is included with the .zip file, and several are only written on this page.
A couple questions in the directions will ask you to write answers out by hand - you can do this in the comment section at the top of your Picture.java file. For others, you will write code in the classes folder. We will not do every exercise in the directions .pdf and I have added several of my own on this page, including a long activity 10. PLEASE READ MY DIRECTIONS CAREFULLY AND THOROUGHLY. For most code, you will write a method in Picture and a corresponding method in PictureTester
Complete the following tasks:
Activity 1 (introduction). Begin reading on page 3 (of the directions pdf) for some background information on what is going on here. You do not have to physically answer the questions on page 4 but you should think about them.
For Activity 2 (colors), start reading on page 5 and follow the directions. You do not have to write down answers to this part, but make sure you get an idea for how changing the RGB values affects the color. This stuff will be VERY important! Also, look at different shades of a color (say different shades of green) – how do they differ and how are they the same?
For Activity 3 (starting on page 6, looking at pictures), read through then answer the questions at the bottom of pg. 6 (just put your answers in a comment at the top of the Picture.java file) and play around with the coding exercises on page 7. Make sure you know how to view different pictures, and you can put some of your own pictures in the “images” folder if you like.
Activity 4 is about 2d arrays (since a picture is just a 2d array of pixels). Skim through the reading from pages 7-10, paying more attention if you do not remember 2d arrays well. Please do the coding exercises on pg. 10 in the appropriate classes. In IntArrayWorkerTester, you can select some code that is commented out, and then click on edit → uncomment in BlueJ.
Activity 5, starting on page 11, is about inheritance structures and how we will actually modify a picture. Read through the instructions (you can skip the parts on interfaces, which are not covered in this class) and complete these tasks:
• Do exercises 1-2 on page 13, and get used to playing around with those.
• Do exercises 3-6 on page 14. For these exercises (and all of the others in the next part), you will write a method in Picture AND you will write a corresponding “test” method in PictureTester which calls that method.
For instance, if you wrote the following method in Picture:
/** Method to set the blue to 0 */
public void zeroBlue()
{
Pixel[][] pixels = this.getPixels2D();
for (Pixel[] rowArray : pixels)
{
for (Pixel pixelObj : rowArray)
{
pixelObj.setBlue(0);
}
}
}
You would also write a method like this in PictureTester.java to demonstrate its use:
/** Method to test zeroBlue */
public static void testZeroBlue()
{
Picture beach = new Picture("beach.jpg"); //or another pic of your choice
beach.explore(); //shows original pic
beach.zeroBlue();
beach.explore(); //shows edited pic
}
Look at the code that already exists as you write these methods! Make sure to test each of your methods on several different pictures! Your PictureTester should have methods named testKeepOnlyBlue, testGrayscale, testNegate, and testFixUnderwater.
For fixUnderwater, there are several ways to solve this, but your picture should not be too distorted and should maintain the general idea of the picture while improving clarity. For an example of what it should look similar to, click here: https://drive.google.com/drive/folders/1lfiDkoJfjbIONC-zU9iLF3Be2t4gPtXd?usp=sharing
For activity 6, which is about reflecting pictures, read everything carefully starting on page 15, then complete exercises 1,2, 3 and 4 on pg. 16-17, as well as writing a tester method for each of them in your PictureTester class. These methods are about mirroring half of a picture onto the other half. Look at the pictures in the document to see how this should turn out. For number 4, the challenge, do this by yourself (although as always, you are allowed to ask your peers for help).
HINTS for mirrorDiagonal:
-Try small cases first on a sheet of paper with a small 2d array of ints before working with a whole picture. Look at which row/column pairs go to which row/column pairs (for example - where does the number in spot (1,2) go?).
-To avoid out of bounds errors, determine whether the width or height of the 2d array is smaller before setting up your loops. (notice that, as in their example, the whole picture will NOT be affected)
NOTE: the effect may be clearer on square images like koala.
Skip Activity 7
Activity 8 is about combining pictures. Read the directions carefully, then do only exercise 2 on page 22, creating a myCollage() method in Picture and then a testMyCollage() method in PictureTester. Feel free to use your own pictures and get creative! You have a lot of freedom in how you want your collage to look. [NOTE: you may want to save this until after exercise 10 so you have more options for ways to make your collage!]
Skip Activity 9 (if you finish early, it is kind of interesting – you can get your program to look at a picture and find objects within that picture by seeing where there are large changes in color. Many programs use something like this to identify people within images and self-driving cars will use a version of this to identify cars and street signs)
I have created here an Activity 10 (this will easily be the longest activity), which is several other interesting methods to write in Picture. For each of the following, write the method in Picture, and then a corresponding test method in PictureTester that calls the method on a Picture of your choosing:
darken() [write this method in picture] and testDarken() [write this method in PictureTester]. This method should darken your photo. How much you decide to darken it is totally up to you but it should be noticeable. Think about the difference between black and white pixels! [For an example of what this should look like, click here: https://drive.google.com/drive/folders/1lfiDkoJfjbIONC-zU9iLF3Be2t4gPtXd?usp=sharing]
brighten() and testBrighten(). This method should brighten your photo and make the colors lighter. How much you decide to lighten it is totally up to you but it should be noticeable. This should look like the opposite of the last example.
crop(int topLeftX, int topLeftY, int bottomRightX, int bottomRightY) and testCrop(). This method should basically “crop” the picture, leaving only the rectangular part of the image given by the (x,y) coordinates in the upper left and lower right corners. Everything else in the original image outside of this rectangle should be turned white. [For an example of what this should look like, click here: https://drive.google.com/drive/folders/1lfiDkoJfjbIONC-zU9iLF3Be2t4gPtXd?usp=sharing]
colorBlind() and testColorBlind(). This method should switch the red and green in an image. There are several ways to do this, but one idea is to define what makes a pixel “red” and what makes a pixel “green”, and then switch the values of green and red for those. [For an example of what this should look like, click here: https://drive.google.com/drive/folders/1lfiDkoJfjbIONC-zU9iLF3Be2t4gPtXd?usp=sharing]
jail() and testJail(). This method should put a series of vertical black bars across your picture to make if look like the picture is in jail. It is up to you how wide you want the bars to be (I recommend between 10-15 pixels.) and how much you space them out. [For an example of what this should look like, click here to see Mr. Kirby in jail: https://drive.google.com/drive/folders/1lfiDkoJfjbIONC-zU9iLF3Be2t4gPtXd?usp=sharing]
lookMirror() and testLookMirror(). This method should basically flip the entire picture as if you were looking in a mirror. The easiest way to do this is probably to have the same loop as with the other mirror methods, but rather than just copying one onto another, do a two way swap of the right and left pixels. You may need to store the individual components (red,green,blue) of one pixel as part of the switch. You can also create a Color variable to store a pixel's color. To see what this should look like, take a picture and put it in front of a mirror.
flipDown() and testFlipDown(). This method should be similar to lookMirror but rather than making left go to right and vice versa, this should make the top parts go to the bottom and the bottom parts go to the top while left and right stay the same. [For an example of what this should look like, click here: https://drive.google.com/drive/folders/1lfiDkoJfjbIONC-zU9iLF3Be2t4gPtXd?usp=sharing]
rotate180() and testRotate180(). This method should rotate your image 180 degrees (it should just be upside down). You may want to use the previous two methods you have written. To see what this looks like, open a picture, then turn your monitor upside down (or do a handstand).
Now, submit your program via google drive. Make sure that you submit your whole “photoshop project” folder which should contain your entire “images” folder AND your entire “classes” folder with all of your updated code (as well as all of the other supporting classes you did not directly edit). I will test your code by calling the methods in your PictureTester with various pictures.
EXTRA CREDIT: Did you finish early? You can write some other methods in Picture and another class in your project named PictureTesterEC.java to test these methods. You may write anything you might want to do in order to manipulate a photo. Think about things that paint or photoshop might let you do – rotate a photo 90 degrees (in either direction), change the contrast, zoom out and get a picture with half the size, blur out a portion of the picture, fill an area detected by edges with a certain color, etc. Feel free to get creative and do something you think is cool!!