📄 grayscaleimage.java
字号:
package IrisRecog;/** * GrayscaleImage.java * * The class holds both the original image and a two-way integer array representation * of the grayscale of that image. * * @owner Michael Huffman * @author Team 6: A. Bare, I. Chaugule,M. Huffman, M. Pearson, C. Schell * @version 0.0.1 * * CSC 480 Section 2 * Fall 2005 * 10/8/05 * * Edit History: * 10/8/05 - created * 10/9/05 - updated the intensity methods, documented and commented * 10/10/05 - added constructor to create grayscale image with width and height */ import java.awt.*;import java.awt.image.*;import javax.swing.*;import java.io.*;public class GrayscaleImage implements Serializable{ /* * Two dimensional array that holds the luminosity of each pixel in the image */ protected int [][] int_Arr_Pixels; /* * The grayscale buffered version of the image. */ protected BufferedImage bim_Grayscale; /** * Empty constructor creates a grayscale image without any * data but with a given size. * * @param w The width * @param h The height */ public GrayscaleImage(int w, int h) { int_Arr_Pixels = new int[w][h]; bim_Grayscale = null; } /** * Constructor creates a grayscale image from the given image. * * @param i The image that is to be turned into a grayscale image */ public GrayscaleImage(Image i) { //Convert the image to grayscale this.int_Arr_Pixels = Functions.convertToGrayscale(i); /* Create the buffered image grayscale representation */ this.bim_Grayscale = new BufferedImage(i.getWidth(null), i.getHeight(null), BufferedImage.TYPE_BYTE_GRAY); Graphics g = bim_Grayscale.getGraphics(); g.drawImage(i, 0, 0, null); g.dispose(); } /** * Returns the original image object. * * @return the original image */ public Image getImage() { return (Image)bim_Grayscale; } /** * Returns the width of the image. * * @return the width of the image */ public int getWidth() { return this.bim_Grayscale.getWidth(null); } /** * Returns the height of the image. * * @return the height of the image */ public int getHeight() { return this.bim_Grayscale.getHeight(null); } /** * Returns the intensity at the specified cartesian location. * * @param x The x coordinate of the located to get the intensity of * @param y The y coordinate of the located to get the intensity of * @return the integer intensity value of the specified cartesian location */ public int getIntensity(int x, int y) { return this.int_Arr_Pixels[x][y]; } /** * Sets the intensity at the specified cartesian location to the given value. * * @param x The x coordinate of the located to get the intensity of * @param y The y coordinate of the located to get the intensity of * @param intensity The intensity to set */ public void setIntensity(int x, int y, int intensity) { this.int_Arr_Pixels[x][y] = intensity; } /** * Returns the intensity at the specified cartesian point. * * @param p The point to get the intensity of * @return the integer intensity value of the specified point */ public int getIntensity(Point p) { return this.int_Arr_Pixels[(int)p.getX()][(int)p.getY()]; } /** * Sets the intensity at the specified cartesian point to the given value. * * @param p The point to get the intensity of * @param intensity The intensity to set */ public void setIntensity(Point p, int intensity) { this.int_Arr_Pixels[(int)p.getX()][(int)p.getY()] = intensity; } /** * Returns the intensity at the specified polar location. * * @param center The origin of the polar coordinate syste, * @param theta The angle of the polar coordinate * @param r The radius of the polar coordinate * @return the integer intensity value of the specified polar location */ public int getIntensity(Point center, double theta, double r) { Point pt_Cartesian = Functions.polarToCartesian(center, theta, r); return this.getIntensity(pt_Cartesian); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -