1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| private void traite_Click(object sender, EventArgs e)
{
Bitmap img = (Bitmap)pictureBox2.Image;
//Bitmap img = new Bitmap(pictureBox2.Image,pictureBox2.Image.Size);
AForge.Imaging.Image.SetGrayscalePalette(img);
int nbr = 0;
// collect statistics
//HorizontalIntensityStatistics his = new HorizontalIntensityStatistics(img);
ImageStatistics his = new ImageStatistics(img);
// get gray histogram (for grayscale image)
Histogram histogram = his.Gray;
// output some histogram's information
label4.Text = "Valeur medianne histogramme : " + (histogram.Median);
label5.Text = "Valeur minimale histogramme : " + (histogram.Min);
label6.Text = "Valeur maximale histogramme : " + (histogram.Max);
int seuil = histogram.Max - histogram.Min;
Threshold filtre = new Threshold(seuil);
filtre.ApplyInPlace(img);
BlobCounter blobCount = new BlobCounter();
blobCount.ProcessImage(img);
Blob[] blobs = blobCount.GetObjectsInformation();
SimpleShapeChecker shapechecker = new SimpleShapeChecker();
for (int i = 0, n = blobs.Length; i < n; i++)
{
List<IntPoint> edge = blobCount.GetBlobsEdgePoints(blobs[i]);
AForge.Point centre;
float radius;
if (shapechecker.IsCircle(edge, out centre, out radius) && radius < 17.5)
{
nbr = nbr + 1;
}
}
pictureBox3.Image = (Bitmap)img.Clone();
res.Text = Convert.ToString("Il y a " + nbr + " colonies");
} |
Partager