Andrid Image Processing System 1.3.0 histogram balancing of images

Source: Internet
Author: User

Image processing result:

 
Add the following code to ImageProcess. java:
[Java]
/*
* Histogram equalization
*/
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 transport Ray = gettransport Ray (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 ){
// Grayscale ing table
Int bMap [] = new int [256];
// Grayscale ing table
Int lCount [] = new int [256];
// Reset the count to 0
Int I, j;
For (I = 0; I <256; I ++ ){
// Clear
LCount [I] = 0;
}
// Calculate the Count of each grayscale value-reference the grayscale histogram drawing code (in the dialog box)
For (I = 0; I For (j = 0; j <width; j ++ ){
LCount [(int) temp. get (I, j)] ++; // count plus 1
}
}
// Calculate the grayscale ing table
For (I = 0; I <256; I ++ ){
// The initial value is 0.
Int Temp = 0;
For (j = 0; j <= I; j ++ ){
Temp + = lCount [j];
}
// Calculate the corresponding new gray value
BMap [I] = (int) (Temp * 255/height/width );
}
// Each line
For (I = 0; I // Each column
For (j = 0; j <width; j ++ ){
Temp. set (I, j, bMap [(int) temp. get (I, j)]);
}
}
Return temp;
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.