android图像处理系统1.3

最终版源代码:https://github.com/nuptboyzhb/AndroidImageProSystem
该版本由很大的更新。在处理图像的方式上,我引入了java中的矩阵类(Matrix)。该类由
http://math.nist.gov/javanumerics/jama/提供。实现了矩阵的加、减、乘、转置、矩阵的逆、范数、行列式等算法,并有多种构造函数和获得矩阵数据的方法。在图像处理系统1.3中,我们将图像的RGB数据保存为矩阵(Matrix),为后续的算法扩充打下了坚实的基础。我们在ImageProcess.java中引入包import Jama.Matrix;为了封装图像处理的过程,我们将获取RGB的模块分别封装成3个成员函数,将生成bitmap图像封装成函数makeToBitmap。并实现了图像翻转90度的算法。

@author:郑海波 2012-08-29 转载请声明:http://blog.csdn.net/nuptboyzhb/article/details/7925994

相关博客:http://blog.csdn.net/nuptboyzhb/article/details/7857366

http://blog.csdn.net/nuptboyzhb/article/details/7852999

[运行界面及效果]


获取RGB及灰度的代码:
[java]

private Matrix getDataR(int[] pix,int width,int height){    Matrix dataR=new Matrix(width,height,0.0);    // Apply pixel-by-pixel change    int index = 0;    for (int y = 0; y < height; y++)    {    for (int x = 0; x < width; x++)    {    int r = ((pix[index] >> 16) & 0xff);      dataR.set(x, y, r);    index++;    } // x    } // y    return dataR;}private Matrix getDataG(int[] pix,int width,int height){    Matrix dataG=new Matrix(width,height,0.0);    // Apply pixel-by-pixel change    int index = 0;    for (int y = 0; y < height; y++)    {    for (int x = 0; x < width; x++)    {    int g = ((pix[index] >> 8) & 0xff);      dataG.set(x, y, g);    index++;    } // x    } // y    return dataG;}private Matrix getDataB(int[] pix,int width,int height){    Matrix dataB=new Matrix(width,height,0.0);    // Apply pixel-by-pixel change    int index = 0;    for (int y = 0; y < height; y++)    {    for (int x = 0; x < width; x++)    {    int b =(pix[index] & 0xff);      dataB.set(x, y, b);    index++;    } // x    } // y    return dataB;}private Matrix getDataGray(int[] pix,int width,int height){    Matrix dataGray=new Matrix(width,height,0.0);    // Apply pixel-by-pixel change    int index = 0;    for (int y = 0; y < height; y++)    {    for (int x = 0; x < width; x++)    {    int r = ((pix[index] >> 16) & 0xff);    int g = ((pix[index] >> 8) & 0xff);    int b = (pix[index] & 0xff);    int gray=(int)(0.3*r+0.59*g+0.11*b);      dataGray.set(x, y, gray);      index++;    } // x    } // y    return dataGray;}



旋转90度的函数代码:
[java]

public Bitmap rotate90(Bitmap myBitmap) {// Create new array    int width = myBitmap.getWidth();    int height = myBitmap.getHeight();    int[] pix = new int[width * height];    myBitmap.getPixels(pix, 0, width, 0, 0, width, height);    Matrix dataR=getDataR(pix, width, height);    Matrix dataG=getDataG(pix, width, height);    Matrix dataB=getDataB(pix, width, height);    //Matrix dataGray=getDataGray(pix, width, height);    /////////////////////////////////////////////////////////    dataR=dataR.transpose();    dataG=dataG.transpose();    dataB=dataB.transpose();    ///////////////////////////////////////////////////////////////    // Change bitmap to use new array    Bitmap bitmap=makeToBitmap(dataR, dataG, dataB, width, height);    myBitmap = null;    pix = null;    return bitmap;}



封装makeToBitmap代码:
[java代码]

public Bitmap rotate90(Bitmap myBitmap) {// Create new array    int width = myBitmap.getWidth();    int height = myBitmap.getHeight();    int[] pix = new int[width * height];    myBitmap.getPixels(pix, 0, width, 0, 0, width, height);    Matrix dataR=getDataR(pix, width, height);    Matrix dataG=getDataG(pix, width, height);    Matrix dataB=getDataB(pix, width, height);    //Matrix dataGray=getDataGray(pix, width, height);    /////////////////////////////////////////////////////////    dataR=dataR.transpose();    dataG=dataG.transpose();    dataB=dataB.transpose();    ///////////////////////////////////////////////////////////////    // Change bitmap to use new array    Bitmap bitmap=makeToBitmap(dataR, dataG, dataB, width, height);    myBitmap = null;    pix = null;    return bitmap;}



更多相关文章

  1. 箭头函数的基础使用
  2. Python技巧匿名函数、回调函数和高阶函数
  3. Native Activity讲解
  4. android 包管理系统分析
  5. Android下打印调用栈
  6. Java工程中调用Android库出现“Stub!”错误
  7. Android(安卓)封装json数据
  8. android中的状态保存
  9. Android(安卓)Camera 使用小结

随机推荐

  1. Android(安卓)内存修改
  2. ADB常用操作
  3. Android最流行的网络框架
  4. java线程相关面试题(第一版)
  5. Android(安卓)RoboGuice 使用指南(4):Lin
  6. android录音MP3格式文件
  7. Android(安卓)View ViewGroup 的measure
  8. c语言数据类型(初学)
  9. Android新特性之CardView的简单使用
  10. 阿里面试官:什么是MySQL索引,为什么要有索