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 : Wednesday, October 18, 2017 3:28:58 PM(UTC)
lauren@photoboothsupplyco.com

Rank: Member

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

Thanks: 7 times
I'm looking at the Tint example (specifically the TintUsingLab() method) from the sample code and had a question regarding how the ImageReader works. I'm in a situation where I already have a Bitmap object so I'm wondering if I need to create an ImageReader before I can apply the tint effect or if I can do so directly to the Bitmap object? Any help is greatly appreciated.
Fedor  
#2 Posted : Wednesday, October 18, 2017 7:49:37 PM(UTC)
Fedor

Rank: Advanced Member

Groups: Member, Administration, Moderator
Joined: 7/28/2003(UTC)
Posts: 1,660

Thanks: 5 times
Was thanked: 76 time(s) in 74 post(s)
You can use an instance of Bitmap (sourceBitmap) instead of ImageReader as a source:

Code:
    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);
                Pipeline.Run(sourceBitmap + 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);
            }
        }
    }

Best regards,
Fedor Skvortsov
thanks 1 user thanked Fedor for this useful post.
lauren@photoboothsupplyco.com on 10/22/2017(UTC)
lauren@photoboothsupplyco.com  
#3 Posted : Sunday, October 22, 2017 5:45:35 PM(UTC)
lauren@photoboothsupplyco.com

Rank: Member

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

Thanks: 7 times
And if I wanted to save the "tinted" image back to the same (sourceBitmap), would I just use the sourceBitmap in place of the ImageWriter? Or is the ImageWriter just used to save the image out to an image file?
Fedor  
#4 Posted : Sunday, October 22, 2017 8:11:09 PM(UTC)
Fedor

Rank: Advanced Member

Groups: Member, Administration, Moderator
Joined: 7/28/2003(UTC)
Posts: 1,660

Thanks: 5 times
Was thanked: 76 time(s) in 74 post(s)
Yes, exactly. Alternatively you can create a new bitmap:

Code:
 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);
                Pipeline.Run(sourceBitmap + 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"))
           using (var resultBitmap = new Bitmap())
            {
                combiner.L = lChannel;
                combiner.A = aChannel;
                combiner.B = bChannel;

                rgbConverter.DestinationProfile = ColorProfile.FromSrgb();

                //Pipeline.Run(combiner + rgbConverter + writer);
                Pipeline.Run(combiner + rgbConverter + resultBitmap);				
            }
        }
    }
Best regards,
Fedor Skvortsov
lauren@photoboothsupplyco.com  
#5 Posted : Monday, October 23, 2017 1:00:07 PM(UTC)
lauren@photoboothsupplyco.com

Rank: Member

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

Thanks: 7 times
Wasn't sure if I should start a new thread but since this has to do with the ImageReader I figured I would continue this one.

If I use the image in the samples folder (Chicago.jpg) this code works perfectly but if I use a picture that I have (just a picture taken from a camera) I am getting an exception whenever I run the Pipeline.Run command with the reader. The exception I'm getting is:

Unhandled Exception: System.ArgumentNullException: Argument is null pointer (LittleCms engine requires source color profile for Lab conversion.).
at Aurigma.GraphicsMill.PipelineElement.RunPipeline()
at Aurigma.GraphicsMill.Pipeline.Run()
at Aurigma.GraphicsMill.Pipeline.Run(Pipeline pipeline)
at TintExample.TintUsingLab(RgbColor color, Bitmap& bmp)
at TintExample.Main(String[] args)

The reason you see the reference to a Bitmap as the parameter for the TintUsingLab method is because I was trying different things to get it to work, such as reading in the image to a Bitmap object and then passing it into the method. But it seems it has something to do with the image that I'm using. Again, if I use the chicago.jpg image it works great but not with one of my own. Any ideas as to why this might be happening?

Thanks

Edited by user Monday, October 23, 2017 1:01:59 PM(UTC)  | Reason: Not specified

lauren@photoboothsupplyco.com  
#6 Posted : Monday, October 23, 2017 1:53:26 PM(UTC)
lauren@photoboothsupplyco.com

Rank: Member

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

Thanks: 7 times
Okay I think I figured this one out. After looking at more documentation, I found that the ColorProfile was not defined on the Bitmap so I just had to define that and everything started working as designed. Just replied here in case anyone else runs into this.
Fedor  
#7 Posted : Monday, October 23, 2017 5:56:05 PM(UTC)
Fedor

Rank: Advanced Member

Groups: Member, Administration, Moderator
Joined: 7/28/2003(UTC)
Posts: 1,660

Thanks: 5 times
Was thanked: 76 time(s) in 74 post(s)
Originally Posted by: lauren@photoboothsupplyco.com Go to Quoted Post
Okay I think I figured this one out. After looking at more documentation, I found that the ColorProfile was not defined on the Bitmap so I just had to define that and everything started working as designed. Just replied here in case anyone else runs into this.


Yes, you can either assign a color profile to a bitmap (for example the sRGB color profile):

Code:
if (bitmap.ColorProfile == null)
	bitmap.ColorProfile = ColorProfile.FromSrgb();


You can specify the default color profile for ColorConverter as well:

Code:
using (var labConverter = new ColorConverter(PixelFormat.Format24bppLab) 
	{ DefaultSourceProfile = ColorProfile.FromSrgb() })
Best regards,
Fedor Skvortsov
Users browsing this topic
Guest
Similar Topics
ImageReader.Create Stream vs. fileName PNG (Discussions – Graphics Mill)
by JoshSmith 6/2/2023 10:02:51 PM(UTC)
Can't read TGA image with ImageReader (Discussions – Graphics Mill)
by bma 1/26/2016 9:08:42 AM(UTC)
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.