1

在此处输入图像描述

我可以以与卷积相同的方式实现互相关吗?

我想实现如图所示的公式,其中Li内核在 4 个不同方向的过滤器中;Ci 是方向 i 的幅值图。所以我所做的就是分别找出四个方向的互相关,然后加起来。我了解到互相关可以与图像线锐化中的卷积相同;s 结果应该是图像的笔划线,但我实际得到的是离散点。我不确定我是否正确实施了公式。请帮忙

private static void sharpTheLine(){
        int[][] cC_0= crossCorrelation(KERNEL_0,CMap_0);
        int[][] cC_45=crossCorrelation(KERNEL_45,CMap_45);
        int[][] cC_90=crossCorrelation(KERNEL_90,CMap_90);
        int[][] cC_135=crossCorrelation(KERNEL_135,CMap_135);


        //generate S
        for(int i=0; i<imageWidth; i++){
            for(int j =0; j<imageHight; j++) {
                SMap[i][j] = cC_0[i][j]+cC_45[i][j]+cC_90[i][j]+cC_135[i][j];
            }
        }
    }

    private static int[][] crossCorrelation(int [][] kernel,int[][] CMapVal){
        int horizontalWalk = imageWidth - K_R;
        int verticalWalk = imageHight - K_C;
        int res[][]=new int[imageWidth][imageHight];
        for (int i = 0; i < horizontalWalk; i++) {
            for (int j = 0; j < verticalWalk; j++) {
                int sample[][] = new int[K_R][K_C];
                for (int k = i; k < K_R + i; k++) {
                    for (int m = j; m < K_C + j; m++) {
                        sample[k - i][m - j] = CMapVal[k][m];
                        OnePixelConvolution(sample, i, j, kernel, res);
                    }
                }
            }
        }

        return res;
    }
private static void OnePixelConvolution(int[][] sample, int x, int y, int [][]kernel, int [][] res) {
        int resrgb = 0;
        for (int i = 0; i < K_R; i++) {
            for (int j = 0; j < K_C; j++) {
                resrgb = resrgb + sample[i][j] * kernel[i][j];
            }
        }
        res[x][y] = resrgb;
    }
4

0 回答 0