public int[] Calculate(Bitmap bitmap) { int[] lumininances = new int[256]; LockableBitmap lockableBitmap = new LockableBitmap(bitmap); lockableBitmap.LockBits(); try { for (int i = 0; i < lockableBitmap.Width; i++) { for (int j = 0; j < lockableBitmap.Height; j++) { byte brightness = lockableBitmap.GetPixel(i, j).Brightness(); lumininances[brightness]++; } } } finally { lockableBitmap.UnlockBits(); } return(lumininances); }
public Bitmap Process(Bitmap source, params IPerItemAlgorithm[] perItemAlgorithms) { LockableBitmap lockableBitmap = new LockableBitmap(source); lockableBitmap.LockBits(); try { foreach (IPerItemAlgorithm algorithm in perItemAlgorithms) { for (int x = 0; x < lockableBitmap.Width; x++) { for (int y = 0; y < lockableBitmap.Height; y++) { Color processedColor = algorithm.Execute(lockableBitmap.GetPixel(x, y)); lockableBitmap.SetPixel(x, y, processedColor); } } } } finally { lockableBitmap.UnlockBits(); } return(source); }
public double Calculate(Region region) { IEnumerable <int> averageColor = region.Infos.Select(e => new { source.GetPixel(e.Coords.X, e.Coords.Y).R, source.GetPixel(e.Coords.X, e.Coords.Y).G, source.GetPixel(e.Coords.X, e.Coords.Y).B }).Aggregate(new[] { 0, 0, 0 }, (tuple, element) => { tuple[0] += element.R; tuple[1] += element.G; tuple[2] += element.B; return(tuple); }).Select(e => e / region.Infos.Count); return(averageColor.Average()); }
private IPattern <double> RetrievePatternValue(LockableBitmap lockableBitmap) { List <double> patternValues = new List <double>(); for (int x = 0; x < lockableBitmap.Width; x++) { for (int y = 0; y < lockableBitmap.Height; y++) { Color processedColor = perItemAlgorithm .Execute(lockableBitmap.GetPixel(x, y)); patternValues.Add( ColorToBinary(processedColor)); } } return(new Pattern(patternValues.ToArray())); }
public LockableBitmapWrapper(LockableBitmap source) { if (source == null) { throw new ArgumentNullException("source"); } this.source = source; infos = new ScanInfo[source.Width, source.Height]; for (int y = 0; y < source.Height; y++) { for (int x = 0; x < source.Width; x++) { infos[x, y] = new ScanInfo(source.GetPixel(x, y), new Point(x, y)); } } }
private Aperture GenerateNext() { Aperture aperture = new Aperture { A1 = apertureSelectorR.Invoke(x - 1, y - 1, x, y, source), A2 = apertureSelectorR.Invoke(x, y - 1, x, y, source), A3 = apertureSelectorR.Invoke(x + 1, y - 1, x, y, source), A4 = apertureSelectorR.Invoke(x - 1, y, x, y, source), A5 = apertureSelectorR.Invoke(x + 1, y, x, y, source), A6 = apertureSelectorR.Invoke(x - 1, y + 1, x, y, source), A7 = apertureSelectorR.Invoke(x, y + 1, x, y, source), A8 = apertureSelectorR.Invoke(x + 1, y + 1, x, y, source), CurrentX = x, CurrentY = y, CurrentColor = source.GetPixel(x, y) }; return(aperture); }
public double Calculate(Region region) { return(region.Infos.Select( e => (int)source.GetPixel(e.Coords.X, e.Coords.Y).Brightness()) .Average()); }
public Color GetPixel(int x, int y) { return(source.GetPixel(x, y)); }