Jump to content


Photo

Color Balance (Plugin) - UPDATED


25 replies to this topic

#1 BoltBait

BoltBait

    2013 Movie Guru Award Winner

  • Administrators
  • 9,591 posts
  • LocationCalifornia, USA
  • Reputation:299

Posted 17 January 2007 - 12:58 AM

Color Balance

Whenever I take pictures indoors, the pictures always come out looking yellow. So, I needed a color correcting effect. I wanted to create something that would be MUCH easier than fiddling with the RGB levels adjustment that is already included in Paint.NET.


The Idea

I wanted to make an effect that would make my pictures less yellow. Well, if they are going to be less yellow they will have to be more... what? Blue? Yup. That's the opposite of yellow. Perfect! I figured a slider between yellow and blue would do the trick. And, while I'm at it, I might as well add a slider between Cyan and Red and a slider between Magenta and Green. (Not that I'll ever need those, but, what the hay!)


Opposites

Yellow is opposite of blue? Sure. Let's take a look at the color wheel:

Posted ImageBasically, the arrows shown in this illustration are the sliders in the Color correction effect.

Posted ImageIn the RGB color model, Yellow is a combination of Red and Green. So, in the code, when we increase the level of Blue in our image, we decrease the levels of Red and Green (each by half of the Blue adjustment). If you notice, we have each of the primary colors on one end of the sliders and the combination of the remaining primary colors (called secondary colors) on the other end.


The Effect DLL

If you like it, you can download the precompiled effect here: BoltBait's Plugin Pack



How to Use

Typically, this effect is used to correct the colors of a photograph. Notice in the illustration of the color wheel above, all 3 arrows cross at white. The best way to adjust a photograph's colors is to look at the white areas of the photograph and try to adjust the sliders until you achieve a true white in those areas.

For example, many times when taking photographs indoors, white walls will appear slightly yellow. Simply move the Yellow/Blue slider to the right until the walls appear white. Then adjust the other sliders to fine tune the resulting shade of white. It may take some tinkering with the sliders to get something close to a true white. Then, once you get the colors right, it may be necessary to adjust the brightness and contrast.

By the way, this is a great way to "whiten" teeth, too. Waaaay easier than brushing. ;) Tinting

Another use of this effect is to tint images. First, change the image to Black and White (desaturate the image). Then run the effect and adjust the sliders for the desired coloring. As an example, you can make an image appear Sepia by making the image Black and White, then running the Color Balance effect and setting the sliders to 100, 85, and 75.


Source Code

The codelab script is fairly straight forward:

void Render(Surface dst, Surface src, Rectangle rect) 
{ 
    int CyanRed = 0;         // Slider, Range -100 to 100, default 0
    int MagentaGreen = 0;    // Slider, Range -100 to 100, default 0
    int YellowBlue = 0;       // Slider, Range -100 to 100, default 0

    int r, g, b;
    PdnRegion selectionRegion = EnvironmentParameters.GetSelection(src.Bounds); 
    Rectangle selection = this.EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt(); 
    for(int y = rect.Top; y < rect.Bottom; y++) 
    { 
        for (int x = rect.Left; x < rect.Right; x++) 
        { 
            if (selectionRegion.IsVisible(x, y)) 
            { 
                r = (int)src[x,y].R;
                g = (int)src[x,y].G;
                b = (int)src[x,y].B;

                // Cyan-Red adjustment
                r += CyanRed;
                g -= (CyanRed / 2);
                b -= (CyanRed / 2);
                // Magenta-Green adjustment
                r -= (MagentaGreen / 2);
                g += MagentaGreen;
                b -= (MagentaGreen / 2);
                // Yellow-Blue adjustment
                r -= (YellowBlue / 2);
                g -= (YellowBlue / 2);
                b += YellowBlue;

                dst[x, y] = ColorBgra.FromBgra( 
                    Utility.ClampToByte(<img src='http://forums.getpaint.net/public/style_emoticons/<#EMO_DIR#>/cool.gif' class='bbc_emoticon' alt='B)' />, 
                    Utility.ClampToByte(g), 
                    Utility.ClampToByte(r),
                    src[x,y].A); 
            } 
        } 
    } 
} 




Enjoy. B)
  • 0
Click to play:
Posted ImagePosted ImagePosted ImagePosted ImagePosted Image
Download: BoltBait's Plugin Pack | CodeLab | More... and how about a Computer Dominos Game

#2 Picc84

Picc84
  • Members
  • 1,122 posts
  • LocationNorth Eastern, PA
  • Reputation:0

Posted 17 January 2007 - 01:08 AM

Doesent Illnab do all your UI's? I had though you two were a good team!
  • 0

#3 BoltBait

BoltBait

    2013 Movie Guru Award Winner

  • Administrators
  • 9,591 posts
  • LocationCalifornia, USA
  • Reputation:299

