Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Java please: public class Imaging{ /*Inverts each value in a 2D array of integers between 0 and 255. A value of 255 becomes 0,

In Java please:

public class Imaging{

/*Inverts each value in a 2D array of integers between 0 and 255. A value of 255 becomes 0, 254 becomes 1,

all the way down to 0 becomes 255.

Parameters:

image - The array of integers with values between 0 and 255 inclusive.

Returns:

A new 2D array with integers inverted.*/

public static int[][] invert(int[][] image){

}

/*Reverses all the values in each row in a 2D array of integers, simulating a horizontal flip..

Parameters:

image - The array of integers.

Returns:

A new 2D array of integers with all the rows reversed.*/

public static int[][] horizontalFlip(int[][] image){

}

/*Reverses all the values in each column in a 2D array of integers, simulating a vertical flip.

Parameters:

image - The array of integers.

Returns:

A new 2D array of integers with all columns reversed.*/

public static int[][] verticalFlip(int[][] image){

}

/*Creates an ASCII image text file with each character represents a range of integer values.

The mapping key is specified in the assignment document.

Parameters:

image - The array of integers with values between 0 and 255 inclusive.

outName - The name of the new text file that will contain the representative characters.*/

public static void makeAscii(int[][] image, String outName){

}

/*Scales a 2D array of integers by a given factor.

Parameters:

image - The 2D array of integers to scale.

scalefactor - The percentage to scale the image by. This value is expected to be greater than 0.

Returns:

A new 2D array resized by the scale.*/

public static int[][] scale(int[][] image, double scalefactor){

}

/*Rotates a 2D array of integers 90 degrees clockwise. The value in the top left corner moves to the

top right corner and all over values move with respect to their orginal position.

Parameters:

image - The array of integers.

Returns:

A new 2D array of integers with values rotated.*/

public static int[][] rotate(int[][] image){

}

/*Reads an image file and converts it to a 2D array of integers. Each value in the array is a

representation of the corresponding pixel's grayscale value.

Parameters:

filename - The name of the image file

Returns:

A 2D array of integers.

Throws:

java.lang.RuntimeException - if the input file cannot be found or read.*/

public static int[][] readGrayscaleImage(String filename){

}

/*Parameters:

args - The input necessary to execute the appropriate conversion. The array is formated in one of the following ways:

invert

: image file

: image file

verticalFlip

horizontalFlip

makeAscii

scale

scalefactor: A number: 1 maintains original size, < 1 reduces size, > 1 enlarges size.

rotate*/

public static void main(String[] args){

}

}

Image conversion java file needed and used to call certain methods:

import java.awt.Color; import java.awt.image.BufferedImage; import java.io.*; import javax.imageio.ImageIO; /** * Class ImageConversions is a collection of methods that convert jpg images * into variations. */ public class ImageConversions { /** * Handles all input instructions and relays the information to the * appropriate method. * If the input is not as specified, the program stops, with an informative message. * @param args The input necessary to execute the appropriate conversion. * The array is formated in one of the following ways: * 
    *
  • [infile outfile] invert *
      *
    • infile: image file outfile: image file
    • *
  • *
  • [infile outfile] verticalFlip
  • *
  • [infile outfile] horizontalFlip
  • *
  • [infile outfile] makeAscii
  • *
  • [infile outfile] scale [scalefactor] *
      *
    • scalefactor: A number: 1 maintains original size, < 1 reduces size, > 1 enlarges size.
    • *
  • *
  • [infile outfile] rotate
  • *
*/ public static void main(String[] args) { System.out.println("Please read through the Assignment 6 pdf file on conneX"); System.out.println("The file includes instructions on how to use the two methods provided."); } // THIS METHOD MAY BE CALLED, BUT MUST NOT BE MODIFIED! /** * Reads an image file and converts it to a 2D array * of integers. * Each value in the array is a representation * of the corresponding pixel's grayscale value. * @param filename The name of the image file * @return A 2D array of integers. * @throws RuntimeException if the input file cannot be found or read. */ public static int[][] readGrayscaleImage(String filename) { int[][] result = null; File imageFile = new File(filename); BufferedImage image = null; try { image = ImageIO.read(imageFile); } catch (IOException ioe) { System.err.println("Problems reading file named " + filename); throw new RuntimeException("Please ensure the image file is saved in the same directory as your java file."); } int height = image.getHeight(); int width = image.getWidth(); result = new int[height][width]; int rgb; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { rgb = image.getRGB(x, y); result[y][x] = rgb & 0xff; } } return result; } // THIS METHOD MAY BE CALLED, BUT MUST NOT BE MODIFIED! /** * Reads a 2D array of integers and creates * a grayscale image. Each pixel's grayscale value is * based on the corresponding value in the 2D array. * @param filename The name of the image file to create * @param array The 2D array of integers */ public static void writeGrayscaleImage(String filename, int[][] array) { int width = array[0].length; int height = array.length; BufferedImage image = new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB); int rgb; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { rgb = array[y][x]; rgb |= rgb << 8; rgb |= rgb << 16; image.setRGB(x, y, rgb); } } File imageFile = new File(filename); try { ImageIO.write(image, "jpg", imageFile); } catch (IOException ioe) { System.err.println("The file could not be created " + filename); return; } } }

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

Current Trends In Database Technology Edbt 2006 Edbt 2006 Workshops Phd Datax Iidb Iiha Icsnw Qlqp Pim Parma And Reactivity On The Web Munich Germany March 2006 Revised Selected Papers Lncs 4254

Authors: Torsten Grust ,Hagen Hopfner ,Arantza Illarramendi ,Stefan Jablonski ,Marco Mesiti ,Sascha Muller ,Paula-Lavinia Patranjan ,Kai-Uwe Sattler ,Myra Spiliopoulou ,Jef Wijsen

2006th Edition

3540467882, 978-3540467885

More Books

Students also viewed these Databases questions

Question

Understand why succession management is important.

Answered: 1 week ago