imageToByteListFloat32 method

Float32List imageToByteListFloat32(
  1. Image image
)

Implementation

Float32List imageToByteListFloat32(imglib.Image image) {
  var convertedBytes = Float32List(1 * 112 * 112 * 3);
  var buffer = Float32List.view(convertedBytes.buffer);
  int pixelIndex = 0;

  for (var i = 0; i < 112; i++) {
    for (var j = 0; j < 112; j++) {
      var pixel = image.getPixel(j, i);

      buffer[pixelIndex++] = (imglib.getRed(pixel) - 128) / 128;
      buffer[pixelIndex++] = (imglib.getGreen(pixel) - 128) / 128;
      buffer[pixelIndex++] = (imglib.getBlue(pixel) - 128) / 128;
    }
  }
  return convertedBytes.buffer.asFloat32List();
}