private void testToolStripMenuItem_Click(object sender, EventArgs e) { CellDescription[,] test = GrowCut.getCellsMap((Bitmap)pictureBox.Image, (Bitmap)drawBox.Image); GrowCut growCut = new GrowCut((Bitmap)pictureBox.Image.Clone(), test); growCut.evolution(updatePictureWithCells); }
private void updatePictureWithCells(CellDescription[,] cells) { //Bitmap image = (Bitmap)pictureBox.Image.Clone(); //Parallel.For(0, image.Width, x => //{ // for (int y = 0; y < image.Height; y++) // { // if (cells[x, y].label == 1) // { // image.SetPixel(x, y, Color.Blue); // } else // { // image.SetPixel(x, y, Color.Red); // } // } //}); Bitmap resultImage = (Bitmap)pictureBox.Image.Clone(); for (int x = 0; x < resultImage.Width; x++) { { for (int y = 0; y < resultImage.Height; y++) { int[] currentPixel = GrowCut.colorToVector(resultImage.GetPixel(x, y)); if (cells[x, y].label == 1) { int blue = Math.Min(255, currentPixel[2] + 100); resultImage.SetPixel(x, y, Color.FromArgb(currentPixel[0], currentPixel[1], blue)); } else { int red = Math.Min(255, currentPixel[0] + 100); resultImage.SetPixel(x, y, Color.FromArgb(red, currentPixel[1], currentPixel[2])); } } } pictureBox.Image = resultImage; } }