Jump to content

How to set white balance?


Recommended Posts

I can't seem to find this anywhere... What I want to be able to do is click on an area of a photo, and then tell paint.net that I want this to be WHITE - and adjust the rest of the photo accordingly. ie, an object photographed on a white background that is tinted due to incandescant lighting etc.

I know this feature exists in photoshop elements. Is it available in paint.net?

Link to comment
Share on other sites

Oh yes I installed it and the feature is there. I just don't think it will do what I'm looking for.

I forget what the tool is called in Elements, but it allows you to click on a spot on a photo. Elements then treats this as "WHITE" and automatically adjusts the rest of the image based on that. It's a terrific feature, and I thought it was probably common amongst photo editors. But maybe not(?)

Link to comment
Share on other sites

Just tried it - looks similar to the elements idea. You find it under Effects/Photo by the way (if you couldn't - like me!).

- Good idea - I think it would be (is) useful. Let's hope it helps 'scoostraw'. ;)

 

Red ochre Plugin pack.............. Diabolical Drawings ................Real Paintings

 

PdnForumSig2.jpg

Link to comment
Share on other sites

I don't have access to Elements at the moment, but I found a description of the feature I'm used to using.

This is what I'd like to do in paint.net:

"Photoshop Elements has a color cast correction feature. When you

select it, you get an eye dropper tool that you use to sample a

white or gray point in the photo. It will use that point as white

and will correct the cast."

This is an extremely useful tool.

Edited by scoostraw
Link to comment
Share on other sites

May I suggest (only an idea),

- that instead of the double vector UI, you could simply let the user set the primary color using the ink dropper tool. And use that as the selected 'white' value?

It would be more logical to use the secondary color though - but that may mean you'd have to write a 'black balance' version too!

Only a suggestion - (it would make the 'white' selection more accurate).

- I know how much work can be involved, even starting from an apparently simple idea.

But I think it could be useful plugin. :)

 

Red ochre Plugin pack.............. Diabolical Drawings ................Real Paintings

 

PdnForumSig2.jpg

Link to comment
Share on other sites

May I suggest (only an idea),

- that instead of the double vector UI, you could simply let the user set the primary color using the ink dropper tool. And use that as the selected 'white' value?

It would be more logical to use the secondary color though - but that may mean you'd have to write a 'black balance' version too!

Only a suggestion - (it would make the 'white' selection more accurate).

- I know how much work can be involved, even starting from an apparently simple idea.

But I think it could be useful plugin. :)

I second Red's motion. All those in favor? (AYE!!) :)

Link to comment
Share on other sites

OK, how about this one:

BBWhiteBalance.zip

Use the eye dropper tool to set your primary color before running the effect. Or, you can use the cross hairs to select a white pixel.

The effect shows up under the Effects > Photo > White Balance... menu.

Here's the CodeLab script:

// Title: BoltBait's White Balance v3.5
// Author: BoltBait
// Submenu: Photo
// Name: White Balance
// URL: http://www.BoltBait.com/pdn
#region UICode
ColorBgra Amount1 = ColorBgra.FromBgr(0,0,0); // Select color of pixel that represents white
bool Amount2 = false; // [0,1] Use manual selection instead
Pair<double, double> Amount3 = Pair.Create( 0.0 , 0.0 ); // Manual white position selection
bool Amount4 = false; // [0,1] Show guide lines
#endregion

private byte Clamp2Byte(int iValue)
{
   if (iValue > 255) return 255;
   if (iValue < 0) return 0;
   return (byte)iValue;
}

private UnaryPixelOps.Invert invertOp = new UnaryPixelOps.Invert();

