简单的图像处理系统v2

简单的图像处理系统v2 之一

2007 0523 星期三 下午 11:34

主程序如下:

package dege.imagetool;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import 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.LinkedList;

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.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 newImage;

//
图像的高和宽
private int h,w;

//
保存历史操作图像矩阵
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(JFrame.EXIT_ON_CLOSE);
  
   //
创建菜单
   JMenuBar jb=new JMenuBar();
   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(){
    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=new 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 BackActionListener());
  
   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();
   defaultFlowLayout.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);
  
   JButton 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 FrontActionListener());
   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 JLabel("");
   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);
   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.HORIZONTAL_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(ActionEvent 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=newImage.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.this.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){
    int[] 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{
     tempImageStack.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_MESSAGE);
    }else{
     currentPixArray=tempImageStack.removeFirst();
     imageStack.addLast(currentPixArray);
     showImage();
    }
   }
  
}


//
获取图像像素矩阵///
private int[]getPixArray(Image im,int w,int h){
      int[] pix=new int[w*h];
      PixelGrabber pg=null;
      try{
        pg = new PixelGrabber(im, 0, 0, w, h, pix, 0, w);
        if(pg.grabPixels()!=true)
          try{
            throw new 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 showImage(){
   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){
   int[]grayArray=new int[h*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;  
     r = colorModel.getRed(ImageSource[k]);
     g = colorModel.getGreen(ImageSource[k]);
     b = colorModel.getBlue(ImageSource[k]);
     int gray=(int)(r*0.3+g*0.59+b*0.11);
     r=g=b=gray;
     grayArray[i*w+j]=(255 << 24) | (r << 16) | (g << 8 )| b;
    }
   }
   return grayArray;
}


/
图像均衡化//
private int[] balance(int[] ImageSource){
     int[] histogram=new int[256];
     int[] dinPixArray=new int[w*h];
        
     for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
       int grey=ImageSource[i*w+j]&0xff;
       histogram[grey]++;
      }
     }
     double a=(double)255/(w*h);
     double[] c=new double[256];
     c[0]=(a*histogram[0]);
     for(int i=1;i<256;i++){
      c[i]=c[i-1]+(int)(a*histogram[i]);
     }
     for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
       int grey=ImageSource[i*w+j]&0x0000ff;
       int hist=(int)c[grey];
      
       dinPixArray[i*w+j]=255<<24|hist<<16|hist<<8|hist;
      }
     }
     return dinPixArray;
}




public int[] getCurrentPixArray() {
   return currentPixArray;
}

public void setCurrentPixArray(int[] currentPixArray) {
   this.currentPixArray = currentPixArray;
}

public int getH() {
   return h;
}

public int getW() {
   return w;
}

public static void main(String[] args) {
   new MyShowImage("ShowImage");
}

}

简单图像处理系统v2 之二

2007 0523 星期三 下午 11:36

