我正在使用此算法在andriod中过滤图像。过滤器图像android?
http://xjaphx.wordpress.com/2011/06/22/image-processing-convolution-matrix/
但图像并不如预期,在哪里可以找到其他的方法来做到这一点。你会发现应用程序已经做到了,速度很快,这个算法太慢了。
问候
我正在使用此算法在andriod中过滤图像。过滤器图像android?
http://xjaphx.wordpress.com/2011/06/22/image-processing-convolution-matrix/
但图像并不如预期,在哪里可以找到其他的方法来做到这一点。你会发现应用程序已经做到了,速度很快,这个算法太慢了。
问候
我使用这个公式来过滤图像按他们的扩展
class FileExtensionFilter implements FilenameFilter {
public boolean accept(File dir, String name) {
return (name.endsWith(".png") || name.endsWith(".PNG"));
}
如果您正在从SD卡读取它让我知道这个。我为它有代码。
我最近在那里发布了一个你试过的代码的更快版本,你应该试试看。
顺便说一句,你是什么意思与句子图像不是预期的?也许你只是使用了错误的矩阵;你可以找到一些矩阵例子here。
以下是您要求的样品。如果不需要缩放/偏移像素颜色,则应该添加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;
}
}
感谢您的回复,当我应用数组时,然后将图像显示几个像素。我会尝试你的代码。 – tebitoq 2012-04-22 02:52:43
您注意到的像素位移是因为要获得一个像素变换,您需要围绕它的八个像素:因此,您将在图像周围“松动”一个像素宽度的矩形 - 或者无论如何,如果您克隆原始像素正如我所做的那样,这些不会被改变。 – ubik 2012-04-22 18:24:07
所以将不得不创建矩阵? \t \t浮子SRC [] = {0,0,0, \t \t \t \t \t -1,-1,0 \t \t \t \t \t,0,0,0}; \t \t Matrix mx = new Matrix(); \t \t mx.setValues(src); – tebitoq 2012-04-22 19:00:29
这个问题涉及图形过滤而不是通过文件扩展名进行过滤。 – stealthcopter 2012-08-22 15:34:26