/
Nadita
/
1st_SemesterProject
Обзор
Документация
Войти
/
Nadita
/
1st_SemesterProject
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
ThresholdFilterTask.cs
43 строки
1 KB
Nadita
upload files
01 ноя 2025, 20:28
01 ноя 2025, 20:28
e7f7b7e
Код
Авторство
О чём код?
using System.Collections.Generic; namespace Recognizer; public static class ThresholdFilterTask { public static double LocationOfT(double[,] original, double whitePixelsFraction) { var neighbors = new List<double>(); var width = original.GetLength(0); var height = original.GetLength(1); for (var x=0; x < width; x++) { for (var y = 0; y < height; y++) { neighbors.Add(original[x, y]); } } neighbors.Sort(); var minWhitePixels = (int)(whitePixelsFraction * width * height); if (minWhitePixels == 0) return double.MaxValue; else return neighbors[width * height - minWhitePixels]; } public static double[,] ThresholdFilter(double[,] original, double whitePixelsFraction) { var width = original.GetLength(0); var height = original.GetLength(1); var T = LocationOfT(original, whitePixelsFraction); var result = new double[width, height]; for (var x = 0; x < width; x++) { for (var y = 0; y < height; y++) { result[x, y] = original[x, y] >= T ? 1.0 : 0.0; } } return result; } }