Android Camera Real-Time Filter (3), androidcamera
I. Implementation of the Basic Filter Algorithm Based on the Android platform
1. Android provides the ColorMatrix method to change the image value. The ColorMatrix method can be used to implement basic filters, such as black and white, gray, and yellowing effects.
2. Use ColorMatrix to change the image value, generate a transformation matrix, and multiply the Matrix to change the pixel value of each vertex.
Matrix =>
|
R1 |
R2 |
R3 |
R4 |
R5 |
|
G1 |
G2 |
G3 |
G4 |
G5 |
|
B1 |
B2 |
B3 |
B4 |
B5 |
|
A1 |
A2 |
A3 |
A4 |
A5 |
After change
R' = R * r1 + G * r2 + B * r3 + A * r4 + r5;
G' = R * g1 + G * g2 + B * g3 + A * g4 + g5;
B '= R * b1 + G * b2 + B * b3 + A * b4 + b5;
A' = R * a1 + G * a2 + B * a3 + A * a4 + a5;
1st ~ Three columns control the color phase, 4th columns control transparency, and 5th columns control the added value of components.
3. Changes in R, G, B, And A numbers will modify the image effect.
(1) When the diagonal value is 1.0 and the other value is 0, the image guarantees the original image.
|
Original Image |
|
R |
1.0 |
0 |
0 |
0 |
0 |
|
G |
0 |
1.0 |
0 |
0 |
0 |
|
B |
0 |
0 |
1.0 |
0 |
0 |
|
A |
0 |
0 |
0 |
1.0 |
0 |
(2) If the diagonal value is greater than 1.0 and the other value is 0, the image is highlighted.
|
Partial brightness |
|
R |
2.0 |
0 |
0 |
0 |
0 |
|
G |
0 |
2.0 |
0 |
0 |
0 |
|
B |
0 |
0 |
2.0 |
0 |
0 |
|
A |
0 |
0 |
0 |
2.0 |
0 |
(3) If the diagonal value is less than 1.0 and the other value is 0, the image is dark.
|
The image is dark. |
|
R |
0.5 |
0 |
0 |
0 |
0 |
|
G |
0 |
0.5 |
0 |
0 |
0 |
|
B |
0 |
0 |
0.5 |
0 |
0 |
|
A |
0 |
0 |
0 |
0.5 |
0 |
(4) set the image to Gray. R 0.3 G0.59 B 0.11
|
The image is dark. |
|
R |
0.3f |
0.59f |
0.11f |
0 |
0 |
|
G |
0.3f |
0.59f |
0.11f |
0 |
0 |
|
B |
0.3f |
0.59f |
0.11f |
0 |
0 |
|
A |
0 |
0 |
0 |
1.0 |
0 |
4. Based on the above implementation, the algorithm for implementing the Basic filter is
Public Bitmap getBlackStyle (Bitmap src) {Bitmap dst = Bitmap. createBitmap (src. getWidth (), src. getHeight (), Config. ARGB_8888); Canvas canvas = new Canvas (dst); ColorMatrix cm = new ColorMatrix (); // sets the image to Gray, query the R 0.3 G0.59 B 0.11cm.set (new float [] {0.3f, 0.59f, 0.11f, 0, 0, 0.3f, 0.59f, 0.11f, 0, 0, 0.3f, 0.59f, 0.11f, 0, 0, 0, 0, 0, 1, 0}); Paint paint = new Paint (); paint. setColorFilter (new ColorMatrixColorFilter (cm); canvas. drawBitmap (src, 0, 0, paint); // Save the image canvas. save (Canvas. ALL_SAVE_FLAG); // stores the canvas. restore (); return dst ;}
Iii. Post-filter Era
I have seen some information and camera applications on the Internet. Many camera players are increasingly using mobile phones and cameras. As mobile phone cameras, developers need to have more ideas and features to improve their mobile phones! The following camera development directions are for your reference:
(1) Real-Time Filter
VIDA is a photography application from a Chinese team. It features real-time filters. You can preview the final product while shooting. This is a way to enhance the filter function. Unlike simply adding a new filter, the real-time filter holds the essence of what you see is what you get.
(2) GIF Animation
GIFshop is an application that allows you to quickly create a frozen animation. It combines the narrative capability of dynamic images and retains the small size of images. However, GIFshop has a very prominent problem. Compared with recording life, it is more suitable for creating humorous dynamic sketches. Once "creation" is involved, the user's threshold is raised relentlessly. However, the idea of moving the screen is more advanced than simply reinforcing the filter.
(3) dynamic images
Images produced by cinemedia can only have dynamic effects in a specific area. You can create an online pop-up "active poster ". Compared with GIFshop, it can make normal notebook photos a little magical. Because of the clever conception of the application, it is suitable for different scenarios. The user's threshold is relatively small, but the gains are quite high. I think of it as an improved version of GIFshop.
(4) Sound + image
Picle is an application that allows you to record the next audio clip while taking a photo. Its advantage is that it allows an interesting role, "voiceover", to participate in the photo narration. Compared with the above applications, Picle has entered another dimension. It takes into account the narrative bottleneck of the image and tries to break through by adding audio. The problem with Picle is that it has established a new format that can only be shared within the Picle system.
In the post-filter era, different teams set different bottlenecks in different directions and used some methods to break through. The starting point of thinking is to enhance the image narrative ability. From the current situation, there are some things worth noting:
· Volume: it cannot be bloated because of enhanced effects.
· Subject matter: you cannot narrow down your use scenarios because it is especially suitable for a subject matter.
· Format: start with the existing popular format to avoid using the new format.
· Threshold: Balance the interests of users and the complexity of use.
· Multimedia: adds images, but cannot evolve into videos.
We believe that with the enhancement of hardware technology, mobile phones will become a new type of camera device. It may not replace traditional cameras, but it can become irreplaceable because of applications. It is foreseeable that the filter will not be the last stop of mobile phone photography.