右边功能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.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 ActionListener{
private 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(MyShowImage 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 button
   for(int i=0;i<categoryNum;i++){
    buttons[i]=new JButton(buttonString[i]);
    buttons[i].addActionListener(this);
    this.NorthPanel.add(buttons[i]);
   }
    
   //add the panel
   for(int i=0;i<categoryNum;i++){
    panel[i]=new JPanel();
    panel[i].setLayout(new BoxLayout(panel[i],BoxLayout.Y_AXIS));
   
   }
   this.scrollPane=new JScrollPane(panel[categoryNum-1]);
   this.add(scrollPane,BorderLayout.CENTER);
  
   for(int i=0;i<categoryNum;i++){
    if(buttonClassString[i]!=null){
     for(int j=0;j<buttonClassString[i].length;j++){
      try{
       JButton b=(JButton)this.getClass().getClassLoader().loadClass(buttonClassString[i][j]).newInstance();
       FuntionButtonInterface c=(FuntionButtonInterface)b;
       c.setParent(this.parent);
       c.doSetText();
      
       Box box=Box.createVerticalBox();
       box.add(b);
       box.add(new JLabel(c.getFuntionName()));   
      
       this.panel[i].add(box);
       this.panel[i].add(Box.createVerticalStrut(20));
      }catch(ClassNotFoundException cnfe){
       cnfe.printStackTrace();
      
      }catch(InstantiationException inse){
       inse.printStackTrace();
      
      }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();
   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 String[categoryNum];
   for(int i=1;i<=categoryNum;i++){
    buttonString[i-1]=prop.getProperty("category"+i);
   }
   butStr=prop.getProperty("category1_fun1");
   buttonClassString=new String[categoryNum][];
   for(int i=1;i<categoryNum;i++){
    String str=prop.getProperty("category"+i+"_funtionNum");
    if(str!=null){
     int funtionNum=Integer.parseInt(str);
     if(funtionNum!=0){
      buttonClassString[i-1]=new String[funtionNum];
      for(int j=1;j<=funtionNum;j++){
       buttonClassString[i-1][j-1]=prop.getProperty("category"+i+"_fun"+j);
      
      }
     }
    }
   
   }
   buttons=new JButton[categoryNum];
   panel=new JPanel[categoryNum];
}
public void actionPerformed (ActionEvent event) {
   JButton button=(JButton)event.getSource();
   String selectButton=button.getText();
  
   boolean flag=true;
   int i;
   for(i=0;i<categoryNum&&flag;i++){
    if(buttonString[i].equals(selectButton))
     flag=false;
   }
  
   this.NorthPanel.removeAll();
   this.northGL.setRows(i);
   for(int j=0;j<i;j++){
    this.NorthPanel.add(buttons[j]);
   }
   this.SouthPanel.removeAll();
   this.southGL.setRows(categoryNum-i);
   for(int k=i;k<categoryNum;k++){
    this.SouthPanel.add(buttons[k]);
   }
  
   this.remove(scrollPane);
   currentNum=i-1;
   this.scrollPane=new JScrollPane(panel[currentNum]);
   this.add(scrollPane,BorderLayout.CENTER);
   System.gc();  
   this.parent.setVisible(true);
  
}
}

左边直方图Panel的代码如下:

package dege.imagetool;

import java.awt.Color;
import java.awt.Graphics;

import javax.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 =new MyPanel(parent,0x0000ff00,8,Color.green);
   MyPanel blueHistPanel =new MyPanel(parent,0x000000ff,0,Color.blue);
  
   this.addTab("
红色直方图", redHistPanel);
   this.addTab("
绿色直方图", greenHistPanel);
   this.addTab("
蓝色直方图", blueHistPanel);
}

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.parent   =parent;
    this.bit   =bit;
    this.movebit =movebit;
    this.color   =color;
   }
  
   public void paint(Graphics g){
    g.drawLine(10, 200, 10, 0);
    g.drawLine(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("0", 10, 215);
   
    if(parent.getCurrentPixArray()!=null){
     int[] imageSource=parent.getCurrentPixArray();
     int[] pixCount=new int[256];
     int length=imageSource.length;
     for(int i=0;i<length;i++){
      pixCount[(imageSource[i]&bit)>>movebit]++;
     }
    
     float max= 0.0f ;
     float min= 1.0f ;
     float[] percent=new float[256];
     for(int i=0;i<256;i++){
      float temp=((float)pixCount[i])/length;
      percent[i]=temp;
      max=temp>max? temp:max;
      min=temp<min? temp:min;
     }
    
     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)(coefficient*percent[i]));
     }
    }
   }
}
}

简单图像处理系统v2 之三

2007 0523 星期三 下午 11:37

系统采用动态加载功能模块的方法,而且每一个新方法的加入以一个新的功能Button为基础

这样的功能类需要实现以下接口以及扩展JButton

接口如下:

