当前位置:文档之家› 基于谱聚类的图像分割

基于谱聚类的图像分割

本科生毕业设计姓名:学号:学院:计算机科学与技术学院专业:计算机科学与技术设计题目:基于谱聚类的图像分割专题:图像分割的设计与实现指导教师:职称:副教授大学毕业设计任务书学院计算机专业年级学生姓名任务下达日期:毕业设计日期:毕业设计题目:毕业设计专题题目毕业设计主要内容和要求:院长签章:指导教师签字:中国矿业大学毕业设计指导教师评阅书指导教师评语(①基础理论及基本技能的掌握;②独立解决实际问题的能力;③研究内容的理论依据和技术方法;④取得的主要成果及创新点;⑤工作态度及工作量;⑥总体评价及建议成绩;⑦存在问题;⑧是否同意答辩等):成绩:指导教师签字:年月日中国矿业大学毕业设计评阅教师评阅书评阅教师评语(①选题的意义;②基础理论及基本技能的掌握;③综合运用所学知识解决实际问题的能力;③工作量的大小;④取得的主要成果及创新点;⑤写作的规范程度;⑥总体评价及建议成绩;⑦存在问题;⑧是否同意答辩等):成绩:评阅教师签字:年月日中国矿业大学毕业设计答辩及综合成绩需求分析一、利用前台,得到一张原始JPG图片;二、把这张图片传到后台,JAVA通过JRI调用R;三、利用R调用K-Means的改进算法,实现对这张图片的处理,由于一张图片的像素值是一个矩阵,可以得到一组关于像素值的数据;四、把这组像素值进行分类,对各类赋予不同的颜色进行标记,从而区分出需要的图片信息;五、把得到的新图片传到前台;六、前台对进行处理后的图片进行显示,从图像中得到需要的信息,从而实现图像的分割。

概要设计模块功能图:图片:在本系统中所能使用到的图片属性为颜色和大小,颜色对应不同的像素,大小对应图像的像素点形成矩阵的大小;前台:前台用来接收图片和显示图片;后台(JA V A):用来接收图片并且调用R来实现对图片的处理;后台(R):在被调用后,把图片信息转化成数据信息形成矩阵,从而实现对图片信息的处理。

经过上述的处理后,把新生成的图像信息返回,并在前端进行显示,从而实现图像分割。

把图像分割系统划分成二个子系统:接收图片并显示子系统,处理图片子系统。

首先从外界得到需要进行分割的图片,通过接收图片并显示子系统把图片进行输入到系统中;然后再把图片输入到处理图片子系统,输入此系统后,把图片信息转化为矩阵,然后利用JA V A调用R,利用R中K-MEANS算法对矩阵信息进行分类获得新的矩阵,最终把矩阵信息转化成图片,实现对图片的处理;最后把处理后得到的新图片输入到显示图片子系统,从而实现图像分割,获得所需要的信息。

