(图像识别与处理代码).doc_第1页
(图像识别与处理代码).doc_第2页
(图像识别与处理代码).doc_第3页
(图像识别与处理代码).doc_第4页
(图像识别与处理代码).doc_第5页
已阅读5页,还剩55页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1.FileChooserTest.java类:package OperationOfPictures;import java.awt.Image;import java.awt.Toolkit;import javax.swing.JFrame;public class FileChooserTest public static void main(String args) ImageViewerFrame frame=new ImageViewerFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); Toolkit kit=Toolkit.getDefaultToolkit(); Image image = kit.getImage(Mark.jpg); frame.setIconImage(image); 2.Canvas.java类:package OperationOfPictures;import java.awt.geom.AffineTransform;import java.awt.image.BufferedImage;import java.awt.*;import javax.swing.JPanel;public class Canvas extends JPanel private BufferedImage bufferedImage;/Buffered private AffineTransform trans = new AffineTransform(); public void setImage(BufferedImage bufferedImage) if (bufferedImage != null) this.bufferedImage = bufferedImage; if (isVisible() paintImmediately(0, 0, getWidth(), getHeight(); public BufferedImage getImage() return bufferedImage; public void setRota(double rota) trans.setToRotation(rota, (bufferedImage.getWidth() 1, (bufferedImage.getHeight() 1); protected void paintComponent(Graphics g) super.paintComponent(g); g.setColor(Color.WHITE); g.fillRect(0, 0, getWidth(), getHeight(); if (bufferedImage = null) return; Graphics2D gg = (Graphics2D) g.create(); int iw = bufferedImage.getWidth(), ih = bufferedImage.getHeight(); int anchorX = (getWidth() - iw) 1, anchorY = (getHeight() - ih) 1; AffineTransform af = gg.getTransform(); af.translate(anchorX, anchorY); af.concatenate(trans); gg.drawImage(bufferedImage, af, this); gg.dispose(); 3.Cellapplet.java类:package OperationOfPictures;import java.applet.Applet;import java.awt.*;import javax.swing.*;public class Cellapplet extends Applet private int default_r = 1; private long default_nr = 18; private int r; private long nr; private boolean layout= false; private Thread drawThread = null; private Cellcanvas canvas; private Choice radiusChoice; private JTextField ruleField; private JLabel ruleSequence; private Button stopButton,restartButton; public Cellapplet() public void init() if (drawThread != null) drawThread = null; r=1; nr=18; if (r 1) r = default_r; if (nr = 0) radius = r;/细胞的邻域半径 if (Master = 0) ruleMaster = Master;/细胞规则的控制者 ruleSequence = makeRule();/重新制定规则 private int makeRule() int n= (int) (Math.pow(cellState, 2 * radius + 1);/确定规则序列的长度 int Sequence = new intn; for (int k = 1; k = n; k+) Sequencek - 1 = computeValue(k, ruleMaster);/确定规则序列每个元素的值 return Sequence; private int computeValue(int count, long n) if (count = 1) return (int) (n % cellState); else return computeValue(count - 1, n / cellState);/递归求值 public int initSequence(int n) /随机生成细胞初始状态序列 Random random = new Random(); int Sequence = new intn; for (int i = 0; i cellState - 1) Sequencei = cellState - 1; return Sequence; public int nextSequence(int Sequence) /求当前细胞序列的下一个状态序列 int len = Sequence.length; int newSequence = new intlen; for (int i = 0; i len; i+) newSequencei = 0; for (int j = -radius; j = radius; j+) newSequencei = newSequencei * cellState + Sequence(i + j + len)%len; newSequencei = ruleSequencenewSequencei; return newSequence; public int getRuleSequence() return ruleSequence; 5.Cellcanvas.java类:package OperationOfPictures;import java.awt.*;public class Cellcanvas extends Canvas implements Runnable/细胞状态板 private int width = -1;/宽度 private int height = -1;/高度 private int gridwidth = 16;/细胞的大小 private int number1, number2;/分别控制细胞的横向变化和纵向变化 private Cellauto cell = null;/细胞序列类型 private int startSequence = null;/细胞序列的开始状态 private Color colors = new Color2;/细胞的状态数组 private Image cellPicture =null;/细胞图像 private int ruleSequence = null; public Cellcanvas(int r, long Master) cell = new Cellauto(r, Master);/细胞序列初始化实例 colors0= Color.white;/黑白色表示细胞的两种状态 colors1= Color.black; ruleSequence=cell.getRuleSequence(); public void reinit(int r, long Master) /改变条件后的细胞序列实例 cell = new Cellauto(r, Master); ruleSequence=cell.getRuleSequence(); public void run() Graphics2D g; Dimension d = getSize(); int nextSequence; width = d.width; number1 = (int) (width / gridwidth);/确定面板内一行容纳的细胞数,即细胞序列长度 height = d.height; number2 = (int) (height / gridwidth); startSequence = cell.initSequence(number1); cellPicture = this.createImage(width, height); g = (Graphics2D) cellPicture.getGraphics(); / Draw the background g.setColor(Color.white);/设置背景色 g.fillRect(0, 0, width, height);/填充背景色 / Draw the initial configuration for (int i = 0; i number1; i+) g.setColor(colorsstartSequencei);/确定初始细胞序列各个细胞的状态颜色 g.fillRect(i * gridwidth, 0, gridwidth, gridwidth);/画出初始细胞序列的状态 show_picture();/显示初始细胞序列的状态 / Compute and draw rest of the picture nextSequence = startSequence; for (int j = 1; j number2; j+) nextSequence = cell.nextSequence(nextSequence);/求演化后的细胞序列 for (int i = 0; i number1; i+) g.setColor(colorsnextSequencei);/求演化后的细胞序列各个细胞的状态颜色 g.fillRect(i * gridwidth, j * gridwidth, gridwidth, gridwidth);/画出演化后的细胞序列的状态 show_picture();/显示演化后的细胞序列的状态 try while (true) g.copyArea(0, 0, width, height, 0, -gridwidth); nextSequence = cell.nextSequence(nextSequence); for (int i = 0; i number1; i+) g.setColor(colorsnextSequencei); g.fillRect(i * gridwidth, height - gridwidth, gridwidth, gridwidth); show_picture(); Thread.sleep(100);/视觉停留时间的设定 catch (InterruptedException e) synchronized void show_picture() Graphics gp = this.getGraphics(); if (gp != null & cellPicture != null) Image picture = cellPicture; gp.drawImage(picture, 0, 0, this);/画出细胞序列的状态颜色表示 gp.dispose(); public void paint(Graphics g) /重载绘画函数,自行调用 show_picture(); public String getRule() String rule = ; for (int k = 0; k ruleSequence.length; k+) rule+= ruleSequencek; return rule; 6.Complex.java类:package OperationOfPictures;public class Complex private double re; private double im; public Complex() this.re = 0; this.im = 0; public Complex(double re, double im) this.re = re; this.im = im; public void setRE(double re) this.re = re; public void setIM(double im) this.im = im; public double getRE() return this.re; public double getIM() return this.im; public double abs() return Math.sqrt(re*re+im*im); public double angle() return Math.atan(im/re); public void equal(Complex that) this.re=that.getRE(); this.im=that.getIM(); public void addEqual(Complex that) this.re+=that.getRE(); this.im+=that.getIM(); public void subEqual(Complex that) this.re-=that.getRE(); this.im-=that.getIM(); public void mulEqual(Complex that) double Re=this.getRE()*that.getRE()-this.getIM()*that.getIM(); double Im=this.getRE()*that.getIM()+this.getIM()*that.getRE(); this.re=Re; this.im=Im; public void mulEqual(double temp) this.re*=temp; this.im*=temp; public void divEqual(double temp) this.re/=temp; this.im/=temp; public Complex add(Complex that) return new Complex(this.getRE()+that.getRE(), this.getIM()+that.getIM(); public Complex sub(Complex that) return new Complex(this.getRE()-that.getRE(), this.getIM()-that.getIM(); public Complex mul(Complex that) return new Complex(this.getRE()*that.getRE()-this.getIM()*that.getIM(), this.getRE()*that.getIM()+this.getIM()*that.getRE(); public Complex div(double temp) return new Complex(this.getRE()/temp, this.getIM()/temp); public void inverse() im=-im; 7.Coordinate.java类:package OperationOfPictures;import java.awt.*;import javax.swing.*;public class Coordinate extends JFrame private int Max; private static int height = 500; private static int width = 400; private int grayHistogram; private int rHistogram; private int gHistogram; private int bHistogram; private boolean colorFlag = false; private boolean grayFlag = false; public Coordinate(int max) Max = max; setTitle(图像直方图); JPanel pdown; setSize(width, height); pdown = new JPanel(); add(pdown, BorderLayout.SOUTH); public void paint(Graphics g) int k=1,max=400; if (max Max) while (max Max) k+; max = max + 400; g.setColor(Color.BLACK); g.drawLine(52, 460, 337, 460); g.drawLine(52, 45, 52, 460); g.drawLine(337, 460, 332, 455); g.drawLine(337, 460, 332, 465); g.drawLine(52, 45, 47, 50); g.drawLine(52, 45, 57, 50); g.drawString(频度, 43, 45); int j = 32; for (int i = 0; i 9; i+) g.drawLine(52 + 32 * i, 455, 52 + 32 * i, 460); g.drawString(Integer.toString(j * i), 49 + 32 * i, 475); j = 40; for (int i = 1; i 11; i+) g.drawLine(52, 460 - i * 40, 57, 460 - i * 40); g.drawString(Integer.toString(j * i * k), 20, 466 - i * 40); if (grayFlag) g.drawString(灰度直方图, 200, 45); g.drawString(灰度值, 340, 465); g.setColor(Color.gray); for (int i = 0; i 256; i+) g.drawLine(52 + i, 459 - (int) (grayHistogrami / k), 52 + i, 460); if (colorFlag) g.drawString(彩色直方图, 200, 45); g.draw

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论