Beispiel #1
0
 public static void threshold(string image_path, string output_path, int brightness = 20, int contrast = 20, int posterize = 2)
 {
     using (MagickImage image = new MagickImage(image_path)) {
         image.BrightnessContrast(brightness, contrast);
         image.ColorSpace = ColorSpace.Gray;
         image.Posterize(posterize);
         image.Normalize();
         image.Write(output_path);
     }
 }
Beispiel #2
0
 private void ExecutePosterize(XmlElement element, MagickImage image)
 {
   Hashtable arguments = new Hashtable();
   foreach (XmlAttribute attribute in element.Attributes)
   {
     if (attribute.Name == "channels")
       arguments["channels"] = Variables.GetValue<Channels>(attribute);
     else if (attribute.Name == "levels")
       arguments["levels"] = Variables.GetValue<Int32>(attribute);
     else if (attribute.Name == "method")
       arguments["method"] = Variables.GetValue<DitherMethod>(attribute);
   }
   if (OnlyContains(arguments, "levels"))
     image.Posterize((Int32)arguments["levels"]);
   else if (OnlyContains(arguments, "levels", "channels"))
     image.Posterize((Int32)arguments["levels"], (Channels)arguments["channels"]);
   else if (OnlyContains(arguments, "levels", "method"))
     image.Posterize((Int32)arguments["levels"], (DitherMethod)arguments["method"]);
   else if (OnlyContains(arguments, "levels", "method", "channels"))
     image.Posterize((Int32)arguments["levels"], (DitherMethod)arguments["method"], (Channels)arguments["channels"]);
   else
     throw new ArgumentException("Invalid argument combination for 'posterize', allowed combinations are: [levels] [levels, channels] [levels, method] [levels, method, channels]");
 }
    public void Test_Posterize()
    {
      using (MagickImage image = new MagickImage(Files.FujiFilmFinePixS1ProJPG))
      {
        image.Posterize(5);

#if Q8
        ColorAssert.AreEqual(new MagickColor("#3f7fbf"), image, 300, 150);
        ColorAssert.AreEqual(new MagickColor("#3f3f7f"), image, 495, 270);
        ColorAssert.AreEqual(new MagickColor("#3f3f3f"), image, 445, 255);
#elif Q16 || Q16HDRI
        ColorAssert.AreEqual(new MagickColor("#3fff7fffbfff"), image, 300, 150);
        ColorAssert.AreEqual(new MagickColor("#3fff3fff7fff"), image, 495, 270);
        ColorAssert.AreEqual(new MagickColor("#3fff3fff3fff"), image, 445, 255);
#else
#error Not implemented!
#endif
      }
    }