All in the PDF, also dont need a referencing style

1 answer below »
All in the PDF, also dont need a referencing style


Changelog • 9/18: Signature of method saveImage modi�ed to include a second parameter Description The purpose of this assignment is to practice object oriented programming principles in Java combined with command line arguments, �le I/O operations, and memory management with arrays. Instructions   Validation : Make sure all method parameters are properly validated (e.g. String[] args can’t be empty, etc.)  Documentation : Comments in JavaDoc-style are required. You must comment each class, each method and each instance/class variable you declare. You must also comment any piece of code that is not obvious what it does.  Visibility : All �elds should be made private unless we explicitly say otherwise. All methods provided in the speci�cation are public.  Packages : You may not import any classes except Scanner, File, PrintWriter Mohammad Qasim Submission Submission instructions are as follows: r) Grading • Grading is based on both automated unit-testing and manual code inspection • If your code doesn’t compile, you will get zero points Testing You will start programming without a tester. The goal is to help you put more focus on writing logically correct programs instead of trying to pass certain tests only. At some point next week, a tester will also be made available. But don’t wait for it in order to start your project. You won’t have enough time to complete the project on time if you wait for the tester! Background A digital image with dimensions HxW is represented with a matrix of pixels that has H rows and W columns. In grayscale images, each pixel is an integer that takes values from 0-255 (i.e. 1 byte). A value of zero corresponds to the black color and a value of 255 corresponds to the white color. Everything in between is a tone of gray; the darker the gray the closer to 0, the lighter the gray the closer to 255. Figure 1a depicts a zoom-in on a 16x12 grayscale image. In Figure 1b you see the values of each pixel superimposed on the image. And in Figure 1c you see the 2D representation of this grayscale image. a b c Figure 1: Grayscale image represenation Images come in many diFerent formats, but to keep things simple for this project, we will use the PGM format (portable graymap format). PGM images can be stored in either a binary or a text format. We will use the text format to make the reading/writing of the images and the debugging of the code even simpler – it will be easy to visually inspect the input you use and the output you generate. Most photo viewing/editing applications support this format, but in case yours doesn’t, you can download GIMP for free (you’re not required to use a photo app, but the whole project will make more sense if you do). In the snippet below, you can see an example of an actual image stored in a PGM �le. P2 24 7 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 50 50 50 50 0 0 125 125 125 125 0 0 200 200 200 200 0 0 255 255 255 255 0 0 50 0 0 0 0 0 125 0 0 0 0 0 200 0 0 0 0 0 255 0 0 255 0 0 50 50 50 0 0 0 125 125 125 0 0 0 200 200 200 0 0 0 255 255 255 255 0 0 50 0 0 0 0 0 125 0 0 0 0 0 200 0 0 0 0 0 255 0 0 0 0 0 50 0 0 0 0 0 125 125 125 125 0 0 200 200 200 200 0 0 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 The �rst row is the code P2 that indicates the format of the �le. The second row contains the width and the height of the image in pixels (24 and 7 respectively). The third row de�nes the maximum grayscale value which is 255 in this project (minimum is 0 by default). And what follows is simply a series of width⨯height pixel values. Open your favorite plain-text editor, copy+paste the above snippet, and save the �le as image.pgm (make sure it’s in plain text format). Then, open it with your favorite photo viewing/editing application (e.g. Photoshop) to verify that it looks like the �gure on the right (you will need to zoom-in a lot because this image is very small). https://www.gimp.org/ When it comes to color images, the only diFerence is that each pixel consists of three, instead of one, values (see Figure 2 below). These three values correspond to the three primary colors: Red, Green, Blue. The theory behind it is the RGB color model but you do not need to know any details to complete this project. Figure 2: Color image representation In terms of the �le format, we will use a very similar to the previous version, called portable pixmap format (PPM). This is again a text-based format, so reading/writing of images and code debugging will remain simple. The following is an example of such a �le. On the left is the actual plain-text content of the �le that you can create/edit with any plain-text editor, and on the right is the image you will see if you open that �le with a photo viewing/editing application (you will need to zoom-in a lot because this image is extremely small). P3 3 2 255 255 0 0 0 255 0 0 0 255 255 255 0 255 255 255 0 0 0 The �rst row is the code P3 that indicates the PPM text format. The second row contains the width and the height of the image in pixels (3 and 2 respectively). The third row de�nes the maximum color value which is 255 in this project (minimum is 0 by default). And what follows is a series of width⨯height pixels – each pixel is a 3-tuple (red green blue). https://en.wikipedia.org/wiki/RGB_color_model Tasks You must implement the following classes based on the speci�cation provided below. In most part, the visibilities and the types of the variables are not provided; it’s your task to �gure out what is the proper visibility and type to use in each case. ImagingApp This is the entry point to your executable application. We want to be able to use a command line argument when we run the application. Execution in the terminal should look like this: java ImagingApp input_file output_file operation parameters input_file the name of the PGM or PPM �le that will be used as input image output_file the name of the PGM or PPM �le that will be used as output image operation a string that indicates what imaging operation should be applied on the input image before it is saved as the output image. The following are the possible values: "scale" for scaling the image "crop" for cropping the image "flip" for Lipping the image "rotate" for rotating the image "compress" for compressing the image parameters one or more command line arguments that further specify the details of the above operation. The following are the options in each case: scale is followed by one integer. If it’s positive (e.g. 3), the image is magni�ed that many times (e.g. triples in both dimensions). If it’s negative (e.g. -2), the image is mini�ed that many times (e.g. halves in both dimensions). Example: java ImagingApp file1 file2 scale 4 crop is followed by four integers y x h w where y,x is the origin of the cropped region, h is the height of the cropped region and w is the width of the cropped region. Example: java ImagingApp file1 file2 crop 13 7 8 5 flip is followed by one string. If it’s "horizontal", the image is Lipped horizontally, and if it’s "vertical", the image is Lipped vertically. Example: java ImagingApp file1 file2 flip vertical rotate is followed by one string. If it’s "clockwise", the image is rotated 90 degrees clockwise, and if it’s "counterclockwise", the image is rotated 90 degrees counterclockwise. Example: java ImagingApp file1 file2 rotate clockwise compress is followed by two strings ttt ppp . The �rst one refers to tile compression, the second one to pixel compression, and there are two possible values for each: yes / no Example: java ImagingApp file1 file2 compress yes no Fields static Image inputImage The input image that is constructed from the contents of the input_file , must be assigned to this �eld. static Image outputImage The output image that is constructed from operations scale, crop, �ip, rotate, must be assigned to this �eld. static CompressedImage compressedImage The output image that is constructed from operation compress, must be assigned to this �eld. Methods public static void main(String[] args) All the handling of the command line arguments as well as the validation of the user input, takes place in this method boolean saveImage(Image img, String filename) Saves the img into a PGM/PPM �le. Returns false if an error occurs, otherwise true. boolean saveImage(CompressedImage img, String filename) Saves the img into a PGM/PPM �le. Returns false if an error occurs, otherwise true. Pixel This class represents a single pixel in an image. Fields value It’s an array that holds the actual value of a pixel. For grayscale images, the
Answered 9 days AfterSep 22, 2022

Answer To: All in the PDF, also dont need a referencing style

Amit answered on Sep 25 2022
53 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here