代写图像处理器,对png格式的图像进行处理。
Getting Started
Instructions for working on a lab machine (B230, other lab, or remote
connection):
- Open a terminal
- Copy the starter code from the public folder.
Paste the following lines of code one after the other in the terminal i.e.
paste the first line, press enter and then the second line and so on:
cd ~
mkdir psa4
cd psa4
cp -r ../../public/psa4/* . THIS COMMAND WILL REPLACE YOUR FILES
ls
(Do you recall what each of the above commands mean. If you are not able to,
review PSA1, where each of the commands is explained.) - Verify that two folders ‘Part1’ and ‘Part2’ are shown as the result of the
last command.
Following these procedures, your file will be named correctly and be located
in the correct place. For every assignment you need to follow correct naming
assignments in the correct locations to get credit for your work. - Proceed to start your programming assignment.
Instructions for working on your Local Machine (Your Laptop/Computer):
- Create a psa4 folder on your machine.
- Download ‘Part1’ and ‘Part2’ nside the psa4 folder.
The following files should be in Part1 folder: ‘8Arocks.png’, ‘Picture.java’,
‘TriEffect.java’, ‘blending.png’, ‘yellowFlowers.jpg’,
‘ColorPictureTester.class’, ‘TestPictures.java’, ‘bear.jpg’, ‘yellow.png’ The
following files should be Part2 folder: ‘Picture.java’,
‘ImageFilterTester.class’, ‘bear.jpg’, ‘Yellow.png’
Part 1 (Collaboration encouraged)
Commenting your code and code style
This week we will give 1 point for proper commenting and style in your code.
Make sure you have proper indentation, that you have your names and
logins/PIDs at the top of all files/methods, and that you use good variable
names (e.g. turtle1 rather than x for a Turtle variable). Also make sure each
method you write has a comment at the top that includes: what the method takes
as input, what it does, and what it returns (if anything). See the style guide
linked here.
Part 1.1: Color Scaling
Complete the method scaleColor in the Picture class.
The scale color method takes three parameters of type double (rScale, gScale
and bScale). These parameters specify how much to scale the red channel, green
channel, and blue channel (in that order) of all Pixels in the calling object
Picture. Fo r example, if you pass (1.12, 1.2, 0.5) as parameters to your
method and the color values of one of the pixels of the picture is (100, 200,
50), then the red, green and blue color values should be scaled to (112, 240,
25), respectively, after your method is called. Again, the order in which the
color values are passed to the method should be red, green, and blue, in that
order.
Some important notes:
- The method should scale the color values of ALL the pixels in the calling object Picture (this).
- Keep in mind that pixel value should be integers, so you may need to typecast values back to int after you scale them.
- Pixel values cannot go below 0, or above 255. We have provided a method in the Picture class named putInColorRange(int value) that will take an int and if that int is between 0 and 255 (inclusive) it will simply return the same value. However, if the integer is below 0 it will return 0. If it is above 255 it will return 255. You will need to call this method on all scaled color values to ensure that the new color value is in the proper range. E.g., if the variable scaled stores a scaled color value, then scaled = this.putInColorRange(scaled); will ensure that the value of scaled is within the range [0,255].
- This method must not be overly complicated. What we mean by this is that it should do only the work it needs to do, and not a lot of extra unneeded computation. Examples of overly complicated code are: extra loops through the Pixels that don’t need to be there, extra computations that are not used, etc.
Using variables does NOT necessarily make your code overly complicated. It is
NOT considered overly complicated to store intermediate results and values in
variables. That is perfectly fine to do.
Test your scaleColor method by exploring Pictures in TestPicutres.java
(nothing to submit for this step)
First, test your scaleColor method by adding the following code to the main
method in TestPicture.java.
- Make a new Picture object with the name of a Picture file. You can do this by either using the FileChooser.pickAFile() method to manually select a file, or by hard-coding the name of a file in your code.
- Make a new Picture object which is a copy of the one you just made. Use this code statement to do so (assuming your original Picture variable is named original):
Picture copy = new Picture(original)
; - Call scaleColor on the copy of the picture.
- Call the method explore() (see the book page 89) on both the original and (modified) copy Picture objects.
Run this program, and manually mouse around to explore the original and
changed picture to make sure your method works correctly (that is, a specific
pixel in the original picture has been scaled by the right amounts in its red,
green, and blue components for the copied picture). - Say you passed in (1.12, 1.2, 0.5) as your parameters. Examine the values of the two pictures at, for example (100, 100), for both the pictures. If the value you examine in the unmodified picture is (150, 200, 50) and (112, 240, 25) for the modified picture, then you know something is wrong with your code. Hmm.. only the red value seems to be incorrect. Perhaps you can go back to the code and see if you accidentally set the wrong value to your red component.
Test your scaleColor method using our Tester
Finally, run the provided program ColorPictureTester. You will see the output
from a number of tests printed to the screen. If any of those tests fail,
debug your code and run the tester again until you are sure that everything is
working.
Note: You don’t need to compile our tester. Don’t remove
ColorPictureTester.class If you accidentally deleted this file, use the
following command to copy from public folder:
cp ../../public/psa4/ColorPictureTester.class .
The tester executable is already compiled. Just run the tester using the
following command:
javac Picture.java
java ColorPictureTester
You should NOT try anything like decompiling the .class file. If you don’t
know about decompiling, you can skip this note.
Part 1.1 grading
For part 1.1 you will receive:
- 4.0 points for passing the provided tester
- You may lose up to 1 point for code that is correct, but is overly complicated. This means, uses an overly complicated approach to solve the problem, even if it works correctly. This point does NOT refer to style, which is accounted for separately. An overly complicated approach might be looping through the Pixels twice, when once will do, calculating a bunch of values that are not needed, etc.
Prepare Part 1.1 for submission
- Create a new Google Doc by going to the File menu at the top of this
document and selecting: File -> New -> Document. - Copy ONLY the method scaleColor in Picture.java to the Google Doc. We do
NOT need to see the code you used to test your method in TestPictures.java - Next, run the provided ColorPictureTester program. Copy the results of Part
1.1 ONLY (either by copying the text or taking a screenshot of the printed
lines in the terminal) and paste these results to the Google Doc. - Remember to change the font of every piece of code you have pasted in to
Courier New and reduce the margins by going to File -> Page Setup… so that
your code and comments look properly formatted and each line (of no more than
80 characters) fits on one line. Ensure that your code looks well-formatted. - Don’t export yet! Make sure you complete Part 1.2 before submitting.
Part 1.2 - Tri-Effect
Complete the method complement in the Picture class.
This method takes two int parameters, which are the first (inclusive) and last
(exclusive) index of the region (part) of the 1D pixel array (i.e. the array
returned by this.getPixels()) to be modified. For example, if the value of
first is 50 and the value of last is 55, the method would modify the Pixels in
index locations 50, 51, 52, 53, and 54 only.
This method should use a loop to invert the color attribute value of each
pixel between the provided indices. For example, if a picture’s RGB is
100,120, and 200, the inverted RGB of that pixel would be 155 (255-100), 135
(255-120) and 55 (255-200)
Recommended: test your complement method at this point (see below)
Complete the method grayscale in the Picture class
This method converts a region of a Picture (as defined above in the complement
method) to convert each Pixel’s color value to grayscale for all the Pixels
within the range between the provided indices (including first, but not
including last).
This method should use the “overly simple” formula for grayscale, which is
just a flat average of the three color values, as defined at the top of page
123 in your book. (Note: it’s fine to reference that code while you are doing
this part of the assignment, but make sure you understand what you are
writing!)
Recommended: test your complement method at this point (see below)
Complete the method: myFilter in the Picture class
Complete this method, which is similar to the the complement and grayscale
methods in that it takes (at least) two parameters: the first and last
index(both inclusive) in the pixel array to be modified. However, this method
should apply any effect of your choice to the pixels in range using a loop.
- This filter cannot be grayscale, complement , a single color filter (i.e. making the picture all one flat color, or setting two of the channels to 0 for all Pixels in the picture), or any of the filters mentioned in part 2.
- You may add additional parameters to this method.
- Have fun with this filter!
Test your three filters exploring Pictures in TestPicutre.java (not
graded, but ESSENTIAL FOR DEBUGGING)
Create a new class (named anything you like) with a main method, and using a
technique similar to the technique you used to test your colorScale method in
Part 1.1 (i.e., make a Picture, make a copy of the Picture, modify a range of
Pixels in the copy using your filter, then explore both Pictures) verify that
your filters are working correctly.
Test your grayscale and complement filters using our testers
Finally, run the provided program ColorPictureTester. You will see the output
from a number of tests printed to the screen. If any of those tests fail,
debug your code and run the tester again until you are sure that everything is
working.
Note: You don’t need to compile our tester. Don’t remove
ColorPictureTester.class If you accidentally deleted this file, use the
following command to copy from public folder:
cp ~/../public/psa4/Part1/ColorPictureTester.class ~/psa4/Part1/.
The tester executable is already compiled. Just run the tester using the
following command:
javac Picture.java
java ColorPictureTester
You should NOT try anything like decompiling the .class file. If you don’t
know about decompiling, you can skip this note.
Complete the main method in the TriEffect.java
- This file will load a Picture of your choice (either a bookClasses image or a personal image) using FileChooser.pickAFile() or by hard-coding the name of a file.
- Display the original image.
- Call the complement method on the first 1/3 of pixels in the image. Next call the grayscale method on the middle 1/3 of pixels in the image. Then apply the myFilter method to the bottom 1/3 of the pixels in the image.
- Lastly, display your new image.
Run your method and take a screenshot as you will need it in your submission.
Grading for Part 1.2
For this part you will receive:
- 4.0 points for the provided tester on the grayscale and complement filters (2.0 points each)
- 1.0 point for correctly applying TriEffect in TriEffect.java as shown through the code and non-trivial screenshots (you cannot earn this point if you did not create your custom filter).
- You may lose up to one point for code that is overly complicated. See Part 1.1 for a discussion of what it means for code to be overly complicated.
Prepare Part 1.2 for submission
- Start a new page and copy ONLY the methods complement, grayscale and
myfilter in Picture.java to the Google Doc. - Copy the ENTIRE TriEffect.java to the Google Doc.
- Next, run your TriEffect program on a non-trivial image. Take a screenshot
of both the original image and the new image, and paste the screenshots below
your code in the Google Doc. - Next, run the provided ColorPictureTester program. Copy the test results of
Part 1.2 ONLY. (i.e. the terminal with tester results) either using a
screenshot or by copying and pasting the text, and paste these results into
the Google Doc. - Remember to change the font of every piece of code you have pasted in to
Courier New and reduce the margins by going to File -> Page Setup… so that
your code and comments look properly formatted and each line (of no more than
80 characters) fits on one line. Ensure that your code looks well-formatted.
Submit Part 1
- Export your Google Doc containing your code and your screenshot as a PDF.
Click: File -> Download as -> PDF Document (.pdf) - Submit your PDF on Gradescope under PSA4 part1 using the class code:
Tutorial on how to submit to Gradescope. - In the Assign Questions and Pages section, make sure you select all part1.1
pages for PSA4 Part 1.1 and select all part 1.2 pages for PSA4 Part 1.2.
Finally select all pages that contain your code ONLY for Comments.
Part 2: More Image Filters (INDIVIDUAL)
Note: You cannot get ANY help with this section, except for asking clarifying
questions. This means you cannot get help running the code (i.e. what commands
to type), or with any aspect of writing or testing the code. If you are lost
as to how to run a piece of code or how to call method for testing, or
anything else, go back to part 1. Part 2 uses exactly the skills you built in
part 1 so if you understand what you did in part 1, you should be able to do
this completely on your own here in part 2.
Please ask all clarifying questions privately on Piazza or in Prof. Alvarado’s
office hours ONLY.
Make sure you are working in the Part 2 folder within the starter code! You
will start with a brand new copy of the Picture.java file!
Complete the blueScale method in the Picture class:
public void blueScale()
—|—
This method should set the red and green channels of all the Pixels in a
calling object to 0, so that the picture appears in shades of blue.
- Example: A Pixel with an RGB value of (40, 30, 26) should be set to (0, 0, 26)
Complete the multiScale method in the Picture class
public void multiScale(double scale)
—|—
This method should cale the red, green and blue channels of each Pixel
proportionally to the input value scale. The red channel is scaled exactly by
scale. The green channel is scaled by 2 times the value of scale. The blue
channel is scaled by half the value of scale.
- Example: If a Pixel’s RGB value is (200, 80, 140), and scale is 0.4, then the Pixel’s RGB values should be set to (80, 64, 28).
- Scaled values that result in decimal values should be truncated (e.g., 40.7 becomes 40).
- This method must ensure that none of the color channels are set to anything outside the range [0,255] (even when scale is negative or very large). Scaled values below 0 should be set to 0; values above 255 should be set to 255.
Complete the rotateRGB method in the Picture class
public void rotateRGB(int start, int end)
—|—
This method should modify the colors each Pixel in range from start
(inclusive) to end (ALSO INCLUSIVE, unlike part 1) in the pixel array of the
calling object (i.e. what is returned by this.getPixels()) as follows:
- The blue channel gets the (former) value of the red channel
- The red channel gets the (former) value of the green channel
- The green channel gets the (former) value of the blue channel
- Example: if this method is called with the parameter 40 and 48, then the index locations that will be modified will be 40, 41, 42, 43, 44, 45, 46, 47, and 48. If one of those Pixels had RGB value (30, 50, 180), then after the method that same Pixel will have RGB value (50, 180, 30).
- You can assume that this method will not be called with values for start and end that are outside of the range of the pixel array for the calling object Picture.
Complete the averageRGB method in the Picture class
public void averageRed(int start, int end)
—|—
This method should modify the colors each Pixel in range from start
(inclusive) to end (ALSO INCLUSIVE) so that each Pixel’s red channel is the
average value of the red channel for all of the pixels in that range. The blue
and the green channels remain unchanged.
- Example: if this method is called with the parameter 40 and 43, then the index locations that will be modified will be 40, 41, 42, 43. If the RGB values of those Pixels are (40, 34, 200), (50, 30, 220), (52, 34, 218) and (55, 44, 220), then values after the transformation will be (49, 34, 200), (49, 30, 220), (49, 34, 218) and (49, 44, 220) because the average of the red channel values ((40+50+52+55)/4) is 49.
- Averages which result in floating point values should be truncated (i.e. the decimal part should be dropped).
- You can assume that this method will not be called with values for start and end that are outside of the range of the pixel array for the calling object Picture.
- If start is greater than end, the method should modify no Pixels.
- Hint: You will need to use two loops inside this method.
You can run the ImageFilterTester program (in ImageFilterTester.class) to test
your code. Simply run the program using the ‘java’ command. It will run a
number of tests on this method and report the results.
javac Picture.java
java ImageFilterTester
Note: You don’t need to compile our tester. Don’t remove
ImageFilterTester.class If you accidentally deleted this file, use the
following command to copy from public folder:
cp ~/../public/psa4/Part2/ImageFilterTester.class ~/psa4/Part2/.
As mentioned before, trying to decompile a .class file provided is against the
academic integrity policy of the course. You will all fail tests related to
the methods of Part2 that you have not implemented yet. Don’t worry about it
for now! Those tests are failing because you haven’t yet completed the methods
for the next part of this task. If you see these messages even after you
finish the those methods, look into your code again and fix the errors.
These are the SAME tests that will be run when you submit your code, however,
note that they are only a subset of the total tests we will use to grade your
code, so just because your code passes all these tests does NOT mean you will
definitely get full credit.
Submit Part 2
- Uncomment (remove the // from) the first line of Picture.java.
- Save the file Picture.java. DO NOT COMPILE THE FILE.
If you need to make changes to your file and run it again, add the comment
back ( put // in front of the first line) so Java knows to ignore this line.
Every time you resubmit, uncomment it again and save before you upload onto
Gradescope. - Submit this file to Gradescope under PSA4 Part2
- If the code runs but one or more tests fail, check your code. You WILL lose
credit if you don’t fix the issue. Make sure your spacing is exactly as
described and shown above, and that you don’t have any extra spaces or
newlines anywhere. Check carefully, make changes, and resubmit until your code
passes all tests.
Star point
The Star point option in this assignment will be to write a filter that will
enhance the global contrast of an image. If you are unclear about what global
contrast enhancement entails, please do a little research to clarify what this
entails. An example of a set of contrast enhanced images are as follows:
The amount by which you want to increase the contrast by is up to you. When
grading, we will check to see if there is a visible increase in contrast after
using your filter. If we do not see any obvious changes in such a way, no star
point will be given. So be sure that your contrast is truly enhanced.
Warning: This is NOT an easy Star point assignment and you should focus on the
main part of the PSA before attempting this. For this Star point, you should
create a NEW filter method in Picture.java that you can call in a new file
called StarPointPSA4.java. Please name your new star point method
starPointFilter and create suitable Picture.java and StarPointPSA4.java
headers. Don’t forget your header information in that file which includes all
the usual information. Refer to previous PSA starter code for class header
formats/comments.
Submit star point
You will put everything you worked on into a pdf file. Include
- The code of all the star point .java files
- Screenshots of the results of the filter on 3 images that best represent the working of this filter.
- The key idea used while designing this filter.
- References.
and submit through Gradescope: PSA4 Star Point.