1、 数字图像处理课程设计报告题 目: 简单图像处理系统 专 业: 信息与计算科学 学 号: 0 组 长: 指导教师: 成 绩: 二一 年 六 月 二十六 日一、课程设计目的课程设计的目的是训练我们学生应用所学数字图像处理知识,完成题目分析、编程实现等软件开发全过程的综合实践能力。巩固、深化学生的理论知识,提高编程水平,并在此过程中培养我们严谨的科学态度和良好的工作作风。二、课程设计基本要求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
3、java.awt.Image;import java.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.Linked
4、List;import javax.imageio.ImageIO;import javax.swing.ImageIcon;import javax.swing.JButton;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.
5、swing.JPanel;import javax.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 newImag
6、e;/图像的高和宽private int h,w;/保存历史操作图像矩阵private LinkedList imageStack=new LinkedList();private LinkedList tempImageStack=new LinkedList();JPanel pane;public MyShowImage(String title) super(title); this.setSize(1000,700); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); /创建菜单 JMenuBar jb=new JMenuBar
7、(); JMenu fileMenu=new JMenu(文件); jb.add(fileMenu); JMenuItem openImageMenuItem=new JMenuItem(打开图像); fileMenu.add(openImageMenuItem); openImageMenuItem.addActionListener(new OpenListener(); JMenuItem exitMenu=new JMenuItem(退出); fileMenu.add(exitMenu); exitMenu.addActionListener(new ActionListener()
8、public void actionPerformed(ActionEvent e) System.exit(0); ); JMenu operateMenu=new JMenu(图像处理); jb.add(operateMenu); JMenuItem RGBtoGrayMenuItem=new JMenuItem(灰度图像转换); operateMenu.add(RGBtoGrayMenuItem); RGBtoGrayMenuItem.addActionListener(new RGBtoGrayActionListener(); JMenuItem balanceMenuItem=ne
9、w JMenuItem(均衡化); operateMenu.add(balanceMenuItem); balanceMenuItem.addActionListener(new BalanceActionListener(); JMenu frontAndBackMenu=new JMenu(历史操作); jb.add(frontAndBackMenu); JMenuItem backMenuItem=new JMenuItem(后退); frontAndBackMenu.add(backMenuItem); backMenuItem.addActionListener(new BackAc
10、tionListener(); JMenuItem frontMenuItem=new JMenuItem(前进); frontAndBackMenu.add(frontMenuItem); frontMenuItem.addActionListener(new FrontActionListener(); this.setJMenuBar(jb); JPanel jToolBarPan=new JPanel(new FlowLayout(); FlowLayout defaultFlowLayout=(FlowLayout)jToolBarPan.getLayout(); defaultFl
11、owLayout.setAlignment(FlowLayout.LEFT); JToolBar backAndForwardToolBar=new JToolBar(); jToolBarPan.add(backAndForwardToolBar); JButton openButton=new JButton(打开,new ImageIcon(getClass().getResource(open.jpg); openButton.addActionListener(new OpenListener(); backAndForwardToolBar.add(openButton); JBu
12、tton backButton=new JButton(后退,new ImageIcon(getClass().getResource(b.jpg); backButton.addActionListener(new BackActionListener(); backAndForwardToolBar.add(backButton); JButton forwardButton=new JButton(前进,new ImageIcon(getClass().getResource(f.jpg); forwardButton.addActionListener(new FrontActionL
13、istener(); backAndForwardToolBar.add(forwardButton); JButton outButton=new JButton(离开,new ImageIcon(getClass().getResource(out.jpg); outButton.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) System.exit(0); ); backAndForwardToolBar.add(outButton); imageLabel=new JLa
14、bel(); JPanel imagePane=new JPanel(); imagePane.add(imageLabel); JScrollPane imageShowPane = new JScrollPane(imagePane); HistPanel histPanel=new HistPanel(this); JPanel p2=new JPanel(); JSplitPane jSplitPane3=new JSplitPane(JSplitPane.VERTICAL_SPLIT, histPanel,p2); jSplitPane3.setDividerLocation(250
15、); jSplitPane3.setOneTouchExpandable(true); JSplitPane jSplitPane2=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, jSplitPane3,imageShowPane); jSplitPane2.setDividerLocation(280); jSplitPane2.setOneTouchExpandable(true); pane=new OperatePane(this); JSplitPane jSplitPane1=new JSplitPane(JSplitPane.HORIZO
16、NTAL_SPLIT, jSplitPane2,pane); jSplitPane1.setDividerLocation(850); jSplitPane1.setOneTouchExpandable(true); this.add(jSplitPane1,BorderLayout.CENTER); this.add(jToolBarPan,BorderLayout.NORTH); this.setVisible(true);private class OpenListener implements ActionListener public void actionPerformed(Act
17、ionEvent e) JFileChooser jc=new JFileChooser(); int returnValue=jc.showOpenDialog(null); if (returnValue = JFileChooser.APPROVE_OPTION) File selectedFile = jc.getSelectedFile(); if (selectedFile != null) fileString=selectedFile.getAbsolutePath(); try newImage =ImageIO.read(new File(fileString); w=ne
18、wImage.getWidth(); h=newImage.getHeight(); currentPixArray=getPixArray(newImage,w,h); imageStack.clear(); tempImageStack.clear(); imageStack.addLast(currentPixArray); imageLabel.setIcon(new ImageIcon(newImage); catch(IOException ex) System.out.println(ex); MyShowImage.this.repaint(); /MyShowImage.th
19、is.pack(); /菜单监听器private class RGBtoGrayActionListener implements ActionListener public void actionPerformed(ActionEvent e) int resultArray=RGBtoGray(currentPixArray); updateImage(resultArray); private class BalanceActionListener implements ActionListener public void actionPerformed(ActionEvent e) i
20、nt resultArray=balance(currentPixArray); updateImage(resultArray); private class BackActionListener implements ActionListener public void actionPerformed(ActionEvent e) if(imageStack.size()=1) JOptionPane.showMessageDialog(null,此幅图片的处理已经没有后退历史操作了,提示, JOptionPane.INFORMATION_MESSAGE); else tempImageS
21、tack.addLast(imageStack.removeLast(); currentPixArray=imageStack.getLast(); showImage(); private class FrontActionListener implements ActionListener public void actionPerformed(ActionEvent e) if(tempImageStack.size()1) JOptionPane.showMessageDialog(null,此幅图片的处理已经没有前进历史操作了,提示, JOptionPane.INFORMATION
22、_MESSAGE); else currentPixArray=tempImageStack.removeFirst(); imageStack.addLast(currentPixArray); showImage(); /获取图像像素矩阵private intgetPixArray(Image im,int w,int h) int pix=new intw*h; PixelGrabber pg=null; try pg = new PixelGrabber(im, 0, 0, w, h, pix, 0, w); if(pg.grabPixels()!=true) try throw ne
23、w java.awt.AWTException(pg error+pg.status(); catch(Exception eq) eq.printStackTrace(); catch(Exception ex) ex.printStackTrace(); return pix; public void updateImage(int resultArray) imageStack.addLast(resultArray); currentPixArray=resultArray; showImage(); tempImageStack.clear();/显示图片private void s
24、howImage() Image pic=createImage(new MemoryImageSource(w,h,this.currentPixArray,0,w); ImageIcon ic=new ImageIcon(pic); imageLabel.setIcon(ic); /imageLabel.repaint(); this.repaint(); /灰度转换private int RGBtoGray(int ImageSource) intgrayArray=new inth*w; ColorModel colorModel=ColorModel.getRGBdefault();
25、 int i ,j,k,r,g,b; for(i = 0; i h;i+) for(j = 0;j w;j+) k = i*w+j; 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; grayArrayi*w+j=(255 24) | (r 16) | (g 8 )| b; return grayArray; /图像均衡化
26、private int balance(int ImageSource) int histogram=new int256; int dinPixArray=new intw*h; for(int i=0;ih;i+) for(int j=0;jw;j+) int grey=ImageSourcei*w+j&0xff; histogramgrey+; double a=(double)255/(w*h); double c=new double256; c0=(a*histogram0); for(int i=1;i256;i+) ci=ci-1+(int)(a*histogrami); fo
27、r(int i=0;ih;i+) for(int j=0;jw;j+) int grey=ImageSourcei*w+j&0x0000ff; int hist=(int)cgrey; dinPixArrayi*w+j=25524|hist16|hist8|hist; return dinPixArray;public int getCurrentPixArray() return currentPixArray;public void setCurrentPixArray(int currentPixArray) this.currentPixArray = currentPixArray;
28、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;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.
29、IOException;import java.io.InputStream;import java.util.Properties;import javax.swing.Box;import javax.swing.BoxLayout;import javax.swing.JButton;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JScrollPane;public class OperatePane extends JPanel implements ActionListenerprivat
30、e MyShowImage parent;private int categoryNum;private String buttonString;JButton buttons;JPanel NorthPanel=new JPanel();JPanel SouthPanel=new JPanel();GridLayout northGL;GridLayout southGL; JPanel panel;int currentNum;String butStr;String buttonClassString;JScrollPane scrollPane;public OperatePane(M
31、yShowImage parent) readini(); this.parent=parent; this.setLayout(new BorderLayout(); northGL=new GridLayout(categoryNum,1); 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 butt
32、on for(int i=0;icategoryNum;i+) buttonsi=new JButton(buttonStringi); buttonsi.addActionListener(this); this.NorthPanel.add(buttonsi); /add the panel for(int i=0;icategoryNum;i+) paneli=new JPanel(); paneli.setLayout(new BoxLayout(paneli,BoxLayout.Y_AXIS); this.scrollPane=new JScrollPane(panelcategor
33、yNum-1); this.add(scrollPane,BorderLayout.CENTER); for(int i=0;icategoryNum;i+) if(buttonClassStringi!=null) for(int j=0;jbuttonClassStringi.length;j+) try JButton b=(JButton)this.getClass().getClassLoader().loadClass(buttonClassStringij).newInstance(); FuntionButtonInterface c=(FuntionButtonInterfa
34、ce)b; c.setParent(this.parent); c.doSetText(); Box box=Box.createVerticalBox(); box.add(b); box.add(new JLabel(c.getFuntionName(); this.paneli.add(box); this.paneli.add(Box.createVerticalStrut(20); catch(ClassNotFoundException cnfe) cnfe.printStackTrace(); catch(InstantiationException inse) inse.pri
35、ntStackTrace(); catch(IllegalAccessException illae) illae.printStackTrace(); this.add(this.NorthPanel, BorderLayout.NORTH); this.add(this.SouthPanel, BorderLayout.SOUTH);private void readini() InputStream is=this.getClass().getResourceAsStream(funtion.properties.xml); Properties prop=new Properties(
36、); try prop.loadFromXML(is); catch(IOException ioe) System.out.println(Something wrong with inputing properties); try is.close(); catch(IOException e) System.out.println(Close input stream is failed!); this.categoryNum=Integer.parseInt(prop.getProperty(categoryNum); buttonString=new StringcategoryNu
37、m; for(int i=1;i=categoryNum;i+) buttonStringi-1=prop.getProperty(category+i); butStr=prop.getProperty(category1_fun1); buttonClassString=new StringcategoryNum; for(int i=1;icategoryNum;i+) String str=prop.getProperty(category+i+_funtionNum); if(str!=null) int funtionNum=Integer.parseInt(str); if(fu
38、ntionNum!=0) buttonClassStringi-1=new StringfuntionNum; for(int j=1;j=funtionNum;j+) buttonClassStringi-1j-1=prop.getProperty(category+i+_fun+j); buttons=new JButtoncategoryNum; panel=new JPanelcategoryNum;public void actionPerformed (ActionEvent event) JButton button=(JButton)event.getSource(); Str
39、ing selectButton=button.getText(); boolean flag=true; int i; for(i=0;icategoryNum&flag;i+) if(buttonStringi.equals(selectButton) flag=false; this.NorthPanel.removeAll(); this.northGL.setRows(i); for(int j=0;ji;j+) this.NorthPanel.add(buttonsj); this.SouthPanel.removeAll(); this.southGL.setRows(categoryNum-i); for(int k=i;kcategoryNum;k+) this.SouthPanel.add(buttonsk); this.remove(scrollPane); currentNum=i-1; this.scrollPane=new JScrollPane(panelcurrentNum); this.add(scrollPane,BorderLayout.CENTER); System.gc(); this.parent.setVisible(true);4、左边直方图Panel
版权声明:以上文章中所选用的图片及文字来源于网络以及用户投稿,由于未联系到知识产权人或未发现有关知识产权的登记,如有知识产权人并不愿意我们使用,如有侵权请立即联系:2622162128@qq.com ,我们立即下架或删除。
Copyright© 2022-2024 www.wodocx.com ,All Rights Reserved |陕ICP备19002583号-1
陕公网安备 61072602000132号 违法和不良信息举报:0916-4228922