Skip to content

Instantly share code, notes, and snippets.

@caioketo
Created November 7, 2013 13:19
Show Gist options
  • Save caioketo/7354455 to your computer and use it in GitHub Desktop.
Save caioketo/7354455 to your computer and use it in GitHub Desktop.
Image processing
string path = @"C:\AC\test.png";
Bitmap image = (Bitmap)Bitmap.FromFile(path);
Grayscale filter = new Grayscale(0.2125, 0.7154, 0.0721);
// apply the filter
image = filter.Apply(image);
image.Save("result0.png");
DifferenceEdgeDetector filter1 = new DifferenceEdgeDetector();
// apply the filter
filter1.ApplyInPlace(image);
image.Save("result1.png");
Dilatation filter2 = new Dilatation();
// apply the filter
filter2.Apply(image);
image.Save("result2.png");
Threshold filter3 = new Threshold(150);
// apply the filter
filter3.ApplyInPlace(image);
image.Save("result3.png");
ConnectedComponentsLabeling filter4 = new ConnectedComponentsLabeling();
// apply the filter
Bitmap newImage = filter4.Apply(image);
// check objects count
int objectCount = filter4.ObjectCount;
MessageBox.Show(objectCount.ToString());
image.Save("result4.png");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment