normalize method
will clone data
Implementation
// Image astype(StbiDType dtype) {
// if (dtype == this.dtype) {
// return clone();
// }
// }
Image normalize({
List<double> mean = const [0.0, 0.0, 0.0, 0.0],
List<double> std = const [1.0, 1.0, 1.0, 1.0],
double scale = 1.0,
}) {
final size = _width * _height * _channels;
final p = calloc<ffi.Float>(size);
p
.asTypedList(size)
.setAll(
0,
values.indexed
.map((e) => (e.$2.toDouble() / scale - mean[e.$1 % _channels]) / std[e.$1 % _channels])
.toList(),
);
return Image.fromPointer(
p.cast(),
width: _width,
height: _height,
channels: _channels,
desiredChannels: _desiredChannels,
dtype: StbiDType.f32,
);
}