Posted 17 January 2007 - 01:10 AM

Doesent Illnab do all your UI's? I had though you two were a good team!

It is true, I like his work... but, where is he?

MadJik also does fine work.

I may just do this one myself when I find the time. I have upgraded my dev enviroment to VS2005. So, its just a matter of time before I get off my lazy butt and do one for myself. :D
  • 0
Click to play:
Posted ImagePosted ImagePosted ImagePosted ImagePosted Image
Download: BoltBait's Plugin Pack | CodeLab | More... and how about a Computer Dominos Game

#4 Picc84

Picc84
  • Members
  • 1,122 posts
  • LocationNorth Eastern, PA
  • Reputation:0

Posted 17 January 2007 - 01:13 AM

I'm not sure, I tried contacting him on Gmail chat, but he's not currently on, wich is something almost unheard of...
  • 0

#5 Rick Brewster

Rick Brewster

    Paint.NET Author and Developer

  • Administrators
  • 13,554 posts
  • LocationKirkland, WA
  • Reputation:325

Posted 17 January 2007 - 01:17 AM

BoltBait, I think it is high time that you just buckled down and learned how to do this :)
  • 0
The Paint.NET Blog: http://blog.getpaint.net/
Donations are always appreciated! http://www.getpaint.net/donate.html

Posted Image

#6 BoltBait

BoltBait

    2013 Movie Guru Award Winner

  • Administrators
  • 9,591 posts
  • LocationCalifornia, USA
  • Reputation:299

Posted 17 January 2007 - 01:19 AM

BoltBait, I think it is high time that you just buckled down and learned how to do this :)

After writing 11 effects... ya think? :D

Rick, Its all a matter of TIME, not ability.

Besides, everybody knows the UI is the hardest part... :D
  • 0
Click to play:
Posted ImagePosted ImagePosted ImagePosted ImagePosted Image
Download: BoltBait's Plugin Pack | CodeLab | More... and how about a Computer Dominos Game

#7 Rick Brewster

Rick Brewster

    Paint.NET Author and Developer

  • Administrators
  • 13,554 posts
  • LocationKirkland, WA
  • Reputation:325

Posted 17 January 2007 - 01:20 AM

You've got Visual Studio 2005, right?
  • 0
The Paint.NET Blog: http://blog.getpaint.net/
Donations are always appreciated! http://www.getpaint.net/donate.html

Posted Image

#8 BoltBait

BoltBait

    2013 Movie Guru Award Winner

  • Administrators
  • 9,591 posts
  • LocationCalifornia, USA
  • Reputation:299

Posted 17 January 2007 - 01:26 AM

You've got Visual Studio 2005, right?

Yes.

Along with 2 full-time jobs and a family...
  • 0
Click to play:
Posted ImagePosted ImagePosted ImagePosted ImagePosted Image
Download: BoltBait's Plugin Pack | CodeLab | More... and how about a Computer Dominos Game

#9 Picc84

Picc84
  • Members
  • 1,122 posts
  • LocationNorth Eastern, PA
  • Reputation:0

Posted 17 January 2007 - 01:32 AM

Man, if i had Visual Studio, i'd learn, and do them for you guys, but I dont... haha, I realise you can get trials, but everyone knows thats not worth the agervation, learning it in the trial period, and not being able to buy it later...
  • 0

#10 Rick Brewster

Rick Brewster

    Paint.NET Author and Developer

  • Administrators
  • 13,554 posts
  • LocationKirkland, WA
  • Reputation:325

Posted 17 January 2007 - 01:38 AM

You've got Visual Studio 2005, right?

Yes.

Along with 2 full-time jobs and a family...

Very true.

Anyway for the UI you want, the "ThreeAmountsConfigDialog" already does exactly what you want. Just look through the code in the Effects project (d/l the PDN 2.72 source) for one of the effects that uses it, like say Hue/Saturation.
  • 0
The Paint.NET Blog: http://blog.getpaint.net/
Donations are always appreciated! http://www.getpaint.net/donate.html

Posted Image

#11 BoltBait

BoltBait

    2013 Movie Guru Award Winner

  • Administrators
  • 9,591 posts
  • LocationCalifornia, USA
  • Reputation:299

Posted 17 January 2007 - 01:53 AM

Well, I'll take a look at it when I get a chance. Maybe tomorrow.

Man, if i had Visual Studio, i'd learn, and do them for you guys, but I dont... haha, I realise you can get trials, but everyone knows thats not worth the agervation, learning it in the trial period, and not being able to buy it later...

You know you can download Visual Studio for free... ;)

http://msdn.microsof...s/visualcsharp/
  • 0
Click to play:
Posted ImagePosted ImagePosted ImagePosted ImagePosted Image
Download: BoltBait's Plugin Pack | CodeLab | More... and how about a Computer Dominos Game

#12 Picc84

