/// <summary> /// Сделать макс-пуллинг. /// </summary> /// <param name="map">Карта изображения.</param> /// <returns>Возвращаёт обработанную карту.</returns> public FigureMap DoMaxPooling(FigureMap map) { if (map.Size <= Size) { throw new Exception("Размер карты изображения не может " + "быть меньше или равен размеру матрицы макс-пуллинга."); } if (map.Size % Size > 0) { throw new Exception("Размеры карты изображения и матрицы " + "макс-пуллинга должны быть кратны."); } var sectorsInLine = map.Size / Size; var matrix = new double[sectorsInLine, sectorsInLine]; for (var xStartIndex = 0; xStartIndex < sectorsInLine; xStartIndex += Size) { for (var yStartIndex = 0; yStartIndex < sectorsInLine; yStartIndex += Size) { var xEndIndex = xStartIndex + Size; var yEndIndex = yStartIndex + Size; var elements = map.Cells.FindAll( cell => cell.X >= xStartIndex && cell.X < xEndIndex && cell.Y >= yStartIndex && cell.Y < yEndIndex); matrix[xStartIndex / Size, yStartIndex / Size] = GetMaxValue(elements); } } return(new FigureMap(sectorsInLine, matrix)); }
/// <summary> /// Сделать фильтрацию карты изображения. /// </summary> /// <param name="map">Карта изображения.</param> /// <returns>Новая карта изображений.</returns> public FigureMap DoMapFiltering(FigureMap map) { if (!_isInitialized) { throw new Exception("Невозможно использовать фильтр до его инициализации!"); } var step = map.Size - this.Size; var newSize = step + 1; double[,] data = new double[newSize, newSize]; for (var xStartIndex = 0; xStartIndex <= step; ++xStartIndex) { for (var yStartIndex = 0; yStartIndex <= step; ++yStartIndex) { var xEndIndex = xStartIndex + this.Size; var yEndIndex = yStartIndex + this.Size; var choosenCells = map.Cells.FindAll( cell => cell.X >= xStartIndex && cell.X < xEndIndex && cell.Y >= yStartIndex && cell.Y < yEndIndex); var cellsToRewrite = new List <Cell>(); choosenCells.ForEach(cell => cellsToRewrite.Add(new Cell(cell.X - xStartIndex, cell.Y - yStartIndex, cell.Value))); data[xStartIndex, xStartIndex] = ToConvoluteData(cellsToRewrite, Cells); } } return(new FigureMap(newSize, data)); }