Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java, new to Java To implement four basic image processing operations on a 2-dimensional array that represents a 2 dimensional digital image The standard libraries

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Java, new to Java

To implement four basic image processing operations on a 2-dimensional array that represents a 2 dimensional digital image The standard libraries of Java has a package called jaxaat that contains a class called Color (https://docs.oracle.com/javase 7/docs/api/java/awt/Color.html) which we will use to represent pixel colors to be stored in the 2-dimensional array. This class provides3 methods, getRed), getGreen), and getBlue) for getting the values of the red, green, and blue component of each pixel. Please read the supplied InverseOperation.java class to learn how to define a 2-dimensional array storing the pixel colors and how to use the 3 above methods to get the individual R, G, B color components of each pixel 3. Classes Provided Class Imageloader.java contains methods to read an image stored in a file with extension .jpg, or pnq, and to store it in a 2-dimensional array of objects of the class Color described above. To test your program, you can download any image in jpg or png format from the internet. We also provide a collection of jpg files for your reference and testing. The class lmageloader.contains two methods, getColorAray, and getcravscaleAray that store the pixels of an image in a 2-dimensional array of type Color][]. This is the array that you will use to manipulate the input image, as explained below. Method getColotArray stores the pixels of the array in their original colors, while get@rexscaleArray stores the pixels in a grey scale format. You will not need to use these methods or any of the methods described in this section in the code that you are required to write; we provide this information for your reference on Class ImageConverter.java contains auxiliary methods needed by getColotAray and getGreclergx It also provides methods for converting the 2-dimensional representation of an image into a format suitable for storage in a jpg or ppg file Class ImageWriter.java contains a method called writelmgge tha takes as arguments an output file and an image represented as a 2-dimensional array and stores this image in the output file. Method writelnage uses the auxiliary method writeFile also defined in this class. Class ImageProcessing.java contains the main method for your program. Hence, to run your program from a terminal or command window, once you have compiled all your java classes, you will type the command See below for explanations of how to run your program from Eclipse. The program will reada configuration file containing an image file and a set of image operations (described below); the program will perform the specified operations on the image and the resulting image will then be saved in an output file. The format of the configuration file is specified later Class lmageProcessing has methods to read the image to be processed and the set of operations that are to be performed on it. This class also has methods to determine the output directory where the processed image will be stored Method processimgae will invoke the code that you will write (explained below) to perform the required operations on the input image. To keep the program simple and to maintain uniformity in the way in which the different image operations are invoked, we provide you with a Java interface class called ImageQperation that defines a method called doOperation, The doOperation method takes as an argument a 2-dimensional array of type Colorl)l storing an image, as explained above, performs a specific operation, and returns a new 2-dimensional array of type Colorlill containing the processed image. The signature of this method is public Color[][] doOperation(Color[][] nggeAraw This means that all your Java classes will implement the ImageOperation Interface; that is, they will all implement the doQperation method. To clarify this look at the sample inverse image operation described in the next section 3.1 Inverse Image Operation The first image operation that we will consider is the inverse operation that inverts the colors of an image, so black pixels become white, while pixels become black, and other pixels change color to their inverse. If a pixel p has color(RG,B) the inverse color is defined as color(255-R,255-G,255-B). To perform this operation the 2-dimensional array storing the colors of the pixels is scanned and for every entry the color of the corresponding pixel is inverted. The java code to perform this operation is in the provided InverseOperation.java class, which for convenience we show below import public class oveseaReration implements TrageOReratieA public Celor doReration(Color rageAaxf iot ovRtCawoos-jnageeraLo].length; // 2-dimensional array to store the processed image // Scan the array and invert each color result [j -new Colorfred, green, blue); return result Note the first line import iavaatncolax That allows the program to use the methods from class Color that, as mentioned above, is part of the Java standard libraries. Note also the third and fourth lines that show how to obtain the width and height of the image; this information is needed to determine the size of the 2-dimensional array result that will be used to store the modified image Color][] result-new Color [ouEBsl ourotcoJwoosl An example input and output images for this operation is provided below 4. Image Processing Operations to Implement For this assignment, you will implement four different operations: contour detection, threshold filtering, adjusting the brightness of pixels based on their distance to the upper left corner, and increasing the size of the image. As mentioned above, each one of your java classes must implement the lmageQperation class. Hence, the headers of your classes must be as follow:s public class CaRtouFAReration implements public class public class public class MaRLEKARevation implements naseoRexatien implements TuageopexatiRa i implements Tmageopexatien Operation 1: Contour. Contour Detection To perform contour detection, we wll need to examine the "color distance" between a pixel and its neighbouring pixels. Note that depending on the position of a pixel in an image, it might have 3, 5, or 8 neighbouring pixels. For example, the red pixel in Figure 1 (page 1) has 3 neighbours: green, white, and a black pixel. The green pixel has 5 neighbours: red, blue, white, and 2 black. The white pixel has 8 neighbours The "color distance" between two pixels is defined as the square root of the sum of the squares of the differences between the R, G, and B components of the pixels. For pixel p, let p.red, p.green, and p.blue denote the red, green, and blue components of its color. Then, for pixels p1 and p2, Color distance(p1,p2)- pl.red-p2.red)2 + (p1. green - p2.green) + (p1.blue -p2.blue)2 (Note that this is the same definition for Euclidean distance between 2 points in the 3-dimensional space.) To perform contour detection for an image you will consider each entry of the 2-dimensional array storing the colors of the pixels of the image, and if for some pixel p the color distance between p and any of its neighbours is more than 65 you will change the color of the pixel to black (i.e. Color(0,0,0)); otherwise you will change the color of the pixel to white (i.e. Color(255,255,255) Note that the above threshold value 65 is arbitrary, but this is the value that we will use to test your implementation of this operation. Look at class InverseOperation.java to get an idea of what this class should look like. You must implement this operation in a Java class called ContourRertieo An example input and output images for this operation is given below. 20 Hint. Use Java class Math to compute the square root of a value. Documentation for all java classes in the standard library is available online. In Google type "java math class". This will take you to the Oracle documentation page that explains all the methods from the java class Math When considering a pixel p and computing the color distance to its neighbours, you need to verify that the neighbours exist. For example, let p be a pixel at position (xx). Its neighbours are at positions (x-1y 1), (x-1,y), (x-1,y+1), (x,y-1), (x,y+1), (x+1,y-1), (x+1,y), and (x+1,y+1). Before trying to compute the color distance between p and, say, neighbour (x-1y-1) you must check that x> 0 and y> 0 as otherwise your Java program will crash with an ArrevlodexQutfBouods exception because no array has an entry with indices [-1]I-1] Operation 2: Thresholding. Threshold Filtering A threshold filter displays each pixel of an image in only one of two colors, black or white. To perform this operation, you will consider each pixel of the image and if the "brightness score" of a pixel is greater than 100, change the color of the pixel to white, otherwise change its color to black. The "brightness score" of a pixel p is defined as Brightness score(p)-0.21*p.red+0.71*p.green+0.07'p.blue The new image will have pixels in only one of the two colors black or white. You must implement this operation in a Java class called ThreshldingQperatien. An example input and output images for this operation is provided below. Operation 3: Adjustment. Adjusting the Brightness Based on Distance to Upper-Left Corner of Image This operation changes the brightness of each pixel p depending its Euclidean distance from the upper left corner of the image. If pixel p is in position (), then its distance to the upper left corner of the image is D Vx2 + y2. The maximum distance from any pixel to the upper left corner of the image is M -width? + height?, where width is the width of the image and height is its height. Then, the color of pixel p must be modified as follows: eredp.ced* gdiustBrightoess eareen-egreen * adiustBxightoess An example input and output images for this operation is provided below. You must implement this operation in a Java class called AdiustmentOperation, Operation 4: Magnify. Increasing the Size of an Image This operation changes the size of the image to twice its width and twice its height. To perform this operation, you will create a 2-dimensional array that has twice as many rows and twice as many columns as the array storing the image. Then you will copy each pixel of the original image into 4 positions of the enlarged array (you need to think which positions of the array you need to use). You must implement this operation in a Java class called Magnifvoperation An example input and output images for this operation is provided below. 5. Configuration File To run the program, we need to specify a configuration file. The configuration has the following format simage-type> . where image-type> can be Color or Grayscale (with first letter in uppercase, as shown). If is Color the input image will be stored as a color image, otherwise it will be stored as a grey scale image. is the name of the image file that will be processed can be any of the following: Contour, Inverse, Thresholding, Adjustment, Magnify (with first letter in uppercase). These are the image operations to be performed on the input image. The operations are applied to the image in the order specified, i.e. first is applied, then on the resulting image is applied, then on the resulting image the next operation is applied, and so on. Observe that the order in which the operations are listed will change the final resulting image. Example 1 Color C:/users/mary/testl.jpg 3 Thresholding Adjustment Contour

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning ASP.NET 4.5 Databases

Authors: Sandeep Chanda, Damien Foggon

3rd Edition

1430243805, 978-1430243809

More Books

Students also viewed these Databases questions