Skip to content

Instantly share code, notes, and snippets.

@dg1an3
Created February 24, 2018 23:35
Show Gist options
  • Save dg1an3/275371651c009e072c6f5bc0535d970f to your computer and use it in GitHub Desktop.
Save dg1an3/275371651c009e072c6f5bc0535d970f to your computer and use it in GitHub Desktop.
C# Image Histogram
// for a 2D array of pixels with some pixel type
var pixels = new TPixel[100,100];
// turn into a sequence
var pixelSequence = pixels.Cast<TPixelType>();
// group the sequence and turn to a dictionary, with pixel values as key and bin count as value
var histo = pixelSequence.GroupBy(px => px).ToDictionary(grp => grp.Key, grp => grp.Count());
@dg1an3
Copy link
Author

dg1an3 commented Feb 24, 2018

quick and dirty histogram (not very efficient) from a 2D pixel array

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment