过滤图像的android? [英] Filter images android?
问题描述
我用这个算法在Andriod的过滤图像。
I'm using this algorithm to filter images in andriod.
HTTP://xjaphx.word press.com / 2011/06/22 /图像处理卷积矩阵/
但图像并不如预期,在哪里可以找到其他的方式来做到这一点。您将看到应用程序已经做到这一点,使得它速度快,这种算法是太慢。
But the images are not as expected, where I can find other ways to do this. You see that applications already do this, makes it fast, this algorithm is way too slow.
关于
推荐答案
我最近公布有你试过code更快的版本,你应该给它一个尝试。
I recently posted there a faster version of the code you tried, you should give it a try.
顺便说一句,你有什么用句意思的图像并不如预期的?也许你只是使用了错误的矩阵;你可以找到一些矩阵例如这里 。
By the way, what do you mean with the sentence images are not as expected ? Maybe you're just using a wrong matrix; you can find some matrix example here.
下面是您所要求的样品。如果您不需要缩放/偏移像素的颜色,你应该添加回旋
不同的实现没有这些参数和相关的不必要的计算。
Here is the sample you requested. If you don't need to scale / offset pixel colors, you should add different implementations of convolute
without those parameters and the related unnecessary computations.
class Convolution {
private static Bitmap convolute(Bitmap bmp, Matrix mat, float factor, int offset) {
/* ... */
}
private static Matrix getEdgeEnhanceMatrix() {
Matrix m = new Matrix();
m.setValues(new float[] {
0, 0, 0,
-1, 1, 0,
0, 0, 0
});
return m;
}
// the simple way
public static Bitmap edgeEnhance1(Bitmap bmp) {
return convolute(bmp, getEdgeEnhanceMatrix(), 1f, 0);
}
// if you want to apply filter to border pixels
// warning: really memory consuming
public static Bitmap edgeEnhance2(Bitmap bmp, int bgColor) {
// create a bigger canvas
Bitmap bigger = Bitmap.createBitmap(bmp.getWidth() + 2, bmp.getHeight() + 2, bmp.getConfig());
Canvas cBigger = new Canvas(bigger);
// paint background
cBigger.drawColor(bgColor);
// draw the bmp you want to manipulate from (1,1)
cBigger.drawBitmap(bmp, 1, 1, null);
// compute convolution
bigger = convolute(bigger, getEdgeEnhanceMatrix(), 1f, 0);
// create the result and project the convolution at (-1,-1)
Bitmap rt = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(), bmp.getConfig());
Canvas cRt = new Canvas(rt);
cRt.drawBitmap(bigger, -1, -1, null);
return rt;
}
}
这篇关于过滤图像的android?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!