【问题标题】:2-Dimensional Convolution - How to implement in Java? [closed]二维卷积 - 如何在 Java 中实现? [关闭]
【发布时间】:2012-10-25 02:34:35
【问题描述】:

我已经用头撞墙了好一阵子了。 我习惯于使用 Matlab 的 conv2 函数,它自己进行卷积。

但是,我只是未能在 Java 中正确实现它。我会提供一个代码 sn-p,但它都搞砸了。我会尽量弄清楚并发布(实际上是凌晨 4:30,我仍在为此苦苦挣扎..)。

任何人都可以发布一个工作代码方法,在 Java 中对两个相同大小的二维数组进行二维卷积吗?

先谢谢了!

【问题讨论】:

  • Re, "can anyone please post a working code method that does the 2d convolution between two 2-dimensional arrays of the same size in Java?":正如目前所写的,这不是一个真正的问题,而是乞求不适合本网站的代码。请通过显示您的代码并在您的问题结束前询问具体的可回答问题来更改此设置。
  • 说真的,粗略的谷歌搜索会产生确切的功能。

标签: java arrays image-processing convolution


【解决方案1】:

一点点谷歌搜索永远不会受到伤害。 This code 可能会对您有所帮助。特别是,

public static double[][] convolution2D(double[][] input,
            int width, int height,
            double[][] kernel,
            int kernelWidth,
            int kernelHeight) {
        int smallWidth = width - kernelWidth + 1;
        int smallHeight = height - kernelHeight + 1;
        double[][] output = new double[smallWidth][smallHeight];
        for (int i = 0; i < smallWidth; ++i) {
            for (int j = 0; j < smallHeight; ++j) {
                output[i][j] = 0;
            }
        }
        for (int i = 0; i < smallWidth; ++i) {
            for (int j = 0; j < smallHeight; ++j) {
                output[i][j] = singlePixelConvolution(input, i, j, kernel,
                        kernelWidth, kernelHeight);
            }
        }
        return output;
    }

【讨论】:

  • 我做了,找不到任何值得使用的东西。将尝试这个部分。谢谢!
猜你喜欢
  • 2011-09-07
  • 2015-10-09
  • 2018-10-27
  • 2017-02-24
  • 1970-01-01
  • 2013-05-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多