Example #1
0
        public byte[] Enhance(string filename)
        {
            try
            {
                var buf = System.IO.File.ReadAllBytes(path + filename);
                img = new MagickImage();
                img.Read(buf);
                img.Enhance();

                return(img.ToByteArray());
            }
            catch
            {
                return(null);
            }
        }
Example #2
0
 public override MagickImage ApplyFilter(MagickImage image)
 {
     image.Enhance();
     return(image);
 }
        public MagickImage DoConversion(MagickImage input)
        {
            MagickImage output = new MagickImage();

            try
            {
                output = new MagickImage(input.Clone());

                foreach (OperationType optype in this.order)
                {
                    switch (optype)
                    {
                    case OperationType.BrightnessContrast:
                        if ((this.contrast != 0) || (this.brightness != 0))
                        {
                            output.BrightnessContrast((Percentage)brightness, (Percentage)contrast);
                        }
                        break;

                    case OperationType.Treshold:
                        if (do_treshold)
                        {
                            output.Threshold((Percentage)treshold);
                        }
                        break;

                    case OperationType.Gamma:
                        if (((double)gamma / 100) != 1.0)
                        {
                            output.GammaCorrect((double)gamma / 100);
                        }
                        break;

                    case OperationType.Enhance:
                        if (do_enhance)
                        {
                            output.Enhance();
                        }
                        break;

                    case OperationType.Sharpen:
                        if (do_sharpen)
                        {
                            output.Sharpen();
                        }
                        break;

                    case OperationType.NoiseFilter:
                        if (noise > 0)
                        {
                            output.ReduceNoise(noise);
                        }
                        break;

                    default:
                        break;
                    }
                }
            }
            catch (MagickCorruptImageErrorException e)
            {
                throw e;
            }
            return(output);
        }
Example #4
0
        private Bitmap processImgForScanning(Bitmap imgInput)
        {
            using (MemoryStream memstream = new MemoryStream())
            {
                imgInput.Save(memstream, ImageFormat.Tiff);
                MagickImage img = new MagickImage(memstream.ToArray());


                if (sharpen)
                {
                    img.Sharpen((int)sharpenIntX.Value, (int)sharpenIntY.Value, Channels.All);
                }

                if (autoGamma)
                {
                    img.AutoGamma();
                }

                if (enhance)
                {
                    img.Enhance();
                }

                if (contrast)
                {
                    img.Contrast();
                }

                if (autoLevel)
                {
                    img.AutoLevel();
                }

                if (autoOrient)
                {
                    img.AutoOrient();
                }

                if (despeckle)
                {
                    img.Despeckle();
                }


                if (medianFilter)
                {
                    img.MedianFilter((int)medianInt.Value);
                }

                if (unsharpmask)
                {
                    img.Unsharpmask(6.8, 4, 4, 0);
                }

                if (wtThreshold)
                {
                    img.LinearStretch((float)0.9, 0.1);
                    //img.WhiteThreshold((int)wtThresInt.Value);
                    //img.ReduceNoise();
                    //img.Grayscale(PixelIntensityMethod.Brightness);
                }

                if (invert)
                {
                    img.Negate();
                }

                return(img.ToBitmap());
            }
        }