andrid影像處理系統1.3.0映像的長條圖均衡

來源:互聯網
上載者:User

影像處理結果:

 
在ImageProcess.java中添加如下代碼:
[java]
/*
     *長條圖均衡化 
     */ 
    public Bitmap histEqualize(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=eachEqualize(dataR,width,height); 
        dataG=eachEqualize(dataG,width,height); 
        dataB=eachEqualize(dataB,width,height); 
        /////////////////////////////////////////////////////////////// 
        // Change bitmap to use new array 
        Bitmap bitmap=makeToBitmap(dataR, dataG, dataB, width, height);  
        myBitmap = null; 
        pix = null; 
        return bitmap; 
    } 
    private Matrix eachEqualize(Matrix temp,int width,int height){ 
        // 灰階映射表 
        int bMap[]=new int[256]; 
        // 灰階映射表 
        int lCount[]=new int[256]; 
        // 重設計數為0 
        int i,j; 
        for (i = 0; i < 256; i ++){ 
            // 清零 
            lCount[i] = 0; 
        } 
        // 計算各個灰階值的計數 - 參考灰階長條圖的繪製代碼 (對話方塊類中) 
        for (i = 0; i < height; i ++){ 
            for (j = 0; j < width; j ++){ 
                    lCount[(int)temp.get(i, j)]++;  // 計數加1 
            } 
        } 
        // 計算灰階映射表 
        for (i = 0; i < 256; i++){ 
            // 初始為0 
            int Temp = 0; 
            for (j = 0; j <= i ; j++){ 
                Temp += lCount[j]; 
            } 
            // 計算對應的新灰階值 
            bMap[i] = (int) (Temp * 255 / height / width); 
        } 
        // 每行 
        for (i = 0; i < height; i++){ 
            // 每列 
            for (j = 0; j < width; j++){ 
                    temp.set(i, j, bMap[(int)temp.get(i,j)]); 
            } 
        } 
        return temp;  
    } 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.