版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、. . . . 数字图像处理课程设计报告题 目: 简单图像处理系统 专 业: 信息与计算科学 23 / 23一、课程设计目的课程设计的目的是训练我们学生应用所学数字图像处理知识,完成题目分析、编程实现等软件开发全过程的综合实践能力。巩固、深化学生的理论知识,提高编程水平,并在此过程中培养我们严谨的科学态度和良好的工作作风。二、课程设计基本要求1、对知识点的掌握要求:(1)熟悉数字图像处理的概念,特点与应用(2)掌握数字图像处理处理过程与问题的分析与纠正(3)利用C+对确定对图像处理分析(4)学会C+的使用,掌握C+的程序设计方法2、分组情况:组长: 组员 :设计全过程的监督与协助、部分源程序代
2、码的编写和整个源程序代码的整理。:编写右边直方图Panel的代码:编写主程序并运行:编写左边直方图Panel的代码:结果分析部分与查找相关文献3、课程设计容以确定处理分析的对象,进行编程来实现这一过程。三、课程设计实现步骤1、问题描述先对图像进行分析,从而编写主程序,编写右边直方图Panel的代码,再编写左边直方图Panel的代码,从而运行出如结果分析中的图像。2、主程序如下:package dege.imagetool;import java.awt.BorderLayout;import java.awt.FlowLayout;import java.awt.Image;import ja
3、va.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.image.BufferedImage;import java.awt.image.ColorModel;import java.awt.image.MemoryImageSource;import java.awt.image.PixelGrabber;import java.io.File;import java.io.IOException;import java.util.LinkedList;import javax.imagei
4、o.ImageIO;import javax.swing.ImageIcon;import javax.swing.utton;import javax.swing.JFileChooser;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JMenu;import javax.swing.JMenuBar;import javax.swing.JMenuItem;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.
5、swing.JScrollPane;import javax.swing.JSplitPane;import javax.swing.JToolBar;public class MyShowImage extends JFrame /保存当前操作的像素矩阵private int currentPixArray=null;/图像的路径private String fileString=null;/用于显示图像的标签private JLabel imageLabel=null;/加载的图像private BufferedImage newImage;/图像的高和宽private int h,w;/
6、保存历史操作图像矩阵private LinkedList<int> imageStack=new LinkedList<int>();private LinkedList<int> tempImageStack=new LinkedList<int>();JPanel pane;public MyShowImage(String title) super(title); this.setSize(1000,700); this.setDefaultCloseOperation
7、(JFrame.EXIT_ON_CLOSE); /创建菜单 JMenuBar =new JMenuBar(); JMenu fileMenu=new JMenu("文件"); .add(fileMenu); JMenuItem openImageMenuItem=new JMenuItem("打开图像"); fileMenu.add(openImageMenuItem); op
8、enImageMenuItem.addActionListener(new OpenListener(); JMenuItem exitMenu=new JMenuItem("退出"); fileMenu.add(exitMenu); exitMenu.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) Sys
9、tem.exit(0); ); JMenu operateMenu=new JMenu("图像处理"); .add(operateMenu); JMenuItem RGBtoGrayMenuItem=new JMenuItem("灰度图像转换"); operateMenu.add(RGBtoGrayMenuItem); RGBtoGrayMenuIte
10、m.addActionListener(new RGBtoGrayActionListener(); JMenuItem balanceMenuItem=new JMenuItem("均衡化"); operateMenu.add(balanceMenuItem); balanceMenuItem.addActionListener(new BalanceActionListener(); JMenu frontAndBackMenu=new JMenu("历史操作");&
11、#160; .add(frontAndBackMenu); JMenuItem backMenuItem=new JMenuItem("后退"); frontAndBackMenu.add(backMenuItem); backMenuItem.addActionListener(new BackActionListener(); JMenuItem frontMenuItem=new JMenuItem("前进"); fr
12、ontAndBackMenu.add(frontMenuItem); frontMenuItem.addActionListener(new FrontActionListener(); this.setJMenuBar(); JPanel jToolBarPan=new JPanel(new FlowLayout(); FlowLayout defaultFlowLayout=(FlowLayout)jToolBarPan.getLayout(); defaul
13、tFlowLayout.setAlignment(FlowLayout.LEFT); JToolBar backAndForwardToolBar=new JToolBar(); jToolBarPan.add(backAndForwardToolBar); utton openButton=new utton("打开",new ImageIcon(getClass().getResource("open.jpg"); openButton.addAction
14、Listener(new OpenListener(); backAndForwardToolBar.add(openButton); utton backButton=new utton("后退",new ImageIcon(getClass().getResource("b.jpg"); backButton.addActionListener(new BackActionListener(); backAndForwardToolBar.add(back
15、Button); utton forwardButton=new utton("前进",new ImageIcon(getClass().getResource("f.jpg"); forwardButton.addActionListener(new FrontActionListener(); backAndForwardToolBar.add(forwardButton); utton outButton=new utton("离开
16、",new ImageIcon(getClass().getResource("out.jpg"); outButton.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) System.exit(0); ); backAndForwardToolBar.add(
17、outButton); imageLabel=new JLabel(""); JPanel imagePane=new JPanel(); imagePane.add(imageLabel); JScrollPane imageShowPane = new JScrollPane(imagePane); HistPanel histPanel=new HistPanel(this); &
18、#160; JPanel p2=new JPanel(); JSplitPane jSplitPane3=new JSplitPane(JSplitPane.VERTICAL_SPLIT, histPanel,p2); jSplitPane3.setDividerLocation(250); jSplitPane3.setOneTouchExpandable(true); JSplitPane jSplitPane2=new J
19、SplitPane(JSplitPane.HORIZONTAL_SPLIT, jSplitPane3,imageShowPane); jSplitPane2.setDividerLocation(280); jSplitPane2.setOneTouchExpandable(true); pane=new OperatePane(this); JSplitPane jSplitPane1=ne
20、w JSplitPane(JSplitPane.HORIZONTAL_SPLIT, jSplitPane2,pane); jSplitPane1.setDividerLocation(850); jSplitPane1.setOneTouchExpandable(true); this.add(jSplitPane1,BorderLayout.CENTER); this.add(jToolBarPan,BorderLayout.
21、NORTH); this.setVisible(true); private class OpenListener implements ActionListener public void actionPerformed(ActionEvent e) JFileChooser jc=new JFileChooser(); int returnValue=jc.showOpenDialog(null);
22、160; if (returnValue = JFileChooser.APPROVE_OPTION) File selectedFile = jc.getSelectedFile();
23、160; if (selectedFile != null) fileString=selectedFile.getAbsolutePath(); try
24、 newImage =ImageIO.read(new File(fileString); w=newImage.getWidth(); h=newImage.getHeight(); currentPixArray=getPixArray(newImage,w,h);
25、60; imageStack.clear(); tempImageStack.clear(); imageStack.addLast(currentPixArray); imageLabel.setIcon(new ImageIcon(newImage);
26、0; catch(IOException ex) System.out.println(ex);
27、60; MyShowImage.this.repaint(); /MyShowImage.this.pack(); /菜单监听器private class RGBtoGrayActionListener implements ActionListener public void actionPerformed(ActionEvent e) int resultArray=RGBtoGray(currentPixArray); u
28、pdateImage(resultArray); private class BalanceActionListener implements ActionListener public void actionPerformed(ActionEvent e) int resultArray=balance(currentPixArray); updateImage(resultArray); privat
29、e class BackActionListener implements ActionListener public void actionPerformed(ActionEvent e) if(imageStack.size()<=1) JOptionPane.showMessageDialog(null,"此幅图片的处理已经没有后退历史操作了","提示", JOpt
30、ionPane.INFORMATION_MESSAGE); else tempImageStack.addLast(imageStack.removeLast(); currentPixArray=imageStack.getLast(); showImage(); private class FrontActionListener
31、 implements ActionListener public void actionPerformed(ActionEvent e) if(tempImageStack.size()<1) JOptionPane.showMessageDialog(null,"此幅图片的处理已经没有前进历史操作了","提示", JOptionPane.INFORMATION_MES
32、SAGE); else currentPixArray=tempImageStack.removeFirst(); imageStack.addLast(currentPixArray); showImage(); /获取图像像素矩阵private intgetPixArray(Image im,int w,int h)
33、 int pix=new intw*h; PixelGrabber pg=null; try pg = new PixelGrabber(im, 0, 0, w, h, pix, 0, w); if(pg.grabPixels()!=true)
34、0; try throw new java.awt.AWTException("pg error"+pg.status(); catch(Exception eq)
35、0; eq.printStackTrace(); catch(Exception ex) ex.printStackTrace();
36、; return pix; public void updateImage(int resultArray) imageStack.addLast(resultArray); currentPixArray=resultArray; showImage(); tempImageStack.clear();/显示图片private void showImage() Image p
37、ic=createImage(new MemoryImageSource(w,h,this.currentPixArray,0,w); ImageIcon ic=new ImageIcon(pic); imageLabel.setIcon(ic); /imageLabel.repaint(); this.repaint(); /灰度转
38、换private int RGBtoGray(int ImageSource) intgrayArray=new inth*w; ColorModel colorModel=ColorModel.getRGBdefault(); int i ,j,k,r,g,b; for(i = 0; i < h;i+) for(j = 0;j < w;j+) k = i*w+j;
39、60; r = colorModel.getRed(ImageSourcek); g = colorModel.getGreen(ImageSourcek); b = colorModel.getBlue(ImageSourcek); int gray=(int)(r*0.3+g*0.59+b*0.11); r=g=b=gray;
40、; grayArrayi*w+j=(255 << 24) | (r << 16) | (g << 8 )| b; return grayArray; /图像均衡化private int balance(int ImageSource) int histogram=new int256; int dinPixArray=new intw*h; &
41、#160; for(int i=0;i<h;i+) for(int j=0;j<w;j+) int grey=ImageSourcei*w+j&0xff; histogramgrey+;
42、0; double a=(double)255/(w*h); double c=new double256; c0=(a*histogram0); for(int i=1;i<256;i+) ci=ci-1+(int)(a*histogrami);
43、60; for(int i=0;i<h;i+) for(int j=0;j<w;j+) int grey=ImageSourcei*w+j&0x0000ff; int hist=(int)cgrey; din
44、PixArrayi*w+j=255<<24|hist<<16|hist<<8|hist; return dinPixArray;public int getCurrentPixArray() return currentPixArray;public void setCurrentPixArray(int currentPixArray) this.
45、currentPixArray = currentPixArray;public int getH() return h;public int getW() return w;public static void main(String args) new MyShowImage("ShowImage");3、右边功能Panel的代码如下:package dege.imagetool;import java.awt.BorderLayout;import java.awt.GridLayout;i
46、mport java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.IOException;import java.io.InputStream;import java.util.Properties;import javax.swing.Box;import javax.swing.BoxLayout;import javax.swing.utton;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.
47、JScrollPane;public class OperatePane extends JPanel implements ActionListenerprivate MyShowImage parent;private int categoryNum;private String buttonString;utton buttons;JPanel NorthPanel=new JPanel();JPanel SouthPanel=new JPanel();GridLayout northGL;GridLayout southGL; JPanel panel;int currentNum;S
48、tring butStr;String buttonClassString;JScrollPane scrollPane;public OperatePane(MyShowImage parent) readini(); this.parent=parent; this.setLayout(new BorderLayout(); northGL=new GridLayout(categoryNum,1);
49、; southGL=new GridLayout(0,1); currentNum=categoryNum-1; /set layout for the panel this.NorthPanel.setLayout(this.northGL); this.SouthPanel.setLayout(this.southGL); /add the button
50、; for(int i=0;i<categoryNum;i+) buttonsi=new utton(buttonStringi); buttonsi.addActionListener(this); this.NorthPanel.add(buttonsi); /add the panel for(int i=0;i<categoryNum;i+)
51、160; paneli=new JPanel(); paneli.setLayout(new BoxLayout(paneli,BoxLayout.Y_AXIS); this.scrollPane=new JScrollPane(panelcategoryNum-1); this.add(scrollPane,BorderLayout.CENTER); for(int i=0;i
52、<categoryNum;i+) if(buttonClassStringi!=null) for(int j=0;j<buttonClassStringi.length;j+) try utton b=(utton)this.getClass().getClassLoader().loadClass(buttonClassStringij).newInstance()
53、; FuntionButtonInterface c=(FuntionButtonInterface)b; c.setParent(this.parent); c.doSetText(); Box box=Box.createVertica
54、lBox(); box.add(b); box.add(new JLabel(c.getFuntionName(); this.paneli.add(box); this.paneli.add(Box.c
55、reateVerticalStrut(20); catch(ClassNotFoundExceptionfe) fe.printStackTrace(); catch(InstantiationException inse) inse.printStackTrace
56、(); catch(IllegalAccessException illae) illae.printStackTrace();
57、0; this.add(this.NorthPanel, BorderLayout.NORTH); this.add(this.SouthPanel, BorderLayout.SOUTH); private void readini() InputStream is=this.getClass().getResourceAsStream("perties.xml"); Properties pro
58、p=new Properties(); try prop.loadFromXML(is); catch(IOException ioe) System.out.println("Something wrong with inputing properties"); try is.close(); catch(IOException e) &
59、#160; System.out.println("Close input stream is failed!"); this.categoryNum=Integer.parseInt(prop.getProperty("categoryNum"); buttonString=new StringcategoryNum; for(int i=1;i<=categoryNum;i+)
60、; buttonStringi-1=prop.getProperty("category"+i); butStr=prop.getProperty("category1_fun1"); buttonClassString=new StringcategoryNum; for(int i=1;i<categoryNum;i+) String str=prop.getProperty("
61、category"+i+"_funtionNum"); if(str!=null) int funtionNum=Integer.parseInt(str); if(funtionNum!=0) buttonClassStringi-1=new StringfuntionNum; for(int j=1;j<=
62、funtionNum;j+) buttonClassStringi-1j-1=prop.getProperty("category"+i+"_fun"+j); buttons=ne
63、w uttoncategoryNum; panel=new JPanelcategoryNum;public void actionPerformed (ActionEvent event) utton button=(utton)event.getSource(); String selectButton=button.getText(); boolean flag=true; int i; for(i=0;i<cat
64、egoryNum&&flag;i+) if(buttonStringi.equals(selectButton) flag=false; this.NorthPanel.removeAll(); this.northGL.setRows(i); for(int j=0;j<i;j+) this.NorthPanel.add(butto
65、nsj); this.SouthPanel.removeAll(); this.southGL.setRows(categoryNum-i); for(int k=i;k<categoryNum;k+) this.SouthPanel.add(buttonsk); this.remove(scrollPane); currentNum=i-1;
66、160; this.scrollPane=new JScrollPane(panelcurrentNum); this.add(scrollPane,BorderLayout.CENTER); System.gc(); this.parent.setVisible(true); 4、左边直方图Panel的代码如下:package dege.imagetool;import java.awt.Color;import java.awt.Graphics;import javax.
67、swing.JPanel;import javax.swing.JTabbedPane;public class HistPanel extends JTabbedPane private MyShowImage parent;public HistPanel(MyShowImage parent) this.parent=parent; MyPanel redHistPanel =new MyPanel(parent,0x00ff0000,16,Color.red); MyPanel greenHistPanel =ne
68、w MyPanel(parent,0x0000ff00,8,Color.green); MyPanel blueHistPanel =new MyPanel(parent,0x000000ff,0,Color.blue); this.addTab("红色直方图", redHistPanel); this.addTab("绿色直方图", greenHistPanel); this.addTab("蓝色直方图", blu
69、eHistPanel);private class MyPanel extends JPanel private MyShowImage parent; private int bit; private int movebit; private Color color; public MyPanel(MyShowImage parent,int bit,int movebit,Color color) this.pa
70、rent =parent; this.bit =bit; this.movebit =movebit; this.color =color; public void paint(Graphics g) g.drawLine(10, 200, 10, 0); g.drawLi
71、ne(10, 0, 5, 5); g.drawLine(10, 0, 15, 5); g.drawLine(10,200,270,200); g.drawLine(270,200,265,195); g.drawLine(270, 200, 265, 205); g.drawString("255", 250, 215); g.drawString("
72、0", 10, 215); if(parent.getCurrentPixArray()!=null) int imageSource=parent.getCurrentPixArray(); int pixCount=new int256; int length=imageSource.length; for(int i=
73、0;i<length;i+) pixCount(imageSourcei&bit)>>movebit+; float max=0.0f; float min=1.0f; float percent=new float256;
74、 for(int i=0;i<256;i+) float temp=(float)pixCounti)/length; percenti=temp; max=temp>max? temp:max; min=temp<min? temp:min;
75、 float differ =max-min; int coefficient =(int)(180/differ); g.setColor(color); for(int i=0;i<256;i+) g.drawLine(10+i, 200, 10+i, 200-(int)(coeffici
76、ent*percenti); 5、系统采用动态加载功能模块的方法,而且每一个新方法的加入以一个新的功能Button为基础这样的功能类需要实现以下接口以与扩展utton接口如下:package dege.imagetool;import javax.swing.Action;import javax.swing.ImageIcon;public interface FuntionButtonInterface void setParent(MyShowImage parent);voi
77、d doSetAction();void doSetText();void doSetIcon();String getFuntionName();四、结果分析已经实现了的三个功能第一个:转换成灰度图像package dege.imagetool;import java.awt.event.ActionEvent;import java.awt.image.ColorModel;import javax.swing.AbstractAction;import javax.swing.ImageIcon;import javax.swing.utton;public class RGBtoGra
78、yButton extends utton implements FuntionButtonInterface private MyShowImage parent;private String funtionName; public RGBtoGrayButton() this.doSetAction(); this.doSetIcon(); public void doSetAction() / TODO 自动生成方法存根 super.setAction(new RGBtoGrayAction();public void doSetIcon() / TODO 自动生成方法存根 super.setIcon(new Ima
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- Photoshop笔试题重点及详细答案(完整版)
- 2025-2026学年湖北省赤壁市初中数学九年级期末下册提升黑金试卷详细参考解析
- PCS专业技能认证考核试题
- 农田排水沟清淤及衬砌方案
- 慢性偏头痛针灸联合药物疗程规范共识
- 宫颈环扎术后活动分级管理共识
- PADI开放水域(OW)潜水员考试真题及详细答案
- Oracle 11g 数据库笔试试题及详细答案
- 咬合桩围护结构施工及桩缝控制方案
- 香料蒸馏提取操作工安全规程
- 纺织厂安全培训
- 信访培训教学课件
- 2025 肝硬化腹水查房课件
- 居住空间课件
- 2025年军事理论知识竞赛试题库及答案(完整版)
- 银行分流引导课件
- 初中语文统编版(五四学制)六年级上册第四单元13 穷人 公开课一等奖创新教学设计
- GJB3165A-2020航空承力件用高温合金热轧和锻制棒材规范
- 小学肺结核宣传课件
- DBJ50-T-200-2024 建筑桩基础技术标准
- 贫血病人疑难病例讨论
评论
0/150
提交评论