我正在使用这个算法来过滤安卓中的图像。
http://xjaphx.wordpress.com/2011/06/22/image-processing-convolution-matrix/
但是图像并不像预期的那样,我可以找到其他方法来做到这一点。您会看到应用程序已经这样做了,让它变得更快,这个算法太慢了。
问候
我正在使用这个算法来过滤安卓中的图像。
http://xjaphx.wordpress.com/2011/06/22/image-processing-convolution-matrix/
但是图像并不像预期的那样,我可以找到其他方法来做到这一点。您会看到应用程序已经这样做了,让它变得更快,这个算法太慢了。
问候
我最近在那里发布了您尝试过的代码的更快版本,您应该试一试。
顺便说一句,句子图像不如预期是什么意思?也许您只是使用了错误的矩阵;你可以在这里找到一些矩阵示例。
这是您要求的样品。如果您不需要缩放/偏移像素颜色,则应添加convolute
不带这些参数的不同实现以及相关的不必要计算。
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;
}
}
我正在使用此公式根据扩展名过滤图像
class FileExtensionFilter implements FilenameFilter {
public boolean accept(File dir, String name) {
return (name.endsWith(".png") || name.endsWith(".PNG"));
}
如果您从 sd 卡中获取它,请告诉我。我有它的代码。