关于高斯低通滤波器(GLPF)的题——图像分析基础

有没有老哥能帮忙解答一下这些题,或是提供一些相关资料给我,万分感谢,实在是不会做。

img

简单易懂的高斯滤波_的博客-CSDN博客_高斯滤波 高斯滤波先引入两个问题。1.图像为什么要滤波?答:a.消除图像在数字化过程中产生或者混入的噪声。b.提取图片对象的特征作为图像识别的特征模式。2.滤波器该如何去理解?答:滤波器可以想象成一个包含加权系数的窗口或者说一个镜片,当使用滤波器去平滑处理图像的时候,就是把通过这个窗口或者镜片去看这个图像。滤波器分为很多种,有方框滤波、均值滤波、高斯滤波等。高斯滤波是一种线性平滑滤波,... https://blog.csdn.net/qq1602382784/article/details/103679805?utm_term=%E7%AE%80%E5%8D%95%E8%AE%A1%E7%AE%97%E9%AB%98%E6%96%AF%E6%BB%A4%E6%B3%A2%E5%99%A8&utm_medium=distribute.pc_aggpage_search_result.none-task-blog-2~all~sobaiduweb~default-1-103679805&spm=3001.4430

二维的高斯滤波函数的 Java 代码实现:


    public static BufferedImage GLPF(BufferedImage image, int width, int height, double sigma) {
        int halfWidth = width/2;
        int halfHeight = height/2;
        // make gaussian core
        double[][] core = new double[width][height];
        double sum = 0;
        for (int x = 0 - halfWidth; x <= 0 + halfWidth; x++) {
            for (int y = 0 - halfHeight; y <= 0 + halfHeight; y++) {
                core[halfWidth+x][halfHeight+y] = Math.exp(-(x*x+y*y)/(2*sigma*sigma))/(2*Math.PI*sigma*sigma);
                sum += core[halfWidth+x][halfHeight+y];
                System.out.println(String.format("(%2d, %2d) %8f", x, y, core[halfWidth+x][halfHeight+y]));
            }
        }
        for (int i=0; i<core.length; i++) {
            for (int j=0; j<core[i].length; j++) {
                core[i][j] /= sum;
            }
        }
        // get rgb data from image
        int rgbWidth  = image.getWidth()  + width/2*2;
        int rgbHeight = image.getHeight() + height/2*2;
        int[][] rgbData = new int[rgbWidth][rgbHeight];
        for (int x=0; x<rgbData.length; x++) {
            for (int y=0; y<rgbData[x].length; y++) {
                int a = x < halfWidth ?
                        halfWidth - x :
                        x >= rgbWidth - halfWidth ?
                                rgbWidth*2 - halfWidth*3 - 2 - x :
                                x - halfWidth;
                int b = y < halfHeight ?
                        halfHeight - y :
                        y >= rgbHeight - halfHeight ?
                                rgbHeight*2 - halfHeight*3 - 2 - y:
                                y - halfHeight;
                rgbData[x][y] = image.getRGB(a, b);
            }
        }
        // create window data
        BufferedImage out = new BufferedImage(image.getWidth(), image.getHeight(), image.getType());
        for (int x=0; x<image.getWidth(); x++) {
            for (int y=0; y<image.getHeight(); y++) {
                int r = gaussianFilter(rgbData, x, y, core, width, height, rgb-> (rgb&0xFF0000)>>16);
                int g = gaussianFilter(rgbData, x, y, core, width, height, rgb-> (rgb&0xFF00)>>8);
                int b = gaussianFilter(rgbData, x, y, core, width, height, rgb-> rgb&0xFF);
                int rgb = (rgbData[x][y] & 0xFF000000) | (r << 16) | (g << 8) | b;
                out.setRGB(x, y, rgb);
            }
        }
        return out;
    }

    private static int gaussianFilter(int[][] rgbData, int x, int y, final double[][] core, int width, int height, Function<Integer, Integer> converter) {
        double value = 0;
        // fill window
        for (int a=0; a < width; a++) {
            for (int b=0; b < height; b++) {
                value += converter.apply(rgbData[x+a][y+b]) * core[a][b];
            }
        }
        return (int)value;
    }