详细设计程序流程图:实现代码;一.实现图片文件选择器:package pri.study.convert;import java.awt.EventQueue;import javax.swing.ImageIcon;import javax.swing.JFileChooser;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import java.awt.BorderLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.File;import javax.swing.JButton;import org.rosuda.REngine.REXPMismatchException;import org.rosuda.REngine.Rserve.RserveException;public class MyApp implements ActionListener {private JFrame frame;JButton selectPrePic = new JButton("选择要转换的图片");JLabel prePic = new JLabel("New label");JLabel label = new JLabel("转换前的图片:");JButton convertPic = new JButton("转换图片");JLabel label_1 = new JLabel("转换后的图片:");JLabel label_2 = new JLabel("提示:转换后的图片默认放在转换前图片所在目录下");JLabel curPic = new JLabel("转化浓厚的图片");JFileChooser jfc = new JFileChooser();// 文件选择器private int i=0;String prePicPath="";String curPicPath="";/*** Create the application.*/public MyApp() {initialize();}/*** Initialize the contents of the frame.*/private void initialize() {jfc.setCurrentDirectory(new File("d://"));// 文件选择器的初始目录定为d盘frame = new JFrame();frame.setBounds(200, 150, 880, 400);frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);JPanel myPanel=new JPanel();myPanel.setLayout(null);frame.getContentPane().add(myPanel, BorderLayout.CENTER);selectPrePic.addActionListener(this);selectPrePic.setBounds(10, 10, 153, 23);convertPic.addActionListener(this);convertPic.setBounds(423, 9, 93, 23);prePic.setBounds(20, 90, 320, 250);curPic.setBounds(423, 90, 320, 250);label.setBounds(20, 42, 139, 15);label_1.setBounds(423, 42, 143, 15);label_2.setBounds(423, 65, 320, 15);myPanel.add(prePic);myPanel.add(label);myPanel.add(convertPic);myPanel.add(label_1);myPanel.add(label_2);myPanel.add(curPic);myPanel.add(selectPrePic);// ImageIcon ico=new ImageIcon("d:/myPlotPic.png");// JLabel lblPrepic = new JLabel("hebe",ico,JLabel.CENTER);// frame.getContentPane().add(lblPrepic, BorderLayout.CENTER);}public void actionPerformed(ActionEvent e) {// TODO Auto-generated method stub// if (e.getSource().equals(button1)) {// 判断触发方法的按钮是哪个// jfc.setFileSelectionMode(1);// 设定只能选择到文件夹// int state = jfc.showOpenDialog(null);// 此句是打开文件选择器界面的触发语句// if (state == 1) {// return;// } else {// File f = jfc.getSelectedFile();// f为选择到的目录// text1.setText(f.getAbsolutePath());// }// }// 绑定到选择文件,先择文件事件if (e.getSource().equals(selectPrePic)) {jfc.setFileSelectionMode(0);// 设定只能选择到文件int state = jfc.showOpenDialog(null);// 此句是打开文件选择器界面的触发语句if (state == 1) {return;// 撤销则返回} else {File f = jfc.getSelectedFile();// f为选择到的文件//System.out.print(f.getPath());//trim()是取出字符串前后的空格和特殊字符String temp01=f.getAbsolutePath().trim();String sub1=temp01.substring(0,3);String sub2=temp01.substring(2, temp01.length());prePicPath=sub1+sub2;System.out.print(prePicPath);String temp02=f.getParent();String sub01=temp01.substring(0,3);String sub02=temp01.substring(2, temp02.length());//curPicPath=sub01+sub02+"\\"+"convert0"+i+++".jpg";curPicPath=sub01+sub02+"convert0"+i+++".jpg";System.out.print("curPicPath--->"+curPicPath);//显示转换前的图片ImageIcon iconPrePic=new ImageIcon(f.getAbsolutePath());prePic.setIcon(iconPrePic);}}if (e.getSource().equals(convertPic)) {try {ConvertPicByRconve=ConvertPicByR.getInstance();conve.DoConvertPic(prePicPath, curPicPath);//显示转换后的图片ImageIcon iconPrePic=new ImageIcon(curPicPath);curPic.setIcon(iconPrePic);} catch (RserveException e1) {// TODO Auto-generated catch blocke1.printStackTrace();} catch (REXPMismatchException e1) {// TODO Auto-generated catch blocke1.printStackTrace();}// JOptionPane.showMessageDialog(null, "init a dialog for test!", "tips", 2); @author zzj}}/*** Launch the application.*/public static void main(String[] args) {EventQueue.invokeLater(new Runnable() {public void run() {try {MyApp window = new MyApp();window.frame.setVisible(true);} catch (Exception e) {e.printStackTrace();}}});}}二.实现JA V A调用R:package pri.study.convert;import java.awt.EventQueue;import javax.swing.ImageIcon;import javax.swing.JFileChooser;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import java.awt.BorderLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.File;import javax.swing.JButton;import org.rosuda.REngine.REXPMismatchException;import org.rosuda.REngine.Rserve.RserveException;public class MyApp implements ActionListener {private JFrame frame;JButton selectPrePic = new JButton("选择要转换的图片");JLabel prePic = new JLabel("New label");JLabel label = new JLabel("转换前的图片:");JButton convertPic = new JButton("转换图片");JLabel label_1 = new JLabel("转换后的图片:");JLabel label_2 = new JLabel("提示:转换后的图片默认放在转换前图片所在目录下");JLabel curPic = new JLabel("转化浓厚的图片");JFileChooser jfc = new JFileChooser();// 文件选择器private int i=0;String prePicPath="";String curPicPath="";/*** Create the application.*/public MyApp() {initialize();}/*** Initialize the contents of the frame.*/private void initialize() {jfc.setCurrentDirectory(new File("d://"));// 文件选择器的初始目录定为d盘frame = new JFrame();frame.setBounds(200, 150, 880, 400);frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);JPanel myPanel=new JPanel();myPanel.setLayout(null);frame.getContentPane().add(myPanel, BorderLayout.CENTER);selectPrePic.addActionListener(this);selectPrePic.setBounds(10, 10, 153, 23);convertPic.addActionListener(this);convertPic.setBounds(423, 9, 93, 23);prePic.setBounds(20, 90, 320, 250);curPic.setBounds(423, 90, 320, 250);label.setBounds(20, 42, 139, 15);label_1.setBounds(423, 42, 143, 15);label_2.setBounds(423, 65, 320, 15);myPanel.add(prePic);myPanel.add(label);myPanel.add(convertPic);myPanel.add(label_1);myPanel.add(label_2);myPanel.add(curPic);myPanel.add(selectPrePic);// ImageIcon ico=new ImageIcon("d:/myPlotPic.png");// JLabel lblPrepic = new JLabel("hebe",ico,JLabel.CENTER);// frame.getContentPane().add(lblPrepic, BorderLayout.CENTER);}public void actionPerformed(ActionEvent e) {// TODO Auto-generated method stub// if (e.getSource().equals(button1)) {// 判断触发方法的按钮是哪个// jfc.setFileSelectionMode(1);// 设定只能选择到文件夹// int state = jfc.showOpenDialog(null);// 此句是打开文件选择器界面的触发语句// if (state == 1) {// return;// } else {// File f = jfc.getSelectedFile();// f为选择到的目录// text1.setText(f.getAbsolutePath());// }// }// 绑定到选择文件,先择文件事件if (e.getSource().equals(selectPrePic)) {jfc.setFileSelectionMode(0);// 设定只能选择到文件int state = jfc.showOpenDialog(null);// 此句是打开文件选择器界面的触发语句if (state == 1) {return;// 撤销则返回} else {File f = jfc.getSelectedFile();// f为选择到的文件//System.out.print(f.getPath());//trim()是取出字符串前后的空格和特殊字符String temp01=f.getAbsolutePath().trim();String sub1=temp01.substring(0,3);String sub2=temp01.substring(2, temp01.length());prePicPath=sub1+sub2;System.out.print(prePicPath);String temp02=f.getParent();String sub01=temp01.substring(0,3);String sub02=temp01.substring(2, temp02.length());//curPicPath=sub01+sub02+"\\"+"convert0"+i+++".jpg";curPicPath=sub01+sub02+"convert0"+i+++".jpg";System.out.print("curPicPath--->"+curPicPath);//显示转换前的图片ImageIcon iconPrePic=new ImageIcon(f.getAbsolutePath());prePic.setIcon(iconPrePic);}}if (e.getSource().equals(convertPic)) {try {ConvertPicByRconve=ConvertPicByR.getInstance();conve.DoConvertPic(prePicPath, curPicPath);//显示转换后的图片ImageIcon iconPrePic=new ImageIcon(curPicPath);curPic.setIcon(iconPrePic);} catch (RserveException e1) {// TODO Auto-generated catch blocke1.printStackTrace();} catch (REXPMismatchException e1) {// TODO Auto-generated catch blocke1.printStackTrace();}// JOptionPane.showMessageDialog(null, "init a dialog for test!", "tips", 2); @author zzj}}/*** Launch the application.*/public static void main(String[] args) {EventQueue.invokeLater(new Runnable() {public void run() {try {MyApp window = new MyApp();window.frame.setVisible(true);} catch (Exception e) {e.printStackTrace();}});}}三.在R中实现图像的处理:public static void DoConvertPic(String prePicPath,String curPicPath) throws RserveException{//R commandsc.eval("library(jpeg)");// Stringtemp="orgpic<-readJPEG(\""+prePicPath+"\")";// System.out.print(temp);c.eval("orgpic<-readJPEG(\""+prePicPath+"\")");c.eval("dim(orgpic)");// c.eval("orgpic[100,200,]");// c.eval("hist(orgpic[,,2])");// String temp="negative<-function(orgpic)";// System.out.print(temp);c.eval("negative<-function(orgpic){return(1-orgpic)}");// c.eval("{");// c.eval("return(1-orgpic)");// c.eval("}");c.eval("writeJPEG(negative(orgpic),target=\""+curPicPath+"\",quality=0.95)");c.eval("");}}摘要为了加强煤矿矿区环境保护,对矿区周边环境的水质监测数据进行有效处理,方便环境监测部门按照国家规范进行定期或不定期的经常性监测测定,建立健全污染源档案,为加强污染源管理提供监测数据,并根据监测数据做出环境质量评价。

相关主题