Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.util.Scanner; import java.io.*; import bridges.connect.Bridges; import bridges.base.ColorGrid; import bridges.base.Color; /* *Public class to create an image object. This Image class hold the operations needed

import java.util.Scanner; import java.io.*; import bridges.connect.Bridges; import bridges.base.ColorGrid; import bridges.base.Color;

/* *Public class to create an image object. This Image class hold the operations needed to read, create, and display an *image in the BRIDGES. **/ public class Image { // These are the class attributes needed to complete this lab // image dimensions // MaxVal is used for reading in the ppm file. for the default constructor, you can init the value as 0 private int width, height, maxVal;

// image array and processed array definitions private int[] image_array;// array holding the pixel values of the read in image ([r,g,b,r,g,b,...etc]) private int[] processed_array;// array holding the pixel values of the grayscale image ([r,g,b,r,g,b,...etc])

// constructors //TODO: create an Image constructor that initializes all the attribute to a default value public Image() { }

// creates an image object by reading the input image //TODO: Create an Image overloaded constructor that takes in an input file string and calls the read in image function public Image(String input_file){ }

// accessors //TODO: get width accessor public int getWidth() { return 0; }

//TODO: set width mutator public void setWidth(int w) { }

//TODO: get height accessor public int getHeight() { return 0; } //TODO: set height mutator public void setHeight(int h) { }

// reads an image from the given input image file //This function is given to you as a help in understanding how the pixel data is read and initialized public void read(String file_name) { // open the file try { Scanner sc = new Scanner(new File(file_name));

// read the header (assumes PPM text images) String magic; magic = sc.next(); width = sc.nextInt(); height = sc.nextInt(); maxVal = sc.nextInt();

System.out.println("Header:" + magic + " " + width + " " + height + " " + maxVal); //make sure the image arrays are null and then initialize them if (image_array == null) image_array = new int[width*height*3];

if (processed_array == null) processed_array = new int[width*height*3];

// read the pixels int k = 0; for (int i = 0; i < height*width*3; i++) image_array[i] = sc.nextInt(); } catch (FileNotFoundException ex) { System.out.println ("Input image file not found!" + ex); ex.printStackTrace(); } }

// displays image using the BRIDGES color grid //TODO: given the colorgrid object and if you want to display a grayscale or normal image, //populate the colorgrid objects with the pixel values from the read in image. //You can set a colorgrids pixel value by doing: cg.set(i, j, new Color(r, g, b); public void setColorGrid (ColorGrid cg, Boolean processed) { }

Just need the code(java) for the TODOs, please answer correctly please. thank you.

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

Database Application Development And Design

Authors: Michael V. Mannino

1st Edition

0072463678, 978-0072463675

Students also viewed these Databases questions