Beispiel #1
0
 public void BlurBoxes(BBOXES boxes)
 {
     foreach (var rect in boxes.ToMagikGeometry())
     {
         if (rect.X >= 0 && rect.Y >= 0 && rect.Width > 0 && rect.Height > 0)
         {
             using (var crop_clone = new MagickImage(_current.ToByteArray()))
             {
                 crop_clone.Crop(rect);
                 crop_clone.Blur();
                 _current.Composite(crop_clone, rect.X, rect.Y, CompositeOperator.Over);
             }
         }
     }
 }
Beispiel #2
0
        private static void ApplyAugmentations(AImage factory, LocalAnnotationContext localContext, AugmentationContext context, AugmentationOptions options)
        {
            var boxes = new BBOXES(localContext.Image.Annotations.Where(a => context.Classes.ContainsKey(a.Label)), factory.Width, factory.Height);

            var store = new Action <AImage, string>((ifac, ann) =>
            {
                var(imgName, lblName) = context.GetNextAugFileNames();
                ifac.Write(imgName);
                File.WriteAllText(lblName, ann);
            });
            var storeWithBB = new Action <AImage, BBOXES>((ifac, bb) =>
            {
                var(imgName, lblName) = context.GetNextAugFileNames();
                ifac.Write(imgName);
                File.WriteAllText(lblName, bb.ToString());
            });
            var app = new Action <AImage, Func <AImage, Action> >((img, gf) =>
            {
                gf(img).Invoke();
                store(img, localContext.SourceAnnotationText);
                img.Reset();
            });

            if (options.Blur)
            {
                app.Invoke(factory, im => im.Blur);
            }
            if (options.Grayscale)
            {
                app.Invoke(factory, im => im.Grayscale);
            }
            if (options.Moonlight)
            {
                app.Invoke(factory, im => im.Moonlight);
            }
            if (options.Noise)
            {
                app.Invoke(factory, im => im.Noise);
            }
            if (options.Sepia)
            {
                app.Invoke(factory, im => im.SepiaTone);
            }
            if (options.Charcoal)
            {
                app.Invoke(factory, im => im.Charcoal);
            }
            if (options.LinesNoise)
            {
                app.Invoke(factory, im => im.LineNoize);
            }
            if (options.Sin)
            {
                app.Invoke(factory, im => im.FSin);
            }

            if (options.Mirrors)
            {
                var horizontallAnn = new StringBuilder();
                var verticalAnn    = new StringBuilder();
                localContext.Image.Annotations.Apply(a =>
                {
                    if (context.Classes.ContainsKey(a.Label))
                    {
                        horizontallAnn.Append($"{context.Classes[a.Label]} {(1.0f - a.Cx).ConvertToString()} {a.Cy.ConvertToString()} {a.Width.ConvertToString()} {a.Height.ConvertToString()}");
                        horizontallAnn.Append("\n");
                        verticalAnn.Append($"{context.Classes[a.Label]} {a.Cx.ConvertToString()} {(1 - a.Cy).ConvertToString()} {a.Width.ConvertToString()} {a.Height.ConvertToString()}");
                        verticalAnn.Append("\n");
                    }
                });
                factory.Flop();
                store(factory, horizontallAnn.ToString());
                factory.Reset();
                factory.Flip();
                store(factory, verticalAnn.ToString());
                factory.Reset();
            }
            if (options.BBoxBlur)
            {
                factory.BlurBoxes(boxes);
                storeWithBB(factory, boxes);
                factory.Reset();
            }
        }