⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 newjframe.java

📁 Image boundayry detection
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        // TODO add your handling code here:                int x,y;                   ii1= gs.filter(ax,ii.getImage());        img=gs1.filter1(ax1, ii.getImage());        jj=new ImageIcon();        jj.setImage(img);                x=jj.getIconHeight();        y=jj.getIconWidth();        jLabel2.setIcon(jj);        jLabel2.setVisible(true);        jLabel4.setVisible(false);        jLabel5.setVisible(false);            }//GEN-LAST:event_jButton2ActionPerformed    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed        // TODO add your handling code here:                int knm=0;                try{            iw=img.getWidth(null);            ih=img.getHeight(null);            hw=new int[ih][iw];            pixels=new int[iw*ih];            pixels2=new int[iw*ih];            PixelGrabber pg=new PixelGrabber(ii1,0,0,iw,ih,pixels,0,iw);            pg.grabPixels();                        iw1=img1.getWidth(null);            ih1=img1.getHeight(null);            hw1=new int[ih1][iw1];            pixels1=new int[iw1*ih1];            PixelGrabber pg1=new PixelGrabber(ii2,0,0,iw1,ih1,pixels1,0,iw1);            pg1.grabPixels();            PixelGrabber pg2=new PixelGrabber(img,0,0,iw,ih,pixels2,0,iw);            pg2.grabPixels();            for(int i=0;i<ih;i++)               { for(int j=0;j<iw;j++)                    {                     hw[i][j]=pixels[knm];knm++;                    }                }            knm=0;            for(int i=0;i<ih1;i++)               { for(int j=0;j<iw1;j++)                    {                     hw1[i][j]=pixels1[knm];knm++;                    }                }            }            catch(Exception e){}            System.out.println(iw+ " "+ih);            System.out.println(iw1+ " "+ih1);                            }//GEN-LAST:event_jButton3ActionPerformed    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed        // TODO add your handling code here:        jFrame3.setVisible(true);                jFrame3.setSize(525,500);            }//GEN-LAST:event_jButton4ActionPerformed    private void jFileChooser2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jFileChooser2ActionPerformed        // TODO add your handling code here:        s1=(jFileChooser2.getSelectedFile()).toString();        ki=new ImageIcon(s1);        jLabel4.setIcon(ki);        ii2= gs.filter(ax,ki.getImage());        img1=gs1.filter1(ax1,ki.getImage());        kj=new ImageIcon();        kj.setImage(img1);        jLabel5.setIcon(kj);        jLabel4.setVisible(true);        jLabel1.setVisible(true);        jLabel2.setVisible(true);        jLabel5.setVisible(true);        jFrame3.setVisible(false);    }//GEN-LAST:event_jFileChooser2ActionPerformed    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed        // TODO add your handling code here:        int w=0,x=0;        sam=new int[ih][iw];        same=new int[iw*ih];        dif=new int[iw*ih];        for(int i=0;i<ih;i++)        {            for(int j=0;j<iw;j++)            {                if(hw[i][j]<=hw1[i][j]+25 && hw[i][j]>=hw1[i][j]-25)                {                    sam[i][j]=hw[i][j];                    same[x++]=hw[i][j];                    dif[w++]=-16777216;                }                else                {                    same[x++]=0;                    sam[i][j]=0;                    dif[w]=hw[i][j];                    w++;                }            }                    }          x=0;        for(int i=0;i<ih;i++)        {            for(int j=0;j<iw-2;j++)         {            if(sam[i][j]!=0 && sam[i][j+1]==0 && sam[i][j+2]==0)            sam[i][j]=-16777216;                     }        }          for(int i=ih-1;i>0;i--)        {            for(int j=iw-1;j>2;j--)         {            if(sam[i][j]!=0 && sam[i][j-1]==0 && sam[i][j-2]==0)            sam[i][j]=-16777216;                     }        }          for(int i=0;i<ih-2;i++)        {            for(int j=0;j<iw;j++)         {            if(sam[i][j]!=0 && sam[i+1][j]==0 && sam[i+2][j]==0)            sam[i][j]=-16777216;                     }        }          for(int i=ih-1;i>2;i--)        {            for(int j=iw-1;j>0;j--)         {            if(sam[i][j]!=0 && sam[i-1][j]==0 && sam[i-2][j]==0)            sam[i][j]=-16777216;                     }        }          for(int i=0;i<ih;i++)        {            for(int j=0;j<iw;j++)         {           same[x++]=sam[i][j];                                 }          }          for(int i=0;i<same.length;i++)          {              if(same[i]!=-16777216)                  same[i]=pixels2[i];              else                  same[i]=0;          }int f=0,f1=0;          id=new int[iw*ih];            for(int i=0;i<ih;i++)        {            for(int j=0;j<iw;j++)            {                  if(hw[i][j]!=0)                       {                    hw[i][j]=-86777216;                }            }            }                for(int i=0;i<ih;i++)        {            for(int j=0;j<iw;j++)            {if(hw[i][j]==sam[i][j])             {                 id[f++]=hw[i][j];//hw[i][j];             f1++;}             else                 f1++;                                             }}          for(int i=0;i<f;i++)          {              System.out.print(id[i]+" ");          }                       // System.out.println(same.length+" "+pixels2.length+" "+same[102]+" "+same[103]);        obj=createImage(new MemoryImageSource(ih,iw,same,0,iw));        ImageIcon obj1=new ImageIcon();        obj1.setImage(obj);        jLabel6.setIcon(obj1);        jLabel6.setVisible(true);        jFrame4.setVisible(true);        jFrame4.setSize(ih+250, iw+75);    }//GEN-LAST:event_jButton5ActionPerformed        /**     * @param args the command line arguments     */    public static void main(String args[]) {        java.awt.EventQueue.invokeLater(new Runnable() {            public void run() {                new NewJFrame().setVisible(true);            }        });    }        // Variables declaration - do not modify//GEN-BEGIN:variables    private javax.swing.JButton jButton1;    private javax.swing.JButton jButton2;    private javax.swing.JButton jButton3;    private javax.swing.JButton jButton4;    private javax.swing.JButton jButton5;    private javax.swing.JFileChooser jFileChooser1;    private javax.swing.JFileChooser jFileChooser2;    private javax.swing.JFrame jFrame1;    private javax.swing.JFrame jFrame2;    private javax.swing.JFrame jFrame3;    private javax.swing.JFrame jFrame4;    private javax.swing.JLabel jLabel1;    private javax.swing.JLabel jLabel2;    private javax.swing.JLabel jLabel3;    private javax.swing.JLabel jLabel4;    private javax.swing.JLabel jLabel5;    private javax.swing.JLabel jLabel6;    // End of variables declaration//GEN-END:variables    }interface PlugInFilter {java.awt.Image filter(java.applet.Applet a, java.awt.Image img);}class Grayscale extends RGBImageFilter implements PlugInFilter {        public Image filter(Applet a, Image img) {    return a.createImage(new FilteredImageSource(img.getSource(),this));}public int filterRGB(int x, int y, int rgb) {    int r = (rgb >> 16) & 0xff;int g = (rgb >> 8) & 0xff;int b = rgb & 0xff;int k = (int) (.56 * g + .33 * r + .11 * b);return (/*0xff000000 | k << 16 | k << 8 |*/ k);}}interface PlugInFilter1 {java.awt.Image filter1(java.applet.Applet a, java.awt.Image img);}class Grayscale1 extends RGBImageFilter implements PlugInFilter1 {        public Image filter1(Applet a, Image img) {    return a.createImage(new FilteredImageSource(img.getSource(),this));}public int filterRGB(int x, int y, int rgb) {    int r = (rgb >> 16) & 0xff;int g = (rgb >> 8) & 0xff;int b = rgb & 0xff;int k = (int) (.56 * g + .33 * r + .11 * b);return (0xff000000 | k << 16 | k << 8 | k);}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -