Cleaning

White balance and histogram normalization for batch photos

The short answer

White balance removes a color cast by multiplying the red, green and blue channels by separate gains, so neutral things come out neutral. Auto white balance has to guess those gains, and the common gray-world method assumes the average color of a scene is gray. Histogram normalization stretches each channel so its darkest value becomes black and its brightest becomes white, which revives faded or hazy images. In a batch, apply one correction to images shot under the same light, fix outliers individually, and leave art and deliberately graded images alone.

Batch photos rarely match. A phone on auto white balance makes a fresh guess for every shot, indoor bulbs are orange, shade is blue, and old scans fade unevenly. One at a time, each image looks fine. Side by side in a training set, the differences jump out.

This guide explains what the two most useful batch fixes actually do to your pixels, with small worked examples. The formulas match how ImgTagger's batch color fixer calculates them, and we point out where other tools differ.

What a color cast is

Light sources have different colors. Tungsten bulbs are strongly orange, open shade is bluish, and some LEDs and fluorescent tubes add a green or magenta tint. Our eyes adapt, so paper looks white under all of them. A camera has to make that adjustment explicitly, and when it guesses wrong, every pixel picks up the same tint: a color cast.

In numbers, a cast is one channel running consistently high or low. A gray wall that should read about (140, 140, 140) might read (175, 140, 105) under a warm bulb: too much red, too little blue.

Here is a color fix on a real photo, made by our Batch Color Fixer with its automatic setting. Drag the line to compare:

Before: a mountain lake photograph that looks faded with a warm cast After: the same photograph with more contrast and balanced color from Smart fix
Before: a faded, warm copy made for this example. After: one click on Smart fix (it does not fix everything: the sky stays warm). Photo: Moraine Lake 17092005 by Gorgo, Public domain (Wikimedia Commons).

White balance is three multipliers

Most white balance corrections, ImgTagger's included, come down to a gain for each channel. Every red value is multiplied by the red gain, and likewise for green and blue. One set of gains covers the whole image, so making one neutral area neutral fixes the cast everywhere.

The hard part is choosing the gains. You can measure a neutral reference (a gray card, or a white wall or sheet of paper in the shot), use a preset for a known light source, or let an algorithm guess, which is what "auto" means.

From a color-picker reading to gains

Say a wall you know is neutral reads (200, 180, 150) in an image editor's color picker. Keep green as the reference and divide it by each channel:

red gain   = 180 / 200 = 0.90
green gain = 180 / 180 = 1.00
blue gain  = 180 / 150 = 1.20

Apply those gains and the wall becomes (180, 180, 180). In ImgTagger, enter them under White Balance → Custom. Green makes a good reference because it carries most of the brightness we perceive, so exposure barely changes.

Taking a reading you can trust

  • Average a patch. A single pixel carries sensor noise and JPEG artifacts that can shift one channel by several levels. Read five to ten spots across the neutral area, or use an averaging sampler if your editor has one, and average them.
  • Stay out of the highlights. A white shirt reading (255, 248, 230) has red clipped at 255, so its real red value is unknown and the red gain you calculate (248 / 255 = 0.97) is too weak. Pick a neutral whose three channels all sit roughly between 100 and 200.
  • Use things that really are gray. Gray cards, white paper, concrete and gray plastic work. Skin, wood and sand have color of their own, which is why Apple's Photos for Mac balances on skin with a separate Skin Tone mode (steps further down).
  • Check a second neutral. After applying the gains, read a different neutral elsewhere in the frame. If it lands within a few levels of equal, you are done. If it is clearly off, the scene has more than one light source (see mixed lighting below).

The gray-world assumption

Auto white balance can't know which objects are neutral, so it needs a rule of thumb. The classic one is the gray-world assumption: across a varied scene, colors average out to gray, so any difference from gray must be the cast. ImgTagger's Auto mode applies exactly this rule, averaging every pixel in the image. An illustrative calculation:

  1. Average every pixel's red, green and blue values. Say the result is R 150, G 120, B 90.
  2. Average those three: (150 + 120 + 90) / 3 = 120. That is the target gray.
  3. Divide the target by each channel's average: red 120/150 = 0.80, green 120/120 = 1.00, blue 120/90 = 1.33.
PixelBefore (R, G, B)After ×0.80, ×1.00, ×1.33
Gray wall175, 140, 105140, 140, 140
White shirt240, 230, 210192, 230, 255 (blue was 280, clipped)

The wall is fixed. The shirt shows the main risk of gains above 1: values run past 255 and get clipped, tinting highlights slightly blue or cyan. ImgTagger clips only after brightness and contrast, so a small negative brightness can pull those values back into range.

Where gray-world fails

The assumption breaks when a scene really is dominated by one color: a forest, a beach, a sunset, a red car filling the frame. Auto then "corrects" real color by tinting toward the opposite hue, magenta for the forest and blue for the sunset. Other methods, such as white-patch (assume the brightest area is white), fail on other scenes. A measured reference beats any guess.

One Auto for the batch, or one per image?

For photos taken under one light, one correction applied to all of them usually beats correcting each separately. Per-image gray-world forces every average to gray, so a photo of someone in a red coat gets pushed toward cyan while the next shot doesn't. ImgTagger's global Auto measures the image you are previewing when you select it and applies those gains to the whole batch, so pick a representative image with varied colors first. Setting Auto on a single image instead, in its per-image controls, measures that image's own pixels, which suits the odd outlier.

Presets, auto and custom

Mode in ImgTaggerGains (R, G, B)Use it when
Warm Sunset1.15, 1.00, 0.90Images look too blue (shade, overcast, cool LEDs), or you want warmth
Cool Daylight0.90, 1.00, 1.15Images look too orange (tungsten bulbs, candlelight)
Neutral Indoor0.95, 1.00, 1.08Indoor shots are slightly orange from warm bulbs and Cool Daylight is too strong
AutoCalculated (gray-world)A batch from one light, measured on a varied image
CustomYour valuesYou measured a neutral area, or presets go too far
Smart fix (button)Calculated per picture from its near-neutral pixelsA mixed batch of photos; it leaves flat art alone (worked example below)

Warm Sunset and Cool Daylight are named for the look they produce rather than the lighting they fix. A sunset photo is already orange, so to neutralize it you would reach for Cool Daylight. Neutral Indoor is the exception: its name describes the goal, a neutral result from warm indoor light. Fixed presets treat every image identically, which makes them the most predictable choice for large batches.

How Smart fix picks its numbers

The color fixer's Smart fix button replaces gray-world with a more cautious set of rules, run separately on every picture. The tool page lists the steps in words. Here they are on numbers, for an imagined indoor photo that is warm, dark and slightly flat. The measurements are made on a copy at most 480 pixels on the long side.

  1. Flat art check. The most common exact color covers 3% of the pixels, typical of a photo. Only at 40% or more would the picture be treated as flat artwork and left untouched.
  2. White balance from near-neutral pixels only. Smart fix keeps pixels whose saturation, (max − min) / max, is under 0.35 and whose brightness sits between 30 and 235. They must make up at least 8% of the picture and share one consistent tint. Say they average (200, 180, 150). The target gray is 176.7, so the raw gains are 0.88, 0.98 and 1.18. They fall inside the 0.80 to 1.25 limits, and then only 85% of each correction is applied: 1 + (0.883 − 1) × 0.85 = 0.90 for red, 0.98 for green and 1.15 for blue.
  3. Gamma, only when clearly too dark or too bright. With those gains applied, the median brightness is 0.30 of full scale and the 95th percentile is 0.55. Both are under the limits (0.36 and 0.62), so the picture counts as underexposed. The gamma that would lift the median to 0.42 is log 0.30 ÷ log 0.42 = 1.39. Going 85% of the way gives 1.33, rounded to 1.3.
  4. Levels, through brightness and contrast. After gamma, the darkest 0.5% of pixels sit at 20 and the brightest 0.5% at 220, a span of 200. Stretching that onto 4 to 251 needs a multiplier of 247 ÷ 200 = 1.235. Going 90% of the way gives 1.21, so contrast becomes +21 and brightness −17. The bright end lands at (220 − 17) × 1.21 = 246, a few levels short of 251 on purpose.
  5. Saturation, only for dull pictures. Among mid-brightness pixels the mean saturation is 0.08, under the 0.12 bar. The formula asks for √(0.2 ÷ 0.08) = 1.58 times, but the cap is 1.15, so saturation becomes 115.

The note under the preview would read cooled a warm color tint, brightened it, added contrast, made the colors richer, and the per-image controls would show gains of 0.90, 0.98 and 1.15, gamma 1.3, brightness −17, contrast +21 and saturation 115.

Step 2 is what keeps Smart fix out of gray-world's traps. In a forest picture the leaves are saturated, so they never enter the white balance sample; without grays or whites that share a tint, the gains stay at 1. A saturated sunset sky is skipped the same way. When the near-neutral pixels disagree about the tint, they are treated as colored objects and white balance is left alone. If the strict pass finds too few candidates, a relaxed second pass looks for bright pixels with saturation under 0.6 covering at least 15% of the picture and sharing a very consistent tint, which is how white fur or a white wall looks under a strong cast.

Mixed lighting: two casts in one picture

A room lit by a window and a table lamp has two casts at once: bluish where daylight falls, orange near the lamp. Gains are one multiplier per channel for the whole picture, so they can neutralize one light only. Say a wall near the window reads (150, 160, 180) and a wall near the lamp reads (190, 160, 120):

Gains taken fromGains (R, G, B)Window wall afterLamp wall after
Window wall1.07, 1.00, 0.89160, 160, 160203, 160, 107 (more orange than before)
Lamp wall0.84, 1.00, 1.33126, 160, 240 (strongly blue)160, 160, 160

Pick the light that falls on the subject. If a face is lit by the lamp, take the gains from the lamp side and let the window glow stay cool, which usually reads as natural. Gray-world averages both lights and lands between them, leaving both areas off. Correcting each area separately takes the local masks of a full photo editor, so in a batch, either accept the mix or set those few pictures aside for hand editing.

Gains act on stored values, not on light

Image files store brightness on a curve. An sRGB value is roughly the light intensity raised to the power 1/2.2, which spends more of the 256 levels on shadows, where eyes notice small steps. A color cast is physically a multiplier on light, so the textbook place for white balance gains is in linear light, before that curve. ImgTagger, like many simple tools, multiplies the stored values directly.

The difference is smaller than it sounds. For a pure power curve, multiplying a stored value by g is the same as multiplying the light by g2.2, because (g × V)2.2 = g2.2 × V2.2. A gain on stored values is still a per-channel multiplier on light, only a stronger one: Warm Sunset's red gain of 1.15 acts like 1.36 in linear light, and its blue 0.90 like 0.79. The real sRGB curve has a short straight section at the very bottom (stored values below about 10 out of 255), where the match breaks down, so the deepest shadows come out slightly differently than a linear-light correction would make them.

Two practical results follow. Gains measured from a neutral reference make that reference neutral in either space, since it ends up with three equal values. And numbers do not carry over between tools that work in different spaces: white balance multipliers stored with raw camera files apply to linear sensor data, so a multiplier of 1.36 there is closer to 1.15 here.

What a histogram shows

A histogram counts how many pixels sit at each level from 0 to 255, usually per channel:

  • Bunched to the left: dark or underexposed.
  • Bunched to the right: bright or overexposed.
  • A narrow hump with nothing near 0 or 255: flat, hazy or faded, like an old print scan.
  • A spike at 0 or 255: clipping, where detail is already lost.

When the red, green and blue histograms sit at different positions, you are looking at a color cast.

Histogram normalization (stretching)

Normalization, also called a contrast stretch, maps the range each channel actually uses onto the full 0–255 range. ImgTagger applies this to each channel:

new value = (value − darkest) / (brightest − darkest) × 255

Here is an illustrative faded scan:

ChannelDarkestBrightestStretch factorSample pixel
Red40220255/180 ≈ 1.42130 → 128
Green30200255/170 = 1.50115 → 128
Blue50180255/130 ≈ 1.96115 → 128

The darkest values become black and the brightest become white, so the image gains contrast. And because each channel stretches separately, the slightly warm pixel (130, 115, 115) became neutral (128, 128, 128). Per-channel normalization doubles as a rough white balance, which helps faded prints and hurts images whose color is meant to lean one way.

The risks

  • Outliers block it. ImgTagger's plain min-max stretch uses the single darkest and brightest value. One black border pixel and one white highlight per channel, and nothing changes. Editors' "auto contrast" features typically ignore a small share of extreme pixels for this reason.
  • It shifts colors. A deliberately warm scene can lose its warmth along with its haze.
  • It amplifies noise. Above, blue is multiplied by almost 2, and so is any noise or JPEG blockiness in it.
  • It can cause banding. That blue channel used 131 distinct levels and still has only 131 after stretching, now with gaps between them. Smooth skies can show visible steps.
  • One image's range clips the others. Applying one image's range to a batch, as ImgTagger's global toggle does, clips pixels in other images that fall outside it. The per-image On setting measures each image's own range instead.

Normalization is not histogram equalization, which reshapes the histogram so pixel counts spread evenly. Equalization is far more aggressive and often looks unnatural on photos. ImgTagger doesn't offer it.

A histogram before and after stretchingA narrow hump of pixel brightness in the middle becomes a wider hump that reaches from black to white.Before: bunched in the middleblackwhiteAfter: stretched to the endsblackwhite
A schematic drawing with made-up data. Stretching moves the darkest pixels to black and the lightest to white and spreads the rest between them, which raises contrast in a flat, hazy picture.

Gamma vs brightness vs contrast

These three are easy to confuse. Take a shadow (0), a midtone (64) and a highlight (230), and use each control to lift the midtone to about 101:

Adjustment0 →64 →230 →Effect
Brightness +3737101255Blacks turn gray; the highlight clips
Gamma 1.50101238Black and white stay put; midtones lift
Contrast +58 (ImgTagger)0101255Multiplies by 1.58, so highlights clip first

For exposure fixes, gamma is usually the gentlest choice because it bends the tone curve without moving pure black or white. Brightness shifts every value equally and washes out shadows. Most editors pivot contrast around mid-gray, but ImgTagger's multiplies from black, so on its own it acts like an exposure boost. Gamma conventions differ too: in ImgTagger each value is raised to the power 1/gamma, so a gamma above 1 brightens, while some tools work the other way round.

What 8-bit corrections cost in levels

Ordinary JPEG, PNG and WebP files hold 256 levels per channel, and every correction here maps those 256 inputs onto 256 possible outputs. A gain below 1 squeezes levels together; a gain above 1 spreads them apart and pushes the top ones into white. We counted the distinct output levels for one channel:

Operation on one channelDistinct output levels (of 256)What happens
Gain 0.80205Output tops out at 204; 51 pairs of neighboring levels merge
Gain 0.90 (a preset's reduced channel)231Output tops out at 230
Gain 1.15 (a preset's boosted channel)223Inputs 222 to 255 all become 255; roughly one empty level in every seven
Gain 1.33193Inputs 192 to 255 all become 255; one empty level in every three
Stretch from 50–180 to 0–255131The same 131 levels, now spread over the full range with gaps

Merged and empty levels are invisible in busy, textured areas and show up as visible steps in smooth gradients such as skies and studio backdrops. Two habits keep the loss down. Correct once, from the original files, rather than correcting an already corrected export. And let one tool do the whole job: ImgTagger keeps each pixel as a fraction between steps and rounds to whole levels only once, at the end, so normalization, gains, gamma and contrast together cost no more levels than their combined curve.

Why consistent color matters for datasets

A model learns whatever is consistent across its training images. If most photos of a subject share a warm cast, a fine-tuned model can learn the cast as part of the subject. Mixed casts cause a different problem: the same object appears in several colors, and the color words in your captions may not match the pixels.

Color also affects tagging. Auto-taggers read hair, eye and clothing colors from pixels, so a strong cast can change the color tags you get, and fully desaturated images tend to be tagged greyscale or monochrome. Fix color after removing duplicates and before running the auto tagger. The dataset preparation workflow puts all the steps in order.

Color fixes rarely interfere with duplicate detection. ImgTagger's duplicate finder compares small, normalized grayscale versions of each image (see how perceptual hashing works), so a uniform brightness or contrast change barely moves the result.

One photo at a time in your photo app

For a handful of pictures, the editor already on your device has white balance controls, and the Mac's can measure a neutral point for you:

  • Photos on Mac: open the photo, click Edit, then Adjust, then White Balance. The pop-up menu offers Neutral Gray, Skin Tone and Temperature/Tint. Choose one, click the eyedropper, then click a matching area of the photo: something neutral gray, or a person's skin for Skin Tone.
  • Google Photos on Android: open the photo, tap Edit, then Adjust, and use the Warmth slider. Tap Save as copy to keep the original untouched.
  • Photos on Windows: select Edit image (Ctrl + E) and use the light and color sliders in the adjustment panel on the right. Microsoft's help page says you can click and hold, or press the spacebar, to see the original.

When to leave color alone

  • Illustrations and digital art. The colors were chosen, not captured, and gray-world will damage a deliberate palette.
  • Style datasets. If the goal is a look, such as a film stock or golden-hour warmth, the "cast" is the style.
  • Intentional mood. Candlelit rooms, sunsets and night scenes are meant to look warm or blue.
  • Monochrome and sepia. Per-channel gains or stretching add tints that were never there.
  • Images that already look consistent. Every export re-encodes JPEG and WebP files, which costs a little quality.

When in doubt, correct a copy, compare the thumbnails side by side, and keep whichever version looks more like the scene did.

Put this into practice

Apply white balance, histogram normalization, brightness, contrast, saturation and gamma to many images at once. It runs in your browser. Open the Batch Color Fixer.

Frequently asked questions

Should I crop or resize before color correcting?

Crop first if you can. Auto white balance and normalization both measure the whole image, so borders, frames and letterbox bars skew the averages and the extremes. Resizing hardly changes the averages, but downscaling blends away single-pixel extremes, which can let normalization stretch a little further.

Is it better to fix white balance in RAW files?

Yes, when you have them. A raw file holds more than 8 bits per channel and stores white balance as a setting rather than baking it in, so a raw converter can change it without clipping or banding. Browser tools such as ImgTagger work on decoded 8-bit images.

How do temperature and tint sliders relate to channel gains?

They are friendlier controls for the same idea. Temperature moves the balance between blue and amber, and tint between green and magenta. ImgTagger exposes the gains directly: to warm an image slightly, raise red a little and lower blue; to remove a green tint, lower green slightly.

Can I apply one photo's Smart fix result to the whole batch?

Yes, by copying the numbers by hand. Press Smart fix, open the photo whose result you like, and write down what its per-image controls show: the three custom white balance gains, gamma, brightness, contrast and saturation. Press Undo Smart fix, then enter the gains under White Balance → Custom in the global panel and the other values in the global sliders. Every picture now gets the same correction, which suits a batch shot under one light better than per-picture fixes.

How can I tell if a batch has a color cast?

Look at things that should be neutral, such as white shirts, gray pavement and paper, and compare skin tones across images. Casts are much easier to spot in a grid of thumbnails than one image at a time. In an editor with separate red, green and blue histograms, channels at clearly different positions point to a cast.