Picc84
  • Members
  • 1,122 posts
  • LocationNorth Eastern, PA
  • Reputation:0

Posted 17 January 2007 - 02:12 AM

Why Look at that! *ithoughiwassosly* I guess i should learn some, it would be realy cool to know... (stopping about this due to getting too offtopic)
  • 0

#13 MadJik

MadJik
  • Members
  • 2,428 posts
  • LocationLille;France
  • Reputation:21

Posted 17 January 2007 - 05:37 AM

Well 3 sliders is standard so...
That's it!

New plugin ColorBalance.dll
here is the DLL

Source for plugin ColorBalance.dll
here is the SRC

Tell me if you want another icone...
  • 0

#14 BoltBait

BoltBait

    2013 Movie Guru Award Winner

  • Administrators
  • 9,591 posts
  • LocationCalifornia, USA
  • Reputation:299

Posted 17 January 2007 - 06:01 AM

Nice! Thanks!

It is working well.

I will add the links to the first post.

By the way, I'm not sure what that icon is, but I like it. :D
  • 0
Click to play:
Posted ImagePosted ImagePosted ImagePosted ImagePosted Image
Download: BoltBait's Plugin Pack | CodeLab | More... and how about a Computer Dominos Game

#15 MadJik

MadJik
  • Members
  • 2,428 posts
  • LocationLille;France
  • Reputation:21

Posted 17 January 2007 - 07:48 AM

...the icon is from nebulous code lab on 16x16...
I find it could "illustrate" the color balance!

And the source is for whose wants to dig into UI creating... :wink:

I use Visual Studio 2005 Express!
  • 0

#16 BoltBait

BoltBait

    2013 Movie Guru Award Winner

  • Administrators
  • 9,591 posts
  • LocationCalifornia, USA
  • Reputation:299

Posted 28 January 2007 - 08:26 AM

Thanks, MadJik, for the source code.

I have modified it so that the Color Balance effect shows up under the Adjustments menu instead of the Effects menu.

Download here: ColorBalance.dll (updated)

Just drop this file into your C:/Program Files/Paint.NET/Effects directory and you should be all set.

Enjoy.
  • 0
Click to play:
Posted ImagePosted ImagePosted ImagePosted ImagePosted Image
Download: BoltBait's Plugin Pack | CodeLab | More... and how about a Computer Dominos Game

#17 BuzzKill

BuzzKill
  • Members
  • 1,021 posts
  • LocationCorpus Christi
  • Reputation:6

Posted 28 January 2007 - 09:30 AM

I have modified it so that the Color Balance effect shows up under the Adjustments menu instead of the Effects menu.

Excellent idea! Thank you.
  • 0
Posted Image
- DO NOT contact me asking for the .pdn of my avatar or the PDN logo. Thank you. Have a nice day.

#18 MadJik

MadJik
  • Members
  • 2,428 posts
  • LocationLille;France
  • Reputation:21

Posted 28 January 2007 - 09:53 AM

Thanks, MadJik, for the source code.

you're welcome.

I have modified it so that the Color Balance effect shows up under the Adjustments menu instead of the Effects menu.

I thought we could only add plugins to the effect menu!
1.Why can't then we put some into the tool menu (polygone)?
2.Could you tell me what you did change for that?

Enjoy.

sure I'll do.
  • 0

#19 BoltBait

BoltBait

    2013 Movie Guru Award Winner

  • Administrators
  • 9,591 posts
  • LocationCalifornia, USA
  • Reputation:299

Posted 28 January 2007 - 05:07 PM

BuzzKill,
You're welcome. :)

Madjik,
I only had to add one line of source code to the file in order to move the effect to the Adjustment menu. If you look through the source code to some of the effects that are in the adjustment menu, I'm sure you'll see the difference. Here is your code, edited (this is only the interesting part):

namespace ColorBalance
{
    [EffectCategory(EffectCategory.Adjustment)]
    public class ColorBalance
        : Effect
    {

You can not put things in any other menus--only Effects and Adjustments.

Please be advised, that Rick told me in a PM that in a future version of Paint.NET, this will not be possible. So, use at your own risk.

By the way, this should be used sparingly. In fact, I've written 11 effects and this is the only one that I feel should be in the Adjustments menu. OK, now two. ;)
  • 0
Click to play:
Posted ImagePosted ImagePosted ImagePosted ImagePosted Image
Download: BoltBait's Plugin Pack | CodeLab | More... and how about a Computer Dominos Game

#20 Rick Brewster

Rick Brewster

    Paint.NET Author and Developer

  • Administrators
  • 13,554 posts
  • LocationKirkland, WA
  • Reputation:325

Posted 28 January 2007 - 08:24 PM

I said it might not be possible.
  • 0
The Paint.NET Blog: http://blog.getpaint.net/
Donations are always appreciated! http://www.getpaint.net/donate.html

Posted Image