The sharpening effect of Android image effect processing

Source: Internet
Author: User

This article deals with the sharpening effect of image effects. As before, the pixel is processed, and the algorithm is universal.

Algorithm principle:

A simple algorithm: To obtain the current pixel and the eight pixels around the RGB value, first find the current pixel RGB value and eight pixels of the RGB value of the average, and then multiplied by the corresponding coefficients, and then at the current pixel and the sum.

Cases:

Abc

Def

GHI

Sharpen the E point:

[Java]View Plaincopy
    1. Float delta = 0.3;
    2. E.R = (E.R-(A.R + B.R + C.R + D.R + F.R + G.R + H.R + I.R)/ 8) * Delta + E.R;
[Java]View PlainCopy
    1. Float delta = 0.3;
    2. E.R = (E.R-(A.R + B.R + C.R + D.R + F.R + G.R + H.R + I.R)/ 8) * Delta + E.R;

e.g,e.b similar, the delta proposed to take 0.3, the specific how much does not matter, try to know. But according to the above principle, did not achieve the desired effect, change the delta value is not, so the code is not posted out, interested can be studied.


Laplace transformation: The product of the Laplace matrix and the corresponding point of the RGB value multiplied by the corresponding coefficients and as the current point of the RGB value.

Example: Use the above example, or the e point sharpening.

[Java]View Plaincopy
  1. Laplace matrix
  2. int[] Laplacian = newint[] {-1,-1,-1,-1,9,-1,-1,-1,-1};
  3. Float delta = 0.3;
  4. E.R = A.R * laplacian[0] * Delta + B.R * laplacian[1] * Delta + C.R * laplacian[2] * Delta + D.R * laplacian[< C3>3] * Delta + E.R * laplacian[4] * Delta + F.R * laplacian[5] * Delta + G.R * laplacian[6] * Delta + H.R * L  aplacian[7] * Delta + I.R * laplacian[8] * DELTA;
  5. E.g and e.b values are similar
[Java]View PlainCopy
  1. Laplace matrix
  2. int[] Laplacian = new int[] {-1,-1,-1,-1, 9,-1,-1,-1,-1};
  3. Float delta = 0.3;
  4. E.R = A.R * laplacian[0] * Delta + B.R * laplacian[1] * Delta + C.R * laplacian[2] * Delta + D.R * laplacian[< C3>3] * Delta + E.R * laplacian[4] * Delta + F.R * laplacian[5] * Delta + G.R * laplacian[6] * Delta + H.R * L  aplacian[7] * Delta + I.R * laplacian[8] * DELTA;
  5. E.g and e.b values are similar


See below:

Original:


After processing:


Seems to deal with a bit of a problem, the middle will see a lot of vertical lines, it is obvious that may not be optimized, because the use of the Getpiexels () and Setpixels () method, so the one-dimensional array of the corresponding picture of the width of a little trouble.

The following code, only for the parameters, the same attention to the size of the picture, the size of the array can not exceed the virtual machine specified value.

[Java]View PlainCopy
    1. /**
    2. * Image Sharpening (Laplace transform)
    3. * @param bmp
    4. * @return
    5. */
    6. private Bitmap sharpenimageameliorate (Bitmap bmp)
    7. {
    8. Long start = System.currenttimemillis ();
    9. //Laplace Matrix
    10. int[] Laplacian = new int[] {-1,-1,-1,-1, 9,-1,-1,-1,-1};
    11. int width = bmp.getwidth ();
    12. int height = bmp.getheight ();
    13. Bitmap Bitmap = bitmap.createbitmap (width, height, Bitmap.Config.RGB_565);
    14. int pixr = 0;
    15. int pixg = 0;
    16. int pixb = 0;
    17. int pixcolor = 0;
    18. int newr = 0;
    19. int NEWG = 0;
    20. int newb = 0;
    21. int idx = 0;
    22. float alpha = 0.3F;
    23. int[] pixels = new int[width * height];
    24. Bmp.getpixels (pixels, 0, width, 0, 0, width, height);
    25. for (int i = 1, length = height- 1; i < length; i++)
    26. {
    27. for (int k = 1, len = width- 1; k < Len; k++)
    28. {
    29. IDX = 0;
    30. For (int m =-1; m <= 1; m++)
    31. {
    32. For (int n =-1; n <= 1; n++)
    33. {
    34. Pixcolor = pixels[(i + N) * width + k + m];
    35. PIXR = Color.Red (Pixcolor);
    36. Pixg = Color.green (Pixcolor);
    37. PIXB = Color.Blue (Pixcolor);
    38. NEWR = NEWR + (int) (PIXR * LAPLACIAN[IDX] * alpha);
    39. NEWG = NEWG + (int) (PIXG * LAPLACIAN[IDX] * alpha);
    40. Newb = newb + (int) (PIXB * LAPLACIAN[IDX] * alpha);
    41. idx++;
    42. }
    43. }
    44. NEWR = Math.min (255, Math.max (0, NEWR));
    45. NEWG = Math.min (255, Math.max (0, NEWG));
    46. Newb = Math.min (255, Math.max (0, newb));
    47. Pixels[i * width + K] = Color.argb (255, NEWR, NEWG, newb);
    48. NEWR = 0;
    49. NEWG = 0;
    50. Newb = 0;
    51. }
    52. }
    53. Bitmap.setpixels (pixels, 0, width, 0, 0, width, height);
    54. Long end = System.currenttimemillis ();
    55. LOG.D ("may", "used time=" + (End-start));
    56. return bitmap;
    57. }

The sharpening effect of Android image effect processing

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.