/// <summary>
    /// Adjusts brightness modifying lightness channel of Lab color space
    /// </summary>
    private static void AdjustLightnessLab()
    {
        using (var lChannel = new Bitmap())
            using (var aChannel = new Bitmap())
                using (var bChannel = new Bitmap())
                {
                    using (var reader = ImageReader.Create("../../../../_Input/Chicago.jpg"))
                        using (var labConverter = new ColorConverter(PixelFormat.Format24bppLab))
                            using (var splitter = new LabChannelSplitter())
                            {
                                splitter.L = lChannel;
                                splitter.A = aChannel;
                                splitter.B = bChannel;

                                Pipeline.Run(reader + labConverter + splitter);
                            }

                    lChannel.ColorAdjustment.Brightness(brightnessAmount);

                    using (var combiner = new LabChannelCombiner())
                        using (var rgbConverter = new ColorConverter(PixelFormat.Format24bppRgb))
                            using (var writer = ImageWriter.Create("../../../../_Output/AdjustLightnessLab.jpg"))
                            {
                                combiner.L = lChannel;
                                combiner.A = aChannel;
                                combiner.B = bChannel;

                                rgbConverter.DestinationProfile = ColorProfile.FromSrgb();

                                Pipeline.Run(combiner + rgbConverter + writer);
                            }
                }
    }
    /// <summary>
    /// Tints using Lab color space
    /// </summary>
    private static void TintUsingLab(RgbColor color)
    {
        // You can hardcode a = 20, b = 60 for sepia effect
        var labColor = RgbToLabColor(color);
        var a        = labColor.A;
        var b        = labColor.B;

        using (var lChannel = new Bitmap())
        {
            // Convert to Lab color space and get lightness channel
            using (var reader = ImageReader.Create("../../../../_Input/Chicago.jpg"))
                using (var labConverter = new ColorConverter(PixelFormat.Format24bppLab))
                    using (var splitter = new LabChannelSplitter())
                    {
                        splitter.L = lChannel;

                        Pipeline.Run(reader + labConverter + splitter);
                    }

            // Create a and b channels, combine with lightness channel and convert to RGB color space
            using (var combiner = new LabChannelCombiner())
                using (var aChannel = new Bitmap(lChannel.Width, lChannel.Height, PixelFormat.Format8bppGrayscale,
                                                 new GrayscaleColor((byte)(a + 127))))
                    using (var bChannel = new Bitmap(lChannel.Width, lChannel.Height, PixelFormat.Format8bppGrayscale,
                                                     new GrayscaleColor((byte)(b + 127))))
                        using (var rgbConverter = new ColorConverter(PixelFormat.Format24bppRgb))
                            using (var writer = ImageWriter.Create("../../../../_Output/TintUsingLab_" + color.ToString() + ".jpg"))
                            {
                                combiner.L = lChannel;
                                combiner.A = aChannel;
                                combiner.B = bChannel;

                                rgbConverter.DestinationProfile = ColorProfile.FromSrgb();

                                Pipeline.Run(combiner + rgbConverter + writer);
                            }
        }
    }
Example #3
0
    /// <summary>
    /// Adjusts hue modifying [a] component of Lab color space
    /// </summary>
    private static void AdjustColorsUsingLab()
    {
        // L - lightness
        // a - green/red
        // b - blue/yellow

        using (var lChannel = new Bitmap())
            using (var aChannel = new Bitmap())
                using (var bChannel = new Bitmap())
                {
                    using (var reader = ImageReader.Create("../../../../_Input/Chicago.jpg"))
                        using (var labConverter = new ColorConverter(PixelFormat.Format24bppLab))
                            using (var splitter = new LabChannelSplitter())
                            {
                                splitter.L = lChannel;
                                splitter.A = aChannel;
                                splitter.B = bChannel;

                                Pipeline.Run(reader + labConverter + splitter);
                            }

                    // Increase yellow
                    bChannel.ColorAdjustment.ChannelBalance(new float[] { 0.1f }, new float[] { 1f });

                    using (var combiner = new LabChannelCombiner())
                        using (var rgbConverter = new ColorConverter(PixelFormat.Format24bppRgb))
                            using (var writer = ImageWriter.Create("../../../../_Output/AdjustColorsUsingLab.jpg"))
                            {
                                combiner.L = lChannel;
                                combiner.A = aChannel;
                                combiner.B = bChannel;

                                rgbConverter.DestinationProfile = ColorProfile.FromSrgb();

                                Pipeline.Run(combiner + rgbConverter + writer);
                            }
                }
    }
    /// <summary>
    /// Corrects tone modifying lightness component of Lab color space
    /// </summary>
    private static void AdjustLevelsUsingLab()
    {
        // L - lightness
        // a - green/red
        // b - blue/yellow

        using (var lChannel = new Bitmap())
            using (var aChannel = new Bitmap())
                using (var bChannel = new Bitmap())
                {
                    using (var reader = ImageReader.Create("../../../../_Input/Chicago.jpg"))
                        using (var labConverter = new ColorConverter(PixelFormat.Format24bppLab))
                            using (var splitter = new LabChannelSplitter())
                            {
                                splitter.L = lChannel;
                                splitter.A = aChannel;
                                splitter.B = bChannel;

                                Pipeline.Run(reader + labConverter + splitter);
                            }

                    lChannel.ColorAdjustment.Levels(0.03F, 0.9F, 0.05F, 1.5F, 0.7F, HistogramMode.Sum);

                    using (var combiner = new LabChannelCombiner())
                        using (var rgbConverter = new ColorConverter(PixelFormat.Format24bppRgb))
                            using (var writer = ImageWriter.Create("../../../../_Output/AdjustLevelsUsingLab.jpg"))
                            {
                                combiner.L = lChannel;
                                combiner.A = aChannel;
                                combiner.B = bChannel;

                                rgbConverter.DestinationProfile = ColorProfile.FromSrgb();

                                Pipeline.Run(combiner + rgbConverter + writer);
                            }
                }
    }