package dege.imagetool;

import javax.swing.Action;
import javax.swing.ImageIcon;

public interface FuntionButtonInterface {
void setParent(MyShowImage parent);
void 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.JButton;

public class RGBtoGrayButton extends JButton 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 ImageIcon(this.getClass().getResource("RGBtoGray.jpg")));
}

public void doSetText() {
   // TODO
自动生成方法存根
   this.funtionName="
灰度图像";
   setToolTipText("
把图像转换为灰度图像");
}

public void setParent(MyShowImage parent) {
   // TODO
自动生成方法存根
   this.parent=parent;
}


public String getFuntionName(){
   return funtionName;
}

  
public class RGBtoGrayAction extends AbstractAction {

   public void actionPerformed(ActionEvent event) {
    // TODO
自动生成方法存根
    int[] ImageSource=parent.getCurrentPixArray();
    int h=parent.getH();
    int w=parent.getW();
    int[]grayArray=new int[h*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;  
      r = colorModel.getRed(ImageSource[k]);
      g = colorModel.getGreen(ImageSource[k]);
      b = colorModel.getBlue(ImageSource[k]);
      int gray=(int)(r*0.3+g*0.59+b*0.11);
      r=g=b=gray;
      grayArray[i*w+j]=(255 << 24) | (r << 16) | (g << 8 )| b;
     }
    }
    parent.setCurrentPixArray(grayArray);
    parent.updateImage(grayArray);
   }
  
}

}

第二个直方图均衡化:

package dege.imagetool;

import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.ImageIcon;
import javax.swing.JButton;

