private void ApplyFilter(FilterType filterType, int windowSize = 0)
        {
            Invoke(new ArgUtils.Action(delegate
            {
                pictureBox2.Image = null;
            }));

            IFilter filter = null;
            IBinarization binarization = null;

            switch (filterType)
            {
                case FilterType.AdaptiveBinarization:
                    binarization = new AdaptiveBinarizatoinFilter(UpdateProgtessBar);
                    break;
                case FilterType.BinarizationByOtsu:
                    binarization = new BinarizationByOtsu(UpdateProgtessBar);
                    break;
                case FilterType.Gaus:
                    filter = new GausFilter(windowSize, false, UpdateProgtessBar);
                    break;
                case FilterType.Median:
                    filter = new Filters.MedianFilter(windowSize, false, UpdateProgtessBar);
                    break;
                case FilterType.Gray:
                    filter = new GrayFilter();
                    break;
                case FilterType.Edge:
                    filter = new Filters.EdgeFilter();
                    break;
                case FilterType.Sharpen:
                    filter = new SharpenFilter();
                    break;
            }

            var bitmap = GetInitialBitmap();
            Bitmap result = null;

            Invoke(new ArgUtils.Action(delegate
            {
                progressBar1.Value = 0;
            }));

            if (filter != null)
            {
                result = filter.GetFilteredImage(bitmap);
            }
            else if (binarization != null)
            {
                result = binarization.GetBinaryImage(bitmap);
            }

            Invoke(new ArgUtils.Action(delegate
            {
                if (progressBar1.Value < 100)
                {
                    progressBar1.Value = 100;
                }
                pictureBox2.Image = result;
            }));
        }
Ejemplo n.º 2
0
        private void ApplyFilter(FilterType filterType, int windowSize = 0)
        {
            Invoke(new ArgUtils.Action(delegate
            {
                pictureBox2.Image = null;
            }));

            IFilter       filter       = null;
            IBinarization binarization = null;

            switch (filterType)
            {
            case FilterType.AdaptiveBinarization:
                binarization = new AdaptiveBinarizatoinFilter(UpdateProgtessBar);
                break;

            case FilterType.BinarizationByOtsu:
                binarization = new BinarizationByOtsu(UpdateProgtessBar);
                break;

            case FilterType.Gaus:
                filter = new GausFilter(windowSize, false, UpdateProgtessBar);
                break;

            case FilterType.Median:
                filter = new Filters.MedianFilter(windowSize, false, UpdateProgtessBar);
                break;

            case FilterType.Gray:
                filter = new GrayFilter();
                break;

            case FilterType.Edge:
                filter = new Filters.EdgeFilter();
                break;

            case FilterType.Sharpen:
                filter = new SharpenFilter();
                break;
            }

            var    bitmap = GetInitialBitmap();
            Bitmap result = null;

            Invoke(new ArgUtils.Action(delegate
            {
                progressBar1.Value = 0;
            }));

            if (filter != null)
            {
                result = filter.GetFilteredImage(bitmap);
            }
            else if (binarization != null)
            {
                result = binarization.GetBinaryImage(bitmap);
            }

            Invoke(new ArgUtils.Action(delegate
            {
                if (progressBar1.Value < 100)
                {
                    progressBar1.Value = 100;
                }
                pictureBox2.Image = result;
            }));
        }