// Here is the main render loop function
unsafe void Render(Surface dst, Surface src, Rectangle rect)
{
   Rectangle selection = EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
   int RedAdjust = 0;
   int BlueAdjust = 0;
   int GreenAdjust = 0;
   int column;
   int row;

   // find manual selected pixel
   int width = selection.Right - selection.Left;
   int height = selection.Bottom - selection.Top;
   double px = (Amount3.First + 1) / 2;
   double py = (Amount3.Second + 1) / 2;
   column = (int)Math.Truncate(px * (width-1));
   row = (int)Math.Truncate(py * (height-1));

   // default to primary color for adjustment
   ColorBgra SourceColor = Amount1;

   // if selected, use the manual selected pixel instead
   if (Amount2)
   {
       SourceColor = src[column,row];
   }

   // Calculate the amount of Red, Green, and Blue to adjust each pixel
   // We'll assume Blue is in the center 
   BlueAdjust = 0; 
   RedAdjust = SourceColor.B - SourceColor.R; 
   GreenAdjust = SourceColor.B - SourceColor.G; 

   // Now, check to see if Red is in the center 
   if (((SourceColor.R <= SourceColor. && (SourceColor.R >= SourceColor.G)) || ((SourceColor.R >= SourceColor. && (SourceColor.R <= SourceColor.G))) 
   { 
       RedAdjust = 0; 
       BlueAdjust = SourceColor.R - SourceColor.B; 
       GreenAdjust = SourceColor.R - SourceColor.G; 
   } 
   // Or, is it Green that's in the center
   else if (((SourceColor.G <= SourceColor.R) && (SourceColor.G >= SourceColor.) || ((SourceColor.G >= SourceColor.R) && (SourceColor.G <= SourceColor.)) 
   { 
       GreenAdjust = 0; 
       RedAdjust = SourceColor.G - SourceColor.R; 
       BlueAdjust = SourceColor.G - SourceColor.B; 
   } 

   // Apply the ajustment to each pixel
   for (int y = rect.Top; y < rect.Bottom; y++)
   {
       ColorBgra* srcPtr = src.GetPointAddressUnchecked(rect.Left, y);
       ColorBgra* dstPtr = dst.GetPointAddressUnchecked(rect.Left, y);
       for (int x = rect.Left; x < rect.Right; x++)
       {
           ColorBgra CurrentPixel = *srcPtr;

           if (Amount4 && Amount2)
           {
               if (x == column || y == row)
               {
                   if (x == column && y == row)
                   {
                       CurrentPixel = ColorBgra.FromBgra(
                                       Clamp2Byte(CurrentPixel.B + BlueAdjust),
                                       Clamp2Byte(CurrentPixel.G + GreenAdjust),
                                       Clamp2Byte(CurrentPixel.R + RedAdjust),
                                       CurrentPixel.A);
                   }
                   else
                   {
                       CurrentPixel = invertOp.Apply(CurrentPixel);
                   }
               }
               else
               {
                   CurrentPixel = ColorBgra.FromBgra(
                                   Clamp2Byte(CurrentPixel.B + BlueAdjust),
                                   Clamp2Byte(CurrentPixel.G + GreenAdjust),
                                   Clamp2Byte(CurrentPixel.R + RedAdjust),
                                   CurrentPixel.A);
               }
           }
           else
           {
               CurrentPixel = ColorBgra.FromBgra(
                               Clamp2Byte(CurrentPixel.B + BlueAdjust),
                               Clamp2Byte(CurrentPixel.G + GreenAdjust),
                               Clamp2Byte(CurrentPixel.R + RedAdjust),
                               CurrentPixel.A);
           }

           *dstPtr = CurrentPixel;
           srcPtr++;
           dstPtr++;
       }
   }
}
 

I wrote this myself, so I can not vouch for the algorithm.

  • Upvote 1

Click to play:
j.pngs.pngd.pnga.pngp.png
Download: BoltBait's Plugin Pack | CodeLab | and how about a Computer Dominos Game

Link to comment
Share on other sites

Nice work! - and thanks for showing the code too :P

1. The UI is great allowing both methods of selection and color change on the fly.

2. It appears to behave pretty much the same behavior as the PS elements version I've got - which I guess is the idea.

3. I'm a bit confused with the elements version anyway. - it says to select an area you wish to become white, grey or black - but it doesn't actually do this (still leaves a slight color caste)?

Still, it's what people used to P.S. will be expecting. Personally I prefer tinkering around with curves - but that is a lot more time consuming.

Thanks for putting the work in!

 

Red ochre Plugin pack.............. Diabolical Drawings ................Real Paintings

 

PdnForumSig2.jpg

Link to comment
Share on other sites

Thanks.

Technically, this isn't "white balance". It is more like "gray balance".

You can select a pixel that is supposed to be anywhere from white to black and the picture will be adjusted so that this pixel is gray balanced (that is: R, G, and B will be all the same value). I wrote the algorithm to try and minimize the adjustment made to the pixel.

Click to play:
j.pngs.pngd.pnga.pngp.png
Download: BoltBait's Plugin Pack | CodeLab | and how about a Computer Dominos Game

Link to comment
Share on other sites

That's what I thought it should do - perhaps it's just my eyes - color is very subjective (dependent on the adjoining colors).

So, if, lets say a 'cream' coloured pixel is selected it should change to a high value neutral grey, say B= G = R = 200 ish. And then change the rest of the picture by the ratio that caused that change?

I don't think P.S is doing that - but I could well be wrong - I often am :P

Edit - YES - I am wrong - both yours and PS do what they should - just my perception of the colors!

Edited by Red ochre

 

Red ochre Plugin pack.............. Diabolical Drawings ................Real Paintings

 

PdnForumSig2.jpg

Link to comment
Share on other sites

This topic had my interest as I used PDN to do photo editing. I use the following technique to "correct" white balance. BoltBait is right, it's a grey card technique, and professional photographer use grey card to calibrate their equipment to have true white balance in their photograph.

To achieve it without plug-in-

1) Expand canvas size 100 pixels on the largest side, tick maintain proportion to on.

2) Use the color wheel and select either grey or light grey as the primary color, and bucket fill it around the white border. Sometime the grey color will overlap the photograph. One trick I have discovered is to set the secondary color to full transparency before changing canvas size.

3) Run levels (don't use Auto Level!) and adjust settings until you perceive the color to be desirable and pleasing to the eyes.

4) Set the canvas back to the original size (-100 pixels on the largest side).

Enjoy the fruit of thy labor!

Officially retired from this forum. Have a nice day.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...