图像处理(基于android)---滤镜实现的一点看法和总结
来源:互联网 发布:淘宝联盟的返现为什么 编辑:程序博客网 时间:2024/05/16 06:46
唠叨几句
我们知道,滤镜在目前社交App中发布用户图像处理中占据了一定的使用频率,有的效果很炫,可以稍微提高用户对app的粘合度。经过传说中的”逆向工程”技术发现,目前存在的大部分滤镜效果其实不是真正的滤镜,对于一个图像处理的小白菜鸟来说,真想说一句,”你大爷的!”。当然,开个玩笑。当下,滤镜处理技术分为两种:
真实滤镜
对于图像处理届的大神介绍,真正的滤镜其实就是颜色矩阵变换的结果,本质上讲,就是对图像像素点的A,R,G,B的数据变换处理。
实现真实滤镜的方法也很多,比如,通过RGB变换公式,颜色矩阵变换(其本质也是RGB变换公式),还有改变图像的色相(色调),亮度,饱和度。
测试图:
1. RGB变换公式 例如: 反色效果(照片底片) r' = 255 - r; g' = 255 - g; b' = 255 - b; 怀旧效果 r' = 0.393 * r + 0.769 * g + 0.189 * b; g' = 0.349 * r + 0.686 * g + 0.168 * b; b' = 0.272 * r + 0.534 * g + 0.131 * b; 2. 颜色矩阵变换
矩阵的运算规则是矩阵A的一行乘以矩阵C的一列作为矩阵R的一行,
C矩阵是图片中包含的ARGB信息,R矩阵是用颜色矩阵应用于C之后的新的颜色分量,运算结果如下:
R’ = a*R + b*G + c*B + d*A + e;
G’ = f*R + g*G + h*B + i*A + j;
B’ = k*R + l*G + m*B + n*A + o;
A’ = p*R + q*G + r*B + s*A + t;
private void functionFilter() { float[] maxtriFilter = new float[20]; for (int index = 0; index < 20; index++) { EditText et = ((EditText) mGridLayout.getChildAt(index)); if (index < 15 && (index + 2) % 5 == 0) { maxtriFilter[index] = 0.0f; et.setText("0"); continue; } if (index >= 15 && index != 18) { maxtriFilter[index] = 0.0f; et.setText("0"); continue; } if (index == 18) { maxtriFilter[index] = 1.0f; et.setText("1"); continue; } float value = Float.valueOf((float) (Math.random() * 255.0f)); maxtriFilter[index] = value; et.setText("" + maxtriFilter[index]); } Bitmap bmp = Bitmap.createBitmap(mBitmapSrc.getWidth(), mBitmapSrc.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(bmp); Paint paint = new Paint(); ColorMatrix mColorMatrix = new ColorMatrix(); mColorMatrix.set(maxtriFilter); paint.setColorFilter(new ColorMatrixColorFilter(mColorMatrix)); canvas.drawBitmap(mBitmapSrc, 0, 0, paint); pictureShow.setImageBitmap(bmp); }
注:感觉特不爽。应该是随机数太大了,那么换成0 ~1的小数试试
float value = Float.valueOf((float) (Math.random()));
而且 颜色分量也可以去掉了,要不然程度太大了,但也可以加上。
private void functionFilter() { float[] maxtriFilter = new float[20]; for (int index = 0; index < 20; index++) { if (index < 15 && ((index + 2) % 5 == 0 || (index + 1) % 5 == 0)) { maxtriFilter[index] = 0.0f; continue; } if (index >= 15 && index != 18) { maxtriFilter[index] = 0.0f; continue; } if (index == 18) { maxtriFilter[index] = 1.0f; continue; } float value = Float.valueOf((float) (Math.random())); maxtriFilter[index] = value; } for (int index = 0; index < 20; index++) { EditText et = ((EditText) mGridLayout.getChildAt(index)); et.setText("" + maxtriFilter[index]); } Bitmap bmp = Bitmap.createBitmap(mBitmapSrc.getWidth(), mBitmapSrc.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(bmp); Paint paint = new Paint(); ColorMatrix mColorMatrix = new ColorMatrix(); mColorMatrix.set(maxtriFilter); paint.setColorFilter(new ColorMatrixColorFilter(mColorMatrix)); canvas.drawBitmap(mBitmapSrc, 0, 0, paint); pictureShow.setImageBitmap(bmp); }
效果是不是很炫。那么我加上颜色分量试试
if (index < 15 && ((index + 2) % 5 == 0 //|| (index + 1) % 5 == 0 ) ) { maxtriFilter[index] = 0.0f; continue; }
效果也不错。
未完待续
3. 改变色相,亮度,饱和度
- 图层混合滤镜
0 0
- 图像处理(基于android)---滤镜实现的一点看法和总结
- 【Android图像处理】水波纹滤镜的实现
- Atitit (Sketch Filter)素描滤镜的实现 图像处理 attilax总结
- Atitit (Sketch Filter)素描滤镜的实现 图像处理 attilax总结v2
- android 图像处理滤镜系列
- CNN处理图像的一点总结
- Android图像处理之镜像和简单滤镜效果
- 基于Opencv的Android图像处理(Eclipse和ndk)
- android 图像处理滤镜系列合集
- android 图像处理滤镜系列合集
- android 图像处理滤镜系列合集
- 【Android图像处理】黑白滤镜(效果)
- 【Android图像处理】光照滤镜(效果)
- 【Android图像处理】宝石蓝滤镜(效果)
- 【Android图像处理】lomo滤镜(效果)
- 【Android图像处理】浮雕滤镜(效果)
- 【Android图像处理】羽化滤镜(效果)
- 【Android图像处理】图像处理之-幻觉滤镜
- 膀葿蚇螈羆艿蚀袃肅膈蚃罿
- 袈莅芅螈螄莅莇薁膃莄蕿袇
- 1078. Hashing
- 袅膃蚅螄膇膅莈薀羆肈莄蝿
- 蕿羁肂蒁薈蚁袅莇薈螃肁芃
- 图像处理(基于android)---滤镜实现的一点看法和总结
- 膁芁螂蚃肄芇蕿羅肆莃蚇袄
- 袂袃莁葿薁膈芇蒈蚄羁膃蒇
- spring之注解(一)概述
- Tk:perl/Tk, TCL/Tk, python/Tk(Tkinter)示例
- UVA - 10006 Carmichael Numbers
- HDU 1829 A Bug's Life
- PL/SQL传参中一个很奇怪的一个问题
- Dubbo 入门实例 本地伪集群测试Demo