【问题标题】:Filter images android?过滤图像android?
【发布时间】:2012-04-23 04:58:47
【问题描述】:

我正在使用这个算法来过滤安卓中的图像。

http://xjaphx.wordpress.com/2011/06/22/image-processing-convolution-matrix/

但图像不如预期,我可以找到其他方法来做到这一点。您会看到应用程序已经这样做了,让它变得更快,这个算法太慢了。

问候

【问题讨论】:

    标签: android image filter convolution


    【解决方案1】:

    我最近在那里发布了您尝试过的代码的更快版本,您应该试一试。

    顺便问一下,images are not as expected这句话是什么意思?也许您只是使用了错误的矩阵;你可以找到一些矩阵示例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;
        }
    }
    

    【讨论】:

    • 感谢您的回复,当我应用数组时,然后将图像显示在几个像素之外。我会试试你的代码。
    • 您注意到的像素位移是因为,要转换一个像素,您需要围绕它的八个像素:因此您将在图像周围“松散”一个像素宽度的矩形 - 或者在任何情况下,如果你像我一样克隆原始像素,那些不会被转换。
    • 那么必须创建矩阵吗?浮动 src[] = {0,0,0, -1,-1,0 ,0,0,0};矩阵 mx = 新矩阵(); mx.setValues(src);
    • imageshack.us/photo/my-images/705/device20120422175353.png 图 16.155。浮雕 m.setValues(new float[] { -2, -1, 0, -1, 1, 1, 0, 1, 2 });
    • 白色像素,我该如何解决?
    【解决方案2】:

    我正在使用此公式根据扩展名过滤图像

    class FileExtensionFilter implements FilenameFilter {
            public boolean accept(File dir, String name) {
                return (name.endsWith(".png") || name.endsWith(".PNG"));
            }
    

    如果您从 sd 卡中获取它,请告诉我。我有它的代码。

    【讨论】:

    • 该问题与图形过滤有关,而不是按文件扩展名过滤。
    猜你喜欢
    • 2011-05-15
    • 1970-01-01
    • 2016-06-07
    • 2011-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-11
    相关资源
    最近更新 更多