Android image processing system 1.4 image sharpening-Edge Detection

Source: Internet
Author: User

Android image processing system 1.4 image sharpening-Edge Detection
Image sharpening-Edge Detection: (Robert Gradient, Sobel Gradient, Laplace Gradient)
@ Author: Zheng Haibo
Related blogs:
1. http://blog.csdn.net/nuptboyzhb/article/details/7925994
2. http://blog.csdn.net/nuptboyzhb/article/details/7926407
1. Robert Gradient
[Figure 1]

2. Sobel Gradient
[Figure 2]

3. Laplace Gradient
[Figure 3]

Key Java code

 
[Java]
/*
* Robert's operator gradient
*
*/
Public Bitmap Robert tgradient (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 = eachrobert tgradient (dataR, width, height );
DataG = eachrobert tgradient (dataG, width, height );
DataB = eachrobert tgradient (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 eachrobert tgradient (Matrix tempM, int width, int height ){
Int I, j;
For (I = 0; I <width-1; I ++ ){
For (j = 0; j Int temp = Math. abs (int) tempM. get (I, j)-(int) tempM. get (I, j + 1 ))
+ Math. abs (int) tempM. get (I + 1, j)-(int) tempM. get (I, j + 1 ));
TempM. set (I, j, temp );
}
}
Return tempM;
}
/*
* Sobel operator sharpening
*/
Public Bitmap SobelGradient (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 );
//////////////////////////////////////// /////////////////
Gradient Ray = eachSobelGradient (gradient Ray, width, height );
DataR = Ray. copy ();
DataG = Ray. copy ();
DataB = Ray. copy ();
//////////////////////////////////////// ///////////////////////
// Change bitmap to use new array
Bitmap bitmap = makeToBitmap (dataR, dataG, dataB, width, height );
MyBitmap = null;
Pix = null;
Return bitmap;
}
Private Matrix eachSobelGradient (Matrix tempM, int width, int height ){
Int I, j;
Matrix resultMatrix = tempM. copy ();
For (I = 1; I <width-1; I ++ ){
For (j = 1; j Int temp1 = Math. abs (int) tempM. get (I + 1, J-1) + 2 * (int) tempM. get (I + 1, j) + (int) tempM. get (I + 1, j + 1 ))
-(Int) tempM. get (I-1, J-1) + 2 * (int) tempM. get (I-1, j) + (int) tempM. get (I-1, J-1 ))));
Int temp2 = Math. abs (int) tempM. get (I-1, j + 1) + 2 * (int) tempM. get (I, j + 1) + (int) tempM. get (I + 1, j + 1 ))
-(Int) tempM. get (I-1, J-1) + 2 * (int) tempM. get (I, J-1) + (int) tempM. get (I + 1, J-1 ))));
Int temp = temp1 + temp2;
ResultMatrix. set (I, j, temp );
}
}
Return resultMatrix;
}
/*
* Laplace sharpening
*/
Public Bitmap LaplaceGradient (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 );
//////////////////////////////////////// /////////////////
Wedding Ray = eachLaplaceGradient (wedding Ray, width, height );
DataR = Ray. copy ();
DataG = Ray. copy ();
DataB = Ray. copy ();
//////////////////////////////////////// ///////////////////////
// Change bitmap to use new array
Bitmap bitmap = makeToBitmap (dataR, dataG, dataB, width, height );
MyBitmap = null;
Pix = null;
Return bitmap;
}
Private Matrix eachLaplaceGradient (Matrix tempM, int width, int height ){
Int I, j;
Matrix resultMatrix = tempM. copy ();
For (I = 1; I <width-1; I ++ ){
For (j = 1; j Int temp = Math. abs (5 * (int) tempM. get (I, j)-(int) tempM. get (I + 1, j)
-(Int) tempM. get (I-1, j)-(int) tempM. get (I, j + 1)-(int) tempM. get (I, J-1 ));
ResultMatrix. set (I, j, temp );
}
}
Return resultMatrix;
}

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.