Hi. I require your wonderful help with figuring out this challenging code.
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.ImageIO;
public class ImageLab {
/*
* This is the grayscale example. Use it for inspiration / help, but you dont
* need to change it.
*
* Creates and returns a new BufferedImage of the same size as the input
* image. The new image is the grayscale version of the input (red, green, and
* blue components averaged together).
*/
public static BufferedImage imageToGrayscale(BufferedImage input) {
// store the image width and height in variables for later use
int img_width = input.getWidth();
int img_height = input.getHeight();
// create a new BufferedImage with the same width and height as the input
// image. TYPE_INT_RGB means we want to specify pixel values using their
// red, green, and blue components.
BufferedImage output_img = new BufferedImage(
img_width, img_height, BufferedImage.TYPE_INT_RGB);
// Loop over all pixels
for (int x = 0; x < img_width; x++) {
for (int y = 0; y < img_height; y++) {
// Get the color of the input image as a java.awt.Color object
Color color_at_pos = new Color(input.getRGB(x, y));
// Call the getRed(), getGreen(), and getBlue() methods on the color
// object to store the red, green, and blue values into separate integer
// variables.
int red = color_at_pos.getRed();
int green = color_at_pos.getGreen();
int blue = color_at_pos.getBlue();
// to get the grayscale version, we just average the red, green, and
// blue channels, then use that average as the red, green, and blue
// values in the output image.
int average = (red + green + blue) / 3;
// You'll get an IllegalArgumentException if you try to specify red,
// green, or blue values greater than 255 or less than 0. While it's
// mathematically impossible to average three values in that range and
// get a value outside the range, the calculations in the other tasks
// will sometimes produce values outside the range. This code "clamps"
// the value to the range 0 - 255
if (average < 0) {
average = 0;
} else if (average > 255) {
average = 255;
}
// make a new Color object, which has the average intensity ((r+g+b)/3)
// for each of its channels.
Color average_color = new Color(average, average, average);
// in the output image, set the color at position (x,y) to our
// calculated average color
output_img.setRGB(x, y, average_color.getRGB());
}
}
// return the output image.
return output_img;
}
public static BufferedImage threshold(BufferedImage input, int level) {
// Replace this method body with your code
return null;
}
public static BufferedImage quantize(BufferedImage input) {
// Replace this method body with your code
return null;
}
public static BufferedImage colorRotate(BufferedImage input) {
// Replace this method body with your code
return null;
}
public static BufferedImage warhol(BufferedImage input) {
// Replace this method body with your code
return null;
}
public static BufferedImage sharpen(BufferedImage input) {
// Replace this method body with your code
return null;
}
public static BufferedImage boxBlur(BufferedImage input) {
// Replace this method body with your code
return null;
}
public static BufferedImage simpleEdgeDetect(BufferedImage input) {
// Replace this method body with your code
return null;
}
public static BufferedImage sobelEdgeDetect(BufferedImage input) {
// Replace this method body with your code
return null;
}
/*=============== You don't need to change anything below this line =======*/
public static BufferedImage readImage(String filename) {
BufferedImage img = null;
try {
img = ImageIO.read(new File(filename));
} catch (IOException e) {
System.out.println("Error - couldn't load " + filename);
return null;
}
return img;
}
public static void writeImage(BufferedImage img, String filename) {
try {
System.out.printf("Writing %s...\n", filename);
File ImageFile = new File(filename);
ImageIO.write(img, "jpg", ImageFile);
} catch (IOException e) {
System.out.printf("Error writing %s\n", filename);
e.printStackTrace();
}
}
public static void main(String[] args) {
if (args.length == 0) {
System.out.println("Usage: java ImageLab <filename>");
System.exit(0);
}
BufferedImage img = readImage(args[0]);
if(img == null) {
System.out.println("Couldn't read image");
System.exit(0);
}
System.out.println("Running imageToGrayscale()...");
BufferedImage gray = imageToGrayscale(img);
if (gray != null) {
writeImage(gray, "grayscale.jpg");
} else {
System.out.println("Got null");
}
System.out.println("Running threshold()...");
BufferedImage thresh = threshold(img, 128);
if (thresh != null) {
writeImage(thresh, "threshold.jpg");
} else {
System.out.println("Got null");
}
System.out.println("Running quantize()...");
BufferedImage quant = quantize(img);
if (quant != null) {
writeImage(quant, "quant.jpg");
} else {
System.out.println("Got null");
}
System.out.println("Running colorRotate()...");
BufferedImage rot = colorRotate(img);
if (rot != null) {
writeImage(rot, "colorrotate.jpg");
} else {
System.out.println("Got null");
}
System.out.println("Running warhol()...");
BufferedImage war = warhol(img);
if (war != null) {
writeImage(war, "warhol.jpg");
} else {
System.out.println("Got null");
}
System.out.println("Running sharpen()...");
BufferedImage sharp = sharpen(img);
if (sharp != null) {
writeImage(sharp, "sharpen.jpg");
} else {
System.out.println("Got null");
}
System.out.println("Running boxBlur()...");
BufferedImage blur = boxBlur(img);
if (blur != null) {
writeImage(blur, "blur.jpg");
} else {
System.out.println("Got null");
}
System.out.println("Running simpleEdgeDetect()...");
BufferedImage edge = simpleEdgeDetect(img);
if (edge != null) {
writeImage(edge, "edge.jpg");
} else {
System.out.println("Got null");
}
System.out.println("Running sobelEdgeDetect()...");
BufferedImage sobel = sobelEdgeDetect(img);
if (sobel != null) {
writeImage(sobel, "sobel.jpg");
} else {
System.out.println("Got null");
}
}
}The expression java.awt.Color refers to a file named Color.class.This is a class that has colors that we may use to change the apperance of the object int the interface which we are using.
In this,to change the apperance of area in browser while running program we use YELLOW color object.
Color begins with a capital letter that tells that it is a class file in java . Firstly note the path to the Color class.It is diffrent to the path of JApplet and JLabel classes.we all know that Classes in java are usually grouped together by functionality.
Many of the classes that control the apperance of GUI are contained in awt package. awt stands for "abstract windowing toolkit".
The classes in this package are contained in the version of java prior to java swing.That is the reason why the path is "java .awt.Color".
Hi. I require your wonderful help with figuring out this challenging code. import java.awt.Color; import java.awt.image.BufferedImage;...
in java coorect this code & screenshoot your output ---------------------------------------------------------------------- public class UNOGame { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner input=new Scanner(System.in); Scanner input2=new Scanner(System.in); UNOCard c=new UNOCard (); UNOCard D=new UNOCard (); Queue Q=new Queue(); listplayer ll=new listplayer(); System.out.println("Enter Players Name :\n Click STOP To Start Game.."); String Name = input.nextLine();...
I need help running this code. import java.util.*; import java.io.*; public class wordcount2 { public static void main(String[] args) { if (args.length !=1) { System.out.println( "Usage: java wordcount2 fullfilename"); System.exit(1); } String filename = args[0]; // Create a tree map to hold words as key and count as value Map<String, Integer> treeMap = new TreeMap<String, Integer>(); try { @SuppressWarnings("resource") Scanner input = new Scanner(new File(filename));...
When I invoke the forward or backward method the current_number isnt being changed. Not sure if its something in my switch case or my methods.. package project4; import java.awt.image.BufferedImage; import java.net.URL; import java.util.Scanner; import javax.imageio.ImageIO; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; public class PictureViewer { final static int MIN_NUMBER = 0; final static int MAX_NUMBER = 8; static int image_number = 1; public static int forward(int current_number) { if (current_number < MAX_NUMBER) { return current_number ++; }...
I cant get the code to work. Any help would be appreciated. Instruction.java package simmac; public class Instruction { public static final int DW = 0x0000; public static final int ADD = 0x0001; public static final int SUB = 0x0002; public static final int LDA = 0x0003; public static final int LDI = 0x0004; public static final int STR = 0x0005; public static final int BRH = 0x0006; public static final int CBR = 0x0007; public static final int HLT...
***This is a JAVA question***
------------------------------------------------------------------------------------------------
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.imageio.*;
import javax.swing.*;
import javax.swing.event.*;
public class DrawingPanel implements ActionListener {
public static final int DELAY = 50; // delay between repaints in
millis
private static final String DUMP_IMAGE_PROPERTY_NAME =
"drawingpanel.save";
private static String TARGET_IMAGE_FILE_NAME = null;
private static final boolean PRETTY = true; // true to
anti-alias
private static boolean DUMP_IMAGE = true; // true to write
DrawingPanel to file
private int width, height; // dimensions...
[Java] PLEASE FIX MY CODE
I think I'm thinking in wrong way. I'm not sure what is wrong
with my code.
Here'e the problem:
Write a class SemiCircle that represents the northern half of a
circle in 2D space. A SemiCircle has center coordinates and a
radius.
Define a constructor:
public SemiCircle(int centerX, int centerY, int theRadius)
Implement the following methods:
public boolean contains(int otherX, int
otherY)
returns true if the point given by the coordinates is inside the
SemiCircle....
need help editing or rewriting java code, I have this program
running that creates random numbers and finds min, max, median ect.
from a group of numbers,array. I need to use a data class and a
constructor to run the code instead of how I have it written right
now. this is an example of what i'm being asked
for.
This is my code:
import java.util.Random;
import java.util.Scanner;
public class RandomArray {
// method to find the minimum number in...
Please write a code in python! Define and test a function named posterize. This function expects an image and a tuple of RGB values as arguments. The function modifies the image like the blackAndWhite function, but it uses the given RGB values instead of black. images.py import tkinter import os, os.path tk = tkinter _root = None class ImageView(tk.Canvas): def __init__(self, image, title = "New Image", autoflush=False): master = tk.Toplevel(_root) master.protocol("WM_DELETE_WINDOW", self.close) tk.Canvas.__init__(self, master, width = image.getWidth(), height = image.getHeight())...
please make a pretty JAVA GUI for this code
this is RED BLACK TREE and i Finished code
already
jus need a JAVA GUI for this code ... if poosible make
it pretty to look thanks and
please make own GUI code base on my code
thanks
ex:
(GUI only have to show RBTree)
----------------------------------------
RBTree.java
import java.util.Stack;
public class RBTree{
private Node current;
private Node parent;
private Node grandparent;
private Node header;
private Node...
Need help with the UML for this code? Thank you. import java.util.Scanner; public class Assignment1Duong1895 { public static void header() { System.out.println("\tWelcome to St. Joseph's College"); } public static void main(String[] args) { Scanner input = new Scanner(System.in); int d; header(); System.out.println("Enter number of items to process"); d = input.nextInt(); ...