buildBinaryMask function
Constrói uma máscara binária a partir dos protótipos de máscara e coeficientes.
Params:
- maskPrototypes: Lista 3D representando os protótipos de máscara (altura x largura x canais).
- maskCoefficients: Lista de coeficientes da máscara.
Returns: Imagem binária resultante.
Implementation
img.Image buildBinaryMask(
List<List<List<double>>> maskPrototypes,
List<double> maskCoefficients,
) {
final height = maskPrototypes.length;
final width = maskPrototypes[0].length;
final channels = maskPrototypes[0][0].length;
final numCoeffs = math.min(maskCoefficients.length, channels);
final binaryMask = img.Image(width: width, height: height);
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
double maskValue = 0.0;
// eixo dos canais no final (y, x, i)
for (int i = 0; i < numCoeffs; i++) {
maskValue += maskCoefficients[i] * maskPrototypes[y][x][i];
}
// Aplicar função sigmoide
final sigmoidValue = 1 / (1 + math.exp(-maskValue));
// Binarizar com threshold 0.5
final pixelValue = sigmoidValue > 0.5 ? 255 : 0;
binaryMask.setPixelRgb(x, y, pixelValue, pixelValue, pixelValue);
}
}
return binaryMask;
}