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
- Float delta = 0.3;
- 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
- Float delta = 0.3;
- 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
- Laplace matrix
- int[] Laplacian = newint[] {-1,-1,-1,-1,9,-1,-1,-1,-1};
- Float delta = 0.3;
- 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;
- E.g and e.b values are similar
[Java]View PlainCopy
- Laplace matrix
- int[] Laplacian = new int[] {-1,-1,-1,-1, 9,-1,-1,-1,-1};
- Float delta = 0.3;
- 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;
- 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
- /**
- * Image Sharpening (Laplace transform)
- * @param bmp
- * @return
- */
- private Bitmap sharpenimageameliorate (Bitmap bmp)
- {
- Long start = System.currenttimemillis ();
- //Laplace Matrix
- int[] Laplacian = new int[] {-1,-1,-1,-1, 9,-1,-1,-1,-1};
- int width = bmp.getwidth ();
- int height = bmp.getheight ();
- Bitmap Bitmap = bitmap.createbitmap (width, height, Bitmap.Config.RGB_565);
- int pixr = 0;
- int pixg = 0;
- int pixb = 0;
- int pixcolor = 0;
- int newr = 0;
- int NEWG = 0;
- int newb = 0;
- int idx = 0;
- float alpha = 0.3F;
- int[] pixels = new int[width * height];
- Bmp.getpixels (pixels, 0, width, 0, 0, width, height);
- for (int i = 1, length = height- 1; i < length; i++)
- {
- for (int k = 1, len = width- 1; k < Len; k++)
- {
- IDX = 0;
- For (int m =-1; m <= 1; m++)
- {
- For (int n =-1; n <= 1; n++)
- {
- Pixcolor = pixels[(i + N) * width + k + m];
- PIXR = Color.Red (Pixcolor);
- Pixg = Color.green (Pixcolor);
- PIXB = Color.Blue (Pixcolor);
- NEWR = NEWR + (int) (PIXR * LAPLACIAN[IDX] * alpha);
- NEWG = NEWG + (int) (PIXG * LAPLACIAN[IDX] * alpha);
- Newb = newb + (int) (PIXB * LAPLACIAN[IDX] * alpha);
- idx++;
- }
- }
- NEWR = Math.min (255, Math.max (0, NEWR));
- NEWG = Math.min (255, Math.max (0, NEWG));
- Newb = Math.min (255, Math.max (0, newb));
- Pixels[i * width + K] = Color.argb (255, NEWR, NEWG, newb);
- NEWR = 0;
- NEWG = 0;
- Newb = 0;
- }
- }
- Bitmap.setpixels (pixels, 0, width, 0, 0, width, height);
- Long end = System.currenttimemillis ();
- LOG.D ("may", "used time=" + (End-start));
- return bitmap;
- }
The sharpening effect of Android image effect processing