public static byte[,] RotateLeft(byte[,] block) { var blockDown = new byte[, ] { { 0, 0, 0 }, { 1, 1, 1 }, { 0, 1, 0 }, }; var blockRight = new byte[, ] { { 0, 1, 0 }, { 0, 1, 1 }, { 0, 1, 0 }, }; var blockUp = new byte[, ] { { 0, 1, 0 }, { 1, 1, 1 }, { 0, 0, 0 }, }; var blockLeft = new byte[, ] { { 0, 1, 0 }, { 1, 1, 0 }, { 0, 1, 0 }, }; bool downTrue = block.Rank == blockDown.Rank && Enumerable.Range(0, block.Rank).All(dimension => block.GetLength(dimension) == blockDown.GetLength(dimension)) && block.Cast <byte>().SequenceEqual(blockDown.Cast <byte>()); bool rightTrue = block.Rank == blockRight.Rank && Enumerable.Range(0, block.Rank).All(dimension => block.GetLength(dimension) == blockRight.GetLength(dimension)) && block.Cast <byte>().SequenceEqual(blockRight.Cast <byte>()); bool upTrue = block.Rank == blockUp.Rank && Enumerable.Range(0, block.Rank).All(dimension => block.GetLength(dimension) == blockUp.GetLength(dimension)) && block.Cast <byte>().SequenceEqual(blockUp.Cast <byte>()); bool leftTrue = block.Rank == blockLeft.Rank && Enumerable.Range(0, block.Rank).All(dimension => block.GetLength(dimension) == blockLeft.GetLength(dimension)) && block.Cast <byte>().SequenceEqual(blockLeft.Cast <byte>()); while (downTrue) { block = blockRight; downTrue = false; } while (rightTrue) { block = blockUp; rightTrue = false; } while (upTrue) { block = blockLeft; upTrue = false; } while (leftTrue) { block = blockDown; leftTrue = false; } return(block); }
/// <summary> /// Creates an <see cref="OxyImage"/> from the specified 8-bit indexed pixel data. /// </summary> /// <param name="indexedData"> /// The indexed pixel data (from bottom-left). /// </param> /// <param name="palette"> /// The palette. /// </param> /// <param name="dpi"> /// The resolution. /// </param> /// <returns> /// An <see cref="OxyImage"/>. /// </returns> public static OxyImage FromIndexed8(byte[,] indexedData, OxyColor[] palette, int dpi = 96) { int height = indexedData.GetLength(0); int width = indexedData.GetLength(1); return(FromIndexed8(width, height, indexedData.Cast <byte>().ToArray(), palette, dpi)); }
private void Trunc(byte[] hash) { int hash_nbytes = HashSizeValue / 8; var flat = _state.Cast <byte>().ToArray(); Array.Copy(flat, flat.Length - hash_nbytes, hash, 0, hash.Length); }
private byte GetMatrixMedian(byte[,] xs) { var lst = xs.Cast <byte>().ToList(); lst.Sort(); return(lst[lst.Count / 2]); }
/// <summary> /// 画像にソーベルフィルタを適用 /// </summary> /// <param name="sourceImage">画像の2次元配列</param> /// <param name="multiplyConstant">画像が見やすくなるように適当な定数倍を掛けるかどうか</param> /// <returns>エッジ強度画像の2次元配列</returns> public static byte[,] ApplySobelFilter(byte[,] sourceImage, bool multiplyConstant) { byte[,] destImage = ImageFiltering.CreateGradientImage( ImageFiltering.ApplyHorizontalSobelFilter(sourceImage), ImageFiltering.ApplyVerticalSobelFilter(sourceImage)); if (!multiplyConstant) { return(destImage); } byte maxPixelValue = destImage.Cast <byte>().Max(); int imageWidth = destImage.GetLength(0); int imageHeight = destImage.GetLength(1); // 見やすくなるように適当な定数倍を掛ける for (int x = 0; x < imageWidth; ++x) { for (int y = 0; y < imageHeight; ++y) { destImage[x, y] = (byte)(destImage[x, y] * 255.0 / maxPixelValue); } } return(destImage); }
public Exploration(byte[,] explorationGrid) { var f = explorationGrid.Cast <byte>().ToArray(); InitialExploreSum = f.Sum <byte>(x => (int)x); CurrentExploreSum = InitialExploreSum; int width = explorationGrid.GetLength(0); int height = explorationGrid.GetLength(1); int numberOfGrids = 3; int widthOfEachGrid = width / numberOfGrids; int heightOfEachGrid = height / numberOfGrids; // Create x grids for (int x = 0; x < numberOfGrids; x++) { for (int y = 0; y < numberOfGrids; y++) { int xStart = widthOfEachGrid * x; int yStart = heightOfEachGrid * y; int clampedWidth = MyExtensions.Clamp <int>(widthOfEachGrid, 0, width - xStart); int clampedHeight = MyExtensions.Clamp <int>(heightOfEachGrid, 0, height - yStart); grids.Add(new ExplorationGrid(explorationGrid, xStart, yStart, clampedWidth, clampedHeight)); } } }
public bool GoalTest(byte[,] state) { if (goalState.Cast <byte>().SequenceEqual(state.Cast <byte>())) { return(true); } return(false); }
void UpdateUI() { byte[] flatArray = Tilehelyzet.Cast <byte>().ToArray(); for (int i = 0; i < 9; i++) { if (flatArray[i] == 0) { (Tilitolielemek[i] as Button).Visibility = Visibility.Hidden; } else { (Tilitolielemek[i] as Button).Visibility = Visibility.Visible; (Tilitolielemek[i] as Button).Content = flatArray[i].ToString(); } } lepesek.Text = lepesekszam.ToString(); }
public static List <byte> TransformTwoDimensionalByteArrayToList(byte[,] arr) { if (arr == null) { throw new NullReferenceException("Array is null"); } List <byte> byteList = arr.Cast <byte>().ToList(); return(byteList); }
/// <summary> /// een afbeelding van Matlab met de beroepmde differentiaalvergelijking die het logo /// van Matlab weergeeft plotten met opgegeven maasaantal /// </summary> /// <param name="gridSize">maasaantal</param> public void UpdateGraphic(double gridSize) { object[] ans = createImage.GimmePeaks(3, gridSize); int width = (int)((double[, ])ans[1])[0, 0]; int height = (int)((double[, ])ans[2])[0, 0]; byte[,] mlImg = (byte[, ])ans[0]; DirectBitmap _dbmGraphic = new DirectBitmap(width, height); byte[] img = mlImg.Cast <byte>().ToArray(); _dbmGraphic.SetBytes(img); pbGraph.Image = _dbmGraphic.Bitmap; }
private byte[] ConvertArray(byte[,] twoDimensionArray) { return(twoDimensionArray.Cast <byte>().ToArray()); }
public void MirrorArray2D_HorizontalMirroring_AsExpected(byte[,] source, byte[,] expected) { source.MirrorArray2D(MirrorOperation.Horizontal); CollectionAssert.AreEqual(source.Cast <byte>(), expected.Cast <byte>()); }
public static bool IsEqual(this byte[,] current, byte[,] compare) { return(current?.Rank == compare?.Rank && Enumerable.Range(0, current.Rank).All(dimension => current.GetLength(dimension) == compare.GetLength(dimension)) && current.Cast <byte>().SequenceEqual(compare.Cast <byte>())); }
private double[] ConvertImage(byte[,] image) { return(image.Cast <byte>().Select(v => v / 255.0).ToArray()); }
private static int ValueCounter(byte[,] input) { return(input.Cast <byte>().Distinct().Count()); }
public void RotateArray2D_Left_AsExpected(byte[,] source, byte[,] expected) { source.RotateArray2D(RotationOperation.Left); CollectionAssert.AreEqual(source.Cast <byte>(), expected.Cast <byte>()); }
public void TransposeArray2D_AsExpected(byte[,] source, byte[,] expected) { source.TransposeArray2D(); CollectionAssert.AreEqual(source.Cast <byte>(), expected.Cast <byte>()); }