Ejemplo n.º 1
0
    /// <summary>
    /// Splits and combines images channels
    /// </summary>
    private static void SplitAndCombineChannels()
    {
        using (var reader = ImageReader.Create("../../../../_Input/Chicago.jpg"))
            using (var channelSplitter = new RgbChannelSplitter())
                using (var brightnessR = new Brightness(0.1f))
                    using (var brightnessG = new Brightness(-0.05f))
                        using (var brightnessB = new Brightness(0.2f))
                            using (var channelCombiner = new RgbChannelCombiner())
                                using (var writer = ImageWriter.Create("../../../../_Output/SplitAndCombineChannels.png"))
                                {
                                    reader.Receivers.Add(channelSplitter);

                                    channelCombiner.R = channelSplitter.R + brightnessR;
                                    channelCombiner.G = channelSplitter.G + brightnessG;
                                    channelCombiner.B = channelSplitter.B + brightnessB;

                                    Pipeline.Run(channelCombiner + writer);
                                }
    }
    /// <summary>
    /// Swaps channels
    /// </summary>
    private static void SwapChannelsMemoryFriendly()
    {
        ////                         /-- (R) ------- (R)--\
        ////                        /                      \
        //// reader --->  splitter  ---- (G) --\ /-- (B)----  combiner  ---> writer
        ////                        \           X          /
        ////                         \-- (B) --/ \-- (G)--/
        using (var reader = ImageReader.Create("../../../../_Input/Chicago.jpg"))
            using (var splitter = new RgbChannelSplitter())
                using (var combiner = new RgbChannelCombiner())
                    using (var writer = ImageWriter.Create("../../../../_Output/SwapChannelsMemoryFriendly.jpg"))
                    {
                        reader.Receivers.Add(splitter);

                        combiner.R = splitter.R;
                        combiner.G = splitter.B;
                        combiner.B = splitter.G;

                        combiner.Receivers.Add(writer);

                        Pipeline.Run(combiner);
                    }
    }