Exemplo n.º 1
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();
            }
        }
Exemplo n.º 2
0
 private void ExecuteLinearStretch(XmlElement element, MagickImage image)
 {
   Percentage blackPoint_ = Variables.GetValue<Percentage>(element, "blackPoint");
   Percentage whitePoint_ = Variables.GetValue<Percentage>(element, "whitePoint");
   image.LinearStretch(blackPoint_, whitePoint_);
 }
Exemplo n.º 3
0
    public void Test_LinearStretch()
    {
      using (MagickImage image = new MagickImage(Files.FujiFilmFinePixS1ProJPG))
      {
        image.Scale(100, 100);

        image.LinearStretch((Percentage)1, (Percentage)1);
        using (MemoryStream memStream = new MemoryStream())
        {
          image.Format = MagickFormat.Histogram;
          image.Write(memStream);
          memStream.Position = 0;

          using (MagickImage histogram = new MagickImage(memStream))
          {
#if Q8
            ColorAssert.AreEqual(MagickColors.Red, histogram, 66, 11);
            ColorAssert.AreEqual(MagickColors.Lime, histogram, 95, 122);
            ColorAssert.AreEqual(MagickColors.Blue, histogram, 204, 80);
#elif Q16 || Q16HDRI
            ColorAssert.AreEqual(MagickColors.Red, histogram, 34, 182);
            ColorAssert.AreEqual(MagickColors.Lime, histogram, 122, 193);
            ColorAssert.AreEqual(MagickColors.Blue, histogram, 210, 194);
#else
#error Not implemented!
#endif
          }
        }

        image.LinearStretch((Percentage)10, (Percentage)90);
        using (MemoryStream memStream = new MemoryStream())
        {
          image.Format = MagickFormat.Histogram;
          image.Write(memStream);
          memStream.Position = 0;

          using (MagickImage histogram = new MagickImage(memStream))
          {
#if Q8
            ColorAssert.AreEqual(MagickColors.Red, histogram, 103, 183);
            ColorAssert.AreEqual(MagickColors.Lime, histogram, 147, 188);
            ColorAssert.AreEqual(MagickColors.Blue, histogram, 194, 190);
#elif Q16 || Q16HDRI
            ColorAssert.AreEqual(MagickColors.Red, histogram, 221, 182);
            ColorAssert.AreEqual(MagickColors.Lime, histogram, 12, 183);
            ColorAssert.AreEqual(MagickColors.Blue, histogram, 45, 194);
#else
#error Not implemented!
#endif
          }
        }
      }
    }