public Image pixelImage() { var image = Image.FromFile(imageName + ".jpg"); using (var context = image.CreateUnsafeContext()) { for (var w = 0; w < context.Width; w++) { for (var h = 0; h < context.Height; h++) { BumpKit.UnsafeBitmapContext.Pixel pixel = context.GetRawPixel(w, h); if (pixel.Red >= 35 && pixel.Red <= 114 && pixel.Green >= 99 && pixel.Green <= 238 && pixel.Blue >= 83 && pixel.Blue <= 114) { context.SetPixel(w, h, Color.White); } else { context.SetPixel(w, h, Color.Black); } } } } image.Save(@"C:\Users\Alex\Documents\GitHub\AlgaeScore\AlgaeScore\AlgaeScore\bin\Debug\new.bmp", ImageFormat.Bmp); return(image); }
//private ImageTesting test1; public decimal scoreCalculator(Image image) { decimal white = whiteScore; decimal black = blackScore; //Get instance of new bitmap image. Image picture = image; //var picture = Bitmap.FromFile(image); using (var context = picture.CreateUnsafeContext()) { for (var w = 0; w < context.Width; w++) { for (var h = 0; h < context.Height; h++) { BumpKit.UnsafeBitmapContext.Pixel pixel = context.GetRawPixel(w, h); if (pixel.EqualsColor(Color.White)) { white++; } else if (pixel.EqualsColor(Color.Black)) { black++; } } } } //Formula for percentage // (count / totalcount) * 100); decimal score = Math.Floor((white / (white + black)) * 100); return(score); }
public string scoreCalculator() { decimal white = whiteScore; decimal black = blackScore; var picture = Bitmap.FromFile("~/Content/Images/new.bmp"); using (var context = picture.CreateUnsafeContext()) { for (var w = 0; w < context.Width; w++) { for (var h = 0; h < context.Height; h++) { BumpKit.UnsafeBitmapContext.Pixel pixel = context.GetRawPixel(w, h); if (pixel.EqualsColor(Color.White)) { white++; } else if (pixel.EqualsColor(Color.Black)) { black++; } } } } decimal score = Math.Floor((white / (white + black)) * 100); return(score.ToString()); }