当前位置:文档之家› JAVA图像处理分段线性拉伸

JAVA图像处理分段线性拉伸

import com.sun.media.jai.widget.DisplayJAI;import java.awt.GridLayout;import javax.media.jai.JAI;import javax.media.jai.PlanarImage;import javax.swing.BorderFactory;import javax.swing.JScrollPane;import javax.swing.border.TitledBorder;/** PieceWise.java* 版权所有- 贺向前* 邮件:hexiangqian@* QQ: 910019784* 未经授权,不得复制、传播。

*//**** @author Administrator*/public class PieceWise extends javax.swing.JFrame {/** Creates new form PieceWise */public PieceWise() {initComponents();setTitle("分段线性拉伸");setLayout(new GridLayout(2,2));}private PlanarImage loadImage(String fileName){PlanarImage im=JAI.create("fileload",fileName);return im;}private void showImage(PlanarImage im,String str){DisplayJAI dj=new DisplayJAI(im);JScrollPane jp=new JScrollPane(dj);TitledBorder titledBorder=BorderFactory.createTitledBorder(str);jp.setBorder(titledBorder);add(jp);}/** This method is called from within the constructor to* initialize the form.* WARNING: Do NOT modify this code. The content of this method is* always regenerated by the Form Editor.*/@SuppressWarnings("unchecked")// <editor-fold defaultstate="collapsed" desc="Generated Code">private void initComponents() {setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);addMouseListener(new java.awt.event.MouseAdapter() {public void mouseClicked(java.awt.event.MouseEvent evt) {formMouseClicked(evt);}});javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());getContentPane().setLayout(layout);layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 400, Short.MAX_V ALUE));layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 300, Short.MAX_V ALUE));pack();}// </editor-fold>private void formMouseClicked(java.awt.event.MouseEvent evt) {// TODO add your handling code here:String fileName1="src1.jpg";String fileName2="src2.jpg";PlanarImage im01=loadImage(fileName1);PlanarImage im02=loadImage(fileName2);showImage(im01,"Source1");showImage(im02,"Source2");int bands1=im01.getNumBands();int bands2=im02.getNumBands();float[][][] bp1 = new float[bands1][2][];for(int b = 0; b < bands1; b++) {bp1[b][0] = new float[]{0.0F, 100.0F, 205.0F,255.0F};bp1[b][1] = new float[]{0.0F, 10.0F, 245.0F,255.0F};}float[][][] bp2 = new float[bands1][2][];for(int b = 0; b < bands1; b++) {bp2[b][0] = new float[]{0.0F, 10.0F, 245.0F,255.0F};bp2[b][1] = new float[]{0.0F, 100.0F, 205.0F,255.0F};}// Create the Piecewise operation.PlanarImage im11 = JAI.create("piecewise", im01, bp1);PlanarImage im12=JAI.create("piecewise",im02,bp2);showImage(im11,"PiecewiseImage1");showImage(im12,"PieceWiseImage2");pack();show();}/*** @param args the command line arguments*/public static void main(String args[]) {/* Set the Nimbus look and feel *///<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.* For details see /javase/tutorial/uiswing/lookandfeel/plaf.html*/try {for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {if ("Nimbus".equals(info.getName())) {javax.swing.UIManager.setLookAndFeel(info.getClassName());break;}}} catch (ClassNotFoundException ex) {java.util.logging.Logger.getLogger(PieceWise.class.getName()).log(java.util.logging.Level.SEVE RE, null, ex);} catch (InstantiationException ex) {java.util.logging.Logger.getLogger(PieceWise.class.getName()).log(java.util.logging.Level.SEVE RE, null, ex);} catch (IllegalAccessException ex) {java.util.logging.Logger.getLogger(PieceWise.class.getName()).log(java.util.logging.Level.SEVE RE, null, ex);} catch (javax.swing.UnsupportedLookAndFeelException ex) {java.util.logging.Logger.getLogger(PieceWise.class.getName()).log(java.util.logging.Level.SEVE RE, null, ex);}//</editor-fold>/* Create and display the form */java.awt.EventQueue.invokeLater(new Runnable() {public void run() {new PieceWise().setVisible(true);}});}// Variables declaration - do not modify// End of variables declaration}。

相关主题