conv2d function

dynamic conv2d(
  1. List input,
  2. List kernal,
  3. Image image
)

Implementation

conv2d(List input, List kernal, Image image) {
  int maxLen = input.length * kernal.length;

  for (int mnij = 0, m = 0, n = 0, i = 0, j = 0; mnij < input.length; mnij++) {
    var imageIndex = j * image.width + i;
    var kernalIndex = n * 3 + m;
    var output = input[imageIndex] * kernal[kernalIndex];
    if (output < 0) {
      output = 0;
    }
    if (output > 255) {
      output = 255;
    }
    image.setPixel(i, j, Color.fromRgba(output, output, output, output));
    print(
        "image Index = ${imageIndex}, x = $i,y = $j, kernal Index = ${kernalIndex}, m = $m, n = $n, output = ${output}");

    //var data = image.getPixel(i, j);

    if (++m == 3) {
      m = 0;
      ++n;
    }
    if (n >= 3) {
      n = 0;
    }
    //n = 0;

    if (++i == image.width) {
      i = 0;
      ++j;
    }
  }
}