Welcome Guest! You need to login or register to make posts.

Notification

Icon
Error

Options
Go to last post Go to first unread
lauren@photoboothsupplyco.com  
#1 Posted : Sunday, November 19, 2017 1:32:09 PM(UTC)
lauren@photoboothsupplyco.com

Rank: Member

Groups: Member
Joined: 7/30/2017(UTC)
Posts: 18

Thanks: 7 times
Hi,

I am trying to apply a tint to a bitmap that has been processed through the GreenRemoval object but am being unsuccessful at it and was wondering if anyone could help me with it.

What I have so far is that I pass in a cv image into my method and then create a bitmap object from that. This image is the one with the green screen background. I then process that image via the GreenRemoval object. Next I try to apply a tint to the image and finally I draw that image onto a background image. If I do not apply the tint the image turns out perfect with the GreenRemoval process but when I try to apply the tint I only get the original image with the green removed with the tint applied but the background image is not present. I think what is happening is that I am losing the transparency when I apply the tint. Is there a way to apply the tint and keep the transparency so that when I draw that on top of the background image the background image is as intended and only the processed image has a tint on it?

I have posted the code that I have so far:

Code:

private void ProcessGreenScreen(string filename, cv.Image<Bgr, byte> img)
{
    try
    {
        // Do we have a valid green screen background?
        if (Globals.AppliedBackground != null)
        {
            // If so get a bitmap object from the cv image.
            using (Aurigma.GraphicsMill.Bitmap bmp = new Aurigma.GraphicsMill.Bitmap(img.Bitmap))
            {
                // Create a new greenscreen removal object.
                using (var GreenRemove = new GreenScreenRemoval())
                {
                    // Remove the green background from the image.
                    Aurigma.GraphicsMill.Bitmap bitmapNoGreen = GreenRemove.Apply((bmp));

                    // Do we need to apply a tint to the image?
                    if (Globals.FiltersEnabled && Globals.AppliedFilter != null && Globals.AppliedFilter.NoFilter == false)
                    {
                        // If so, send it to the method that applies the tint.
                        _cameraBase.TintedFilter(new RgbColor(Globals.AppliedFilter.Red, Globals.AppliedFilter.Green, Globals.AppliedFilter.Blue), ref bitmapNoGreen);
                    }

                    // Get the green screen background image filename.
                    string backgroundImage = Globals.GreenscreenFolder + "\\" + Globals.AppliedBackground.Filename;

                    // Create a bitmap object from the file.
                    using (var bckgrnd = new Aurigma.GraphicsMill.Bitmap(backgroundImage))
                    {
                        // Does the green screen background image need to be resized?
                        if (Globals.AppliedBackground.IsValidDimensions == false)
                        {
                            // If so, resize it now.
                            bckgrnd.Transforms.Resize(new Size((int)Globals.CameraDefaultWidth, (int)Globals.CameraDefaultHeight), ResizeInterpolationMode.Lanczos3, ResizeMode.ImageFill);
                        }

                        // Draw the image onto the background image.
                        bckgrnd.Draw(bitmapNoGreen, 0, 0, CombineMode.Alpha);

                        // Change the DPI of the image.
                        bckgrnd.DpiX = Globals.PrintDPI;
                        bckgrnd.DpiY = Globals.PrintDPI;

                        // Save the image as a jpg
                        var jpegSettings = new Aurigma.GraphicsMill.Codecs.JpegSettings();
                        jpegSettings.Quality = 90;
                        jpegSettings.UseSubsampling = false;
                        jpegSettings.IsProgressive = true;

                        bckgrnd.Save(filename, jpegSettings);
                    }
                }
            }
        }
        else
        {
            log.Debug("Green Screen Background not loaded");
        }
    }
    catch (Exception e)
    {
        log.Debug(e);
    }
}


And the code that actually applies the tint is as follows:

Code:

public void TintedFilter(RgbColor color, ref Aurigma.GraphicsMill.Bitmap bmp)
{
    if (bmp.ColorProfile == null)
    {
        bmp.ColorProfile = ColorProfile.FromSrgb();    
    }

    var labColor = RgbToLabColor(color);
    var a = labColor.A;
    var b = labColor.B;

    using (var lChannel = new Aurigma.GraphicsMill.Bitmap())
    {
        // Convert to Lab color space and get lightness channel
        using (var labConverter = new Aurigma.GraphicsMill.Transforms.ColorConverter(Aurigma.GraphicsMill.PixelFormat.Format24bppLab))
        using (var splitter = new LabChannelSplitter())
        {
            splitter.L = lChannel;

            Pipeline.Run(bmp + 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 Aurigma.GraphicsMill.Bitmap(lChannel.Width, lChannel.Height, Aurigma.GraphicsMill.PixelFormat.Format8bppGrayscale, new GrayscaleColor((byte)(a + 127))))
        using (var bChannel = new Aurigma.GraphicsMill.Bitmap(lChannel.Width, lChannel.Height, Aurigma.GraphicsMill.PixelFormat.Format8bppGrayscale, new GrayscaleColor((byte)(b + 127))))
        using (var rgbConverter = new Aurigma.GraphicsMill.Transforms.ColorConverter(Aurigma.GraphicsMill.PixelFormat.Format24bppRgb))
        {
            combiner.L = lChannel;
            combiner.A = aChannel;
            combiner.B = bChannel;

            rgbConverter.DestinationProfile = ColorProfile.FromSrgb();

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


Andrey Semenov  
#2 Posted : Tuesday, November 21, 2017 3:20:23 AM(UTC)
Andrey Semenov

Rank: Advanced Member

Groups: Member
Joined: 7/4/2017(UTC)
Posts: 43

Was thanked: 12 time(s) in 12 post(s)
Hi Lauren,

Just save original alpha channel in the beginning of TintedFilter() function and then add it to the bitmap after applying the tint:

Code:
public static void TintedFilter(RgbColor color, ref Aurigma.GraphicsMill.Bitmap bmp)
{
    var transparencyChannel = bmp.Channels[Channel.Alpha];

    // ... Existing code ...

    using (var combiner = new RgbChannelCombiner())
    {
        combiner.R = bmp.Channels[Channel.Red];
        combiner.G = bmp.Channels[Channel.Green];
        combiner.B = bmp.Channels[Channel.Blue];
        combiner.A = transparencyChannel;

        Pipeline.Run(combiner + bmp);
    }
}


Regards,
Andrew

Edited by user Tuesday, November 21, 2017 3:23:13 AM(UTC)  | Reason: Not specified

thanks 1 user thanked Andrey Semenov for this useful post.
lauren@photoboothsupplyco.com on 11/21/2017(UTC)
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.