public void Grayscale_mode_CorrectProcessor <T>(TestType <T> testType, GrayscaleMode mode) where T : IImageProcessor { this.operations.Grayscale(mode); this.Verify <T>(); }
/// <summary> /// Applies grayscale toning to the image with the given <see cref="GrayscaleMode"/>. /// </summary> /// <typeparam name="TPixel">The pixel format.</typeparam> /// <param name="source">The image this method extends.</param> /// <param name="mode">The formula to apply to perform the operation.</param> /// <returns>The <see cref="Image{TPixel}"/>.</returns> public static IImageProcessingContext <TPixel> Grayscale <TPixel>(this IImageProcessingContext <TPixel> source, GrayscaleMode mode) where TPixel : struct, IPixel <TPixel> => Grayscale(source, mode, 1F);
/// <summary> /// Applies grayscale toning to the image with the given <see cref="GrayscaleMode"/> using the given amount. /// </summary> /// <typeparam name="TPixel">The pixel format.</typeparam> /// <param name="source">The image this method extends.</param> /// <param name="mode">The formula to apply to perform the operation.</param> /// <param name="amount">The proportion of the conversion. Must be between 0 and 1.</param> /// <returns>The <see cref="Image{TPixel}"/>.</returns> public static IImageProcessingContext <TPixel> Grayscale <TPixel>(this IImageProcessingContext <TPixel> source, GrayscaleMode mode, float amount) where TPixel : struct, IPixel <TPixel> { IImageProcessor <TPixel> processor = mode == GrayscaleMode.Bt709 ? (IImageProcessor <TPixel>) new GrayscaleBt709Processor <TPixel>(amount) : new GrayscaleBt601Processor <TPixel>(1F); source.ApplyProcessor(processor); return(source); }
/// <summary> /// Applies Grayscale toning to the image. /// </summary> /// <typeparam name="TColor">The pixel format.</typeparam> /// <param name="source">The image this method extends.</param> /// <param name="mode">The formula to apply to perform the operation.</param> /// <returns>The <see cref="Image{TColor}"/>.</returns> public static Image <TColor> Grayscale <TColor>(this Image <TColor> source, GrayscaleMode mode = GrayscaleMode.Bt709) where TColor : struct, IPackedPixel, IEquatable <TColor> { return(Grayscale(source, source.Bounds, mode)); }
/// <summary> /// Applies Grayscale toning to the image. /// </summary> /// <typeparam name="TColor">The pixel format.</typeparam> /// <param name="source">The image this method extends.</param> /// <param name="rectangle"> /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter. /// </param> /// <param name="mode">The formula to apply to perform the operation.</param> /// <returns>The <see cref="Image{TColor}"/>.</returns> public static Image <TColor> Grayscale <TColor>(this Image <TColor> source, Rectangle rectangle, GrayscaleMode mode = GrayscaleMode.Bt709) where TColor : struct, IPackedPixel, IEquatable <TColor> { IImageProcessor <TColor> processor = mode == GrayscaleMode.Bt709 ? (IImageProcessor <TColor>) new GrayscaleBt709Processor <TColor>() : new GrayscaleBt601Processor <TColor>(); return(source.Apply(rectangle, processor)); }
/// <summary> /// Applies Grayscale toning to the image. /// </summary> /// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam> /// <param name="source">The image this method extends.</param> /// <param name="rectangle"> /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter. /// </param> /// <param name="mode">The formula to apply to perform the operation.</param> /// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns> public static Image <TColor, TPacked> Grayscale <TColor, TPacked>(this Image <TColor, TPacked> source, Rectangle rectangle, GrayscaleMode mode = GrayscaleMode.Bt709) where TColor : struct, IPackedPixel <TPacked> where TPacked : struct { IImageFilteringProcessor <TColor, TPacked> processor = mode == GrayscaleMode.Bt709 ? (IImageFilteringProcessor <TColor, TPacked>) new GrayscaleBt709Processor <TColor, TPacked>() : new GrayscaleBt601Processor <TColor, TPacked>(); return(source.Process(rectangle, processor)); }
public void ApplyGrayscaleFilter <TPixel>(TestImageProvider <TPixel> provider, GrayscaleMode value) where TPixel : struct, IPixel <TPixel> { provider.RunValidatingProcessorTest(x => x.Grayscale(value), value); }
/// <summary> /// Applies grayscale toning to the image with the given <see cref="GrayscaleMode"/>. /// </summary> /// <param name="source">The image this method extends.</param> /// <param name="mode">The formula to apply to perform the operation.</param> /// <returns>The <see cref="IImageProcessingContext"/>.</returns> public static IImageProcessingContext Grayscale(this IImageProcessingContext source, GrayscaleMode mode) => Grayscale(source, mode, 1F);
/// <summary> /// Applies grayscale toning to the image with the given <see cref="GrayscaleMode"/> using the given amount. /// </summary> /// <param name="source">The image this method extends.</param> /// <param name="mode">The formula to apply to perform the operation.</param> /// <param name="amount">The proportion of the conversion. Must be between 0 and 1.</param> /// <returns>The <see cref="IImageProcessingContext"/>.</returns> public static IImageProcessingContext Grayscale(this IImageProcessingContext source, GrayscaleMode mode, float amount) { IImageProcessor processor = mode == GrayscaleMode.Bt709 ? (IImageProcessor) new GrayscaleBt709Processor(amount) : new GrayscaleBt601Processor(1F); source.ApplyProcessor(processor); return(source); }
public void ImageShouldApplyGrayscaleFilterAll <TPixel>(TestImageProvider <TPixel> provider, GrayscaleMode value) where TPixel : struct, IPixel <TPixel> { using (Image <TPixel> image = provider.GetImage()) { image.Grayscale(value); byte[] data = new byte[3]; foreach (TPixel p in image.Pixels) { p.ToXyzBytes(data, 0); Assert.Equal(data[0], data[1]); Assert.Equal(data[1], data[2]); } image.DebugSave(provider, value.ToString()); } }
public void ImageShouldApplyGrayscaleFilterInBox <TPixel>(TestImageProvider <TPixel> provider, GrayscaleMode value) where TPixel : struct, IPixel <TPixel> { using (Image <TPixel> source = provider.GetImage()) using (Image <TPixel> image = new Image <TPixel>(source)) { Rectangle rect = new Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2); image.Grayscale(rect, value) .DebugSave(provider, value.ToString()); // Let's draw identical shapes over the greyed areas and ensure that it didn't change the outer area image.Fill(NamedColors <TPixel> .HotPink, rect); source.Fill(NamedColors <TPixel> .HotPink, rect); ImageComparer.CheckSimilarity(image, source); } }
public void ImageShouldApplyGrayscaleFilterInBox <TPixel>(TestImageProvider <TPixel> provider, GrayscaleMode value) where TPixel : struct, IPixel <TPixel> { using (Image <TPixel> source = provider.GetImage()) using (var image = new Image <TPixel>(source)) { var bounds = new Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2); image.Grayscale(value, bounds) .DebugSave(provider, value.ToString()); ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); } }
/// <summary> /// Applies Grayscale toning to the image. /// </summary> /// <typeparam name="TPixel">The pixel format.</typeparam> /// <param name="source">The image this method extends.</param> /// <param name="mode">The formula to apply to perform the operation.</param> /// <returns>The <see cref="Image{TPixel}"/>.</returns> public static Image <TPixel> Grayscale <TPixel>(this Image <TPixel> source, GrayscaleMode mode) where TPixel : struct, IPixel <TPixel> { return(Grayscale(source, mode, source.Bounds)); }
/// <summary> /// /// </summary> /// <param name="image"></param> /// <returns></returns> public override Image Apply(Image image) { GetParams(fm); if (!(image is Image)) { return(image); } Bitmap dst = AddinUtils.CloneImage(image) as Bitmap; HslFilterMode HslFilterMode = (HslFilterMode)Params["HslFilterMode"].Value; GrayscaleMode grayscaleMode = (GrayscaleMode)Params["GrayscaleMode"].Value; int hueValue = (int)Params["HslHue"].Value; float satValue = (float)Params["HslSaturation"].Value; float lumValue = (float)Params["HslLuminance"].Value; float tolValue = (float)Params["HslTolerance"].Value; float factor_n = 1 - tolValue / 100; float factor_p = 1 + tolValue / 100; // // your filter codes begin // Accord.Imaging.Filters.HSLFiltering filter = new Accord.Imaging.Filters.HSLFiltering(); filter.Hue = new Accord.IntRange((int)Math.Round(hueValue * factor_n), (int)Math.Round(hueValue * factor_p)); filter.Saturation = new Accord.Range(satValue * factor_n, satValue * factor_p); filter.Luminance = new Accord.Range(lumValue * factor_n, lumValue * factor_p); //filter.FillColor = new Accord.Imaging.HSL( hueValue, satValue, lumValue ); //filter.FillOutsideRange = false; filter.FillColor = new Accord.Imaging.HSL(hueValue, 0.0f, lumValue); filter.FillOutsideRange = true; // // your filter codes end // //dst = AddinUtils.ProcessImage( filter, dst, false ); dst = filter.Apply(dst); dst = Accord.Imaging.Image.Clone(dst as Bitmap, PixelFormat.Format32bppArgb); Accord.Imaging.UnmanagedImage uimg = Accord.Imaging.UnmanagedImage.FromManagedImage(dst); Color fc = filter.FillColor.ToRGB().Color; for (int y = 0; y < uimg.Height; y++) { for (int x = 0; x < uimg.Width; x++) { if (uimg.GetPixel(x, y) == fc) { uimg.SetPixel(x, y, Color.Transparent); } } } dst = uimg.ToManagedImage(); IAddin gfilter = Host.Effects["Grayscale"]; Dictionary <string, ParamItem> oldParams = gfilter.Params; object data = null; gfilter.Command(AddinCommand.InitParams, out data, new Dictionary <string, object>() { { "GrayscaleMode", grayscaleMode } } ); var gimg = gfilter.Apply(image); gfilter.Command(AddinCommand.SetParams, out data, oldParams); using (var g = Graphics.FromImage(gimg)) { g.DrawImage(dst, 0, 0, dst.Width, dst.Height); } dst = gimg as Bitmap; AddinUtils.CloneExif(image, dst); return(dst); }
public void Grayscale_mode_rect_CorrectProcessor <T>(TestType <T> testType, GrayscaleMode mode) where T : IImageProcessor <Rgba32> { this.operations.Grayscale(mode, this.rect); this.Verify <T>(this.rect); }
/// <summary> /// Applies grayscale toning to the image. /// </summary> /// <param name="source">The image this method extends.</param> /// <param name="mode">The formula to apply to perform the operation.</param> /// <param name="rectangle"> /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter. /// </param> /// <returns>The <see cref="IImageProcessingContext"/>.</returns> public static IImageProcessingContext Grayscale(this IImageProcessingContext source, GrayscaleMode mode, Rectangle rectangle) => Grayscale(source, mode, 1F, rectangle);
public void ImageShouldApplyGrayscaleFilterAll <TPixel>(TestImageProvider <TPixel> provider, GrayscaleMode value) where TPixel : struct, IPixel <TPixel> { using (Image <TPixel> image = provider.GetImage()) { image.Mutate(x => x.Grayscale(value)); var rgb = default(Rgb24); System.Span <TPixel> span = image.Frames.RootFrame.GetPixelSpan(); for (int i = 0; i < span.Length; i++) { span[i].ToRgb24(ref rgb); Assert.Equal(rgb.R, rgb.B); Assert.Equal(rgb.B, rgb.G); } image.DebugSave(provider, value.ToString()); } }
/// <summary> /// Applies Grayscale toning to the image. /// </summary> /// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam> /// <param name="source">The image this method extends.</param> /// <param name="mode">The formula to apply to perform the operation.</param> /// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns> public static Image <TColor, TPacked> Grayscale <TColor, TPacked>(this Image <TColor, TPacked> source, GrayscaleMode mode = GrayscaleMode.Bt709) where TColor : struct, IPackedPixel <TPacked> where TPacked : struct { return(Grayscale(source, source.Bounds, mode)); }