public class ZFUBalanceButton extends JButton implements FuntionButtonInterface {

private MyShowImage parent;
private String funtionName;

public ZFUBalanceButton(){
   this.doSetAction();
   this.doSetIcon();
}

public void doSetAction() {
   // TODO
自动生成方法存根
   super.setAction(new ZFUBalanceAction());
}

public void doSetIcon() {
   // TODO
自动生成方法存根
   super.setIcon(new ImageIcon(this.getClass().getResource("Balance.jpg")));
}

public void doSetText() {
   // TODO
自动生成方法存根
   this.funtionName="
直方图均衡化";
   super.setToolTipText("
对灰度图像进行直方图均衡化");
}

public void setParent(MyShowImage parent) {
   // TODO
自动生成方法存根
   this.parent=parent;
}

public String getFuntionName(){
   return funtionName;
}

public class ZFUBalanceAction extends AbstractAction {

   public void actionPerformed(ActionEvent event) {
    // TODO
自动生成方法存根
    int[] ImageSource=parent.getCurrentPixArray();
    int h=parent.getH();
    int w=parent.getW();
    int[] histogram=new int[256];
    int[] dinPixArray=new int[w*h];
          
    for(int i=0;i<h;i++){
     for(int j=0;j<w;j++){
       int grey=ImageSource[i*w+j]&0xff;
       histogram[grey]++;
      }
    }
    double a=(double)255/(w*h);
    double[] c=new double[256];
    c[0]=(a*histogram[0]);
    for(int i=1;i<256;i++){
     c[i]=c[i-1]+(int)(a*histogram[i]);
    }
    for(int i=0;i<h;i++){
     for(int j=0;j<w;j++){
      int grey=ImageSource[i*w+j]&0x0000ff;
      int hist=(int)c[grey];
      dinPixArray[i*w+j]=255<<24|hist<<16|hist<<8|hist;
     }
    }
   
    parent.setCurrentPixArray(dinPixArray);
    parent.updateImage(dinPixArray);
   
   }
  
}

}

简单图像处理系统v2 之四

2007 0523 星期三 下午 11:39

第三个 Roberts边缘检测

package dege.imagetool;

import java.awt.event.ActionEvent;
import java.awt.image.ColorModel;

import javax.swing.AbstractAction;
import javax.swing.ImageIcon;
import javax.swing.JButton;

public class RobertsButton extends JButton implements FuntionButtonInterface {

private MyShowImage parent;
private String funtionName;

public RobertsButton(){
   this.doSetAction();
   this.doSetIcon();
}

public void doSetAction() {
   // TODO
自动生成方法存根
   super.setAction(new RobertsAction());
}

public void doSetIcon() {
   // TODO
自动生成方法存根
   super.setIcon(new ImageIcon(this.getClass().getResource("Balance.jpg")));
}

public void doSetText() {
   // TODO
自动生成方法存根
   this.funtionName="Roberts
边缘检测";
   super.setToolTipText("
对图像进行边缘检测");
}

public void setParent(MyShowImage parent) {
   // TODO
自动生成方法存根
   this.parent=parent;
}

public String getFuntionName(){
   return funtionName;
}

public class RobertsAction extends AbstractAction {

   public void actionPerformed(ActionEvent event) {
    // TODO
自动生成方法存根
    int[] ImageSource=parent.getCurrentPixArray();
    int h=parent.getH();
    int w=parent.getW();
    int[] dinPixArray=new int[w*h];
    ColorModel colorModel=ColorModel.getRGBdefault();
    for(int i=1;i<h-1;i++){
     for(int j=1;j<w-1;j++){
     
      int red5=colorModel.getRed(ImageSource[i*w+j]);
      int red6=colorModel.getRed(ImageSource[i*w+j+1]);
      int red8=colorModel.getRed(ImageSource[(i+1)*w+j]);
      int red9=colorModel.getRed(ImageSource[(i+1)*w+j+1]);
      int robertRed=Math.max(Math.abs(red5-red9), Math.abs(red8-red6));
     
      int green5=colorModel.getGreen(ImageSource[i*w+j]);
      int green6=colorModel.getGreen(ImageSource[i*w+j+1]);
      int green8=colorModel.getGreen(ImageSource[(i+1)*w+j]);
      int green9=colorModel.getGreen(ImageSource[(i+1)*w+j+1]);
      int robertGreen=Math.max(Math.abs(green5-green9), Math.abs(green8-green6));
     
      int blue5=colorModel.getBlue(ImageSource[i*w+j]);
      int blue6=colorModel.getBlue(ImageSource[i*w+j+1]);
      int blue8=colorModel.getBlue(ImageSource[(i+1)*w+j]);
      int blue9=colorModel.getBlue(ImageSource[(i+1)*w+j+1]);
      int robertBlue=Math.max(Math.abs(blue5-blue9), Math.abs(blue8-blue6));
     
      dinPixArray[i*w+j]=255<<24|robertRed<<16|robertGreen<<8|robertBlue;
     }
    }
   
    parent.setCurrentPixArray(dinPixArray);
    parent.updateImage(dinPixArray);
   }
  
}

}

简单图像处理系统v2 之五

2007 0523 星期三 下午 11:39

动态加载采用了读取xml配置文件的形式

现有配置文件如下:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
   <entry key="categoryNum">6</entry>
  
   <entry key="category1">
灰度变换</entry>
   <entry key="category1_funtionNum">1</entry>
   <entry key="category1_fun1">dege.imagetool.RGBtoGrayButton</entry>
  
   <entry key="category2">
均衡化</entry>
   <entry key="category2_funtionNum">1</entry>
   <entry key="category2_fun1">dege.imagetool.ZFUBalanceButton</entry>
   
   <entry key="category3">
锐化与边缘检测</entry>
   <entry key="category3_funtionNum">1</entry>
   <entry key="category3_fun1">dege.imagetool.RobertsButton</entry>
  
   <entry key="category4">
图像分割</entry>
  
   <entry key="category5">
形态学</entry>
  
   <entry key="category6">
频域变换</entry>
</properties>

最后系统还加入了如下的按钮图片,需要和class文件放在一起:

 

 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值