频道直达 - 专题 - 新闻 - 技巧 - 组网 - 开发 - 安全 - web编程 - 图像 - 操作系统 - 数据库 - 教育 - 旅游 - 健康 - 时尚 - 驱动 - 软件 - 游戏 - 多媒体 - ERP - 讨论组

java数字图像处理常用算法

来源: 作者: 出处:巧巧读书 2007-07-09 进入讨论组
下一页 1 2 3 4 
     前些时候做毕业设计,用java做的数字图像处理方面的东西,这方面的资料ms比较少,发点东西上来大家共享一下,主要就是些算法,有自己写的,有人家的,还有改人家的,有的算法写的不好,大家不要见笑。

一 读取bmp图片数据

//  获取待检测图像 ,数据保存在数组 nData[],nB[] ,nG[] ,nR[]中

 public  void getBMPImage(String source) throws Exception {
          
         clearNData();                        //清除数据保存区
         FileInputStream fs = null;
       
        try {
            fs = new FileInputStream(source);
            int bfLen = 14;
            byte bf[] = new byte[bfLen];
            fs.read(bf, 0, bfLen); // 读取14字节BMP文件头
            int biLen = 40;
            byte bi[] = new byte[biLen];
            fs.read(bi, 0, biLen); // 读取40字节BMP信息头

            // 源图宽度
            nWidth = (((int) bi[7] & 0xff) << 24)
                    | (((int) bi[6] & 0xff) << 16)
                    | (((int) bi[5] & 0xff) << 8) | (int) bi[4] & 0xff;

            // 源图高度
            nHeight = (((int) bi[11] & 0xff) << 24)
                    | (((int) bi[10] & 0xff) << 16)
                    | (((int) bi[9] & 0xff) << 8) | (int) bi[8] & 0xff;

            // 位数
            nBitCount = (((int) bi[15] & 0xff) << 8) | (int) bi[14] & 0xff;

            // 源图大小
            int nSizeImage = (((int) bi[23] & 0xff) << 24)
                    | (((int) bi[22] & 0xff) << 16)
                    | (((int) bi[21] & 0xff) << 8) | (int) bi[20] & 0xff;

            // 对24位BMP进行解析
            if (nBitCount == 24){
                int nPad = (nSizeImage / nHeight) - nWidth * 3;
                nData = new int[nHeight * nWidth];
                nB=new int[nHeight * nWidth];
                nR=new int[nHeight * nWidth];
                nG=new int[nHeight * nWidth];
                byte bRGB[] = new byte[(nWidth + nPad) * 3 * nHeight];
                fs.read(bRGB, 0, (nWidth + nPad) * 3 * nHeight);
                int nIndex = 0;
                for (int j = 0; j < nHeight; j++){
                    for (int i = 0; i < nWidth; i++) {
                        nData[nWidth * (nHeight - j - 1) + i] = (255 & 0xff) << 24
                                | (((int) bRGB[nIndex + 2] & 0xff) << 16)
                                 | (((int) bRGB[nIndex + 1] & 0xff) << 8)
                                | (int) bRGB[nIndex] & 0xff;                     
                        nB[nWidth * (nHeight - j - 1) + i]=(int) bRGB[nIndex]& 0xff;
                        nG[nWidth * (nHeight - j - 1) + i]=(int) bRGB[nIndex+1]& 0xff;
                        nR[nWidth * (nHeight - j - 1) + i]=(int) bRGB[nIndex+2]& 0xff;
                        nIndex += 3;
                    }
                    nIndex += nPad;
                }
 //               Toolkit kit = Toolkit.getDefaultToolkit();
 //               image = kit.createImage(new MemoryImageSource(nWidth, nHeight,
 //                       nData, 0, nWidth));

/*              
//调试数据的读取

                FileWriter fw = new FileWriter("C:\\Documents and Settings\\Administrator\\My Documents\\nDataRaw.txt");//创建新文件
                PrintWriter out = new PrintWriter(fw);
                for(int j=0;j<nHeight;j++){
                 for(int i=0;i<nWidth;i++){
                  out.print((65536*256+nData[nWidth * (nHeight - j - 1) + i])+"_"
                    +nR[nWidth * (nHeight - j - 1) + i]+"_"
                    +nG[nWidth * (nHeight - j - 1) + i]+"_"
                    +nB[nWidth * (nHeight - j - 1) + i]+" ");
                  
                 }
                 out.println("");
                }
                out.close();
*/         
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            throw new Exception(e);
        }
        finally {
            if (fs != null) {
                fs.close();
            }
        }
     //   return image;
    } 

 

本文:http://www.qqread.com/java/2007/07/c320731.html 更多文章 更多内容请看Java环境安装配置数据库处理专题Java编程开发手册专题,或进入讨论组讨论。
下一页 1 2 3 4 
收藏此文】【 】【打印】【关闭
相关图文阅读
频道图文推荐
健 康 咨 询
时 尚 咨 询
巧巧读书宗旨
相关专题
讨论组问题推荐
站内各频道最新更新文档
站内最新制作专题
热门关键字导读
Photoshop教 程照片处理 照片制作 PS快捷键 抠图
计 算 机 故 障XP系统修复
艺 术 与 设 计设计 流媒体 设计欣赏 边框
计 算 机 安 全ARP
站内频道文章精选
巧巧电脑频道编辑信箱  告诉我们您想看的专题或文章