private void ProcessImage() { try { if (bitmap == null) { throw new Exception("Chưa chọn ảnh nguồn"); } var opt = new SegmentOptions { ThreshHold = double.Parse(editNguong.EditValue.ToString()), MinSize = int.Parse(editMinSize.EditValue.ToString()) }; if (opt.MinSize < 0) { throw new Exception("Minsize phải >= 0"); } if (opt.ThreshHold < 0 || opt.ThreshHold > 50) { throw new Exception("Threshold phải lớn hơn hoặc bằng 0 và nhỏ hơn hoặc bằng 50"); } var newBm = bitmap.Clone(new Rectangle(0, 0, bitmap.Width, bitmap.Height), PixelFormat.Format24bppRgb); newBm = new AForge.Imaging.Filters.Sharpen().Apply(newBm); newBm = new GraphImageSegmentation(this, opt).Apply(newBm); picResult.Image = newBm; GC.Collect(); } catch (Exception exc) { MessageBox.Show(this, exc.Message, "Có lỗi xảy ra", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Hàm khởi tạo /// </summary> /// <param name="opt">Tham số truyền vào cho bộ lọc</param> public GraphImageSegmentation(ILogProvider logger, SegmentOptions opt) { this.threshold = opt.ThreshHold; this.minsize = opt.MinSize; _logger = logger; formats = new Dictionary <PixelFormat, PixelFormat> { [PixelFormat.Format24bppRgb] = PixelFormat.Format24bppRgb }; }