android影像處理系統1.3

來源:互聯網
上載者:User

                                                                   android影像處理系統1.3

項目成品:手相評分:http://as.baidu.com/a/item?docid=2758385
該版本由很大的更新。在處理映像的方式上,我引入了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;}

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.