Home  /  Guides  /  Seven levels, one batch of black and white

Seven Levels, 68% Changed, Not One Pixel More

Updated 2026-11-26 · measured on 12 mixed files, 20,933,726 bytes, 63,016,384 pixels, seven threshold levels from 32 to 224

The short answer

Every threshold level from 32 to 224 changed exactly 42,995,243 pixels of the batch, 68.229%, because a two-value output changes any pixel that was not already pure black or pure white. What the slider actually decides is how that 68% splits — on photo_landscape.jpg the white share fell from 64.660% at level 32 to 2.583% at level 224, while 35.340% of the frame stayed black the whole way.

So the number you pick never governs how much of the image changes. It governs which of the two values each pixel lands on. A pixel-count audit cannot tell you which level ran; the white-to-black split can.

This page treats thresholding as a batch operation: one level, a folder of mixed files, and a per-file account of the output. The neighbouring measurements on the same twelve files are the batch gamma measurement (a curved lift that keeps grays), the batch equalize measurement, the batch grayscale measurement (grays kept, colour gone) and the batch invert measurement. If you want the single-image case, start at the photo flipper.

Gamma and threshold are worth comparing directly because both are one-number controls. Gamma moves every value and never reaches black or white by accident; threshold keeps only the two ends and throws the middle away on purpose. On the transparent logo the same folder gave 53.46% changed under gamma 2.2 and 53.46% changed under a threshold of 128, yet the alpha channel behaved differently at the edges, as section 6 shows.

1. What was run and on what

Twelve files, 20,933,726 bytes on disk and 63,016,384 pixels across the 11 that decoded. Each readable file was converted to RGBA, the three colour channels were averaged into one luma value per pixel, that value was compared with the level, and the pixel was written as 255 if it was at or above the level and 0 if it was below. The comparison is inclusive: a pixel exactly at the level goes white.

What the twelve files were: two byte-identical 3000 x 4000 portrait JPEGs, one 4000 x 3000 landscape JPEG, one 3000 x 4000 grayscale JPEG, one 2000 x 1500 JPEG with orientation tag 6, one 3000 x 3000 PNG, one 1200 x 800 transparent PNG, one 128 x 128 PNG icon, one 1600 x 900 WebP, one 400 x 300 six-frame GIF, one 800 x 600 16-bit grayscale PNG, and one truncated 1,200-byte JPEG that failed to decode. Nothing left the machine: Pillow 13.0.0, numpy 2.5.4 and Python 3.13.14 on Windows. The seven levels were 32, 64, 96, 128, 160, 192 and 224.

2. The count is flat, the white share is not

Seven settings, one count. That is not a bug in the measurement, it is arithmetic: on a frame with no pure black and no pure white, a threshold changes every single pixel no matter where the cut falls, so the count can only be the whole frame. It happens to be 68.229% here because 31.771% of these frames are already at 0 or 255.

LevelPixels changedShare of batchPure whitePure black
3242,995,24368.229%67.701%32.299%
6442,995,24368.229%59.735%40.265%
9642,995,24368.229%52.096%47.904%
12842,995,24368.229%42.697%57.303%
16042,995,24368.229%31.347%68.653%
19242,995,24368.229%15.454%84.546%
22442,995,24368.229%3.735%96.265%

Shares are of the 63,016,384-pixel batch, readable files only. The changed count is identical at all seven levels: 42,995,243 divided by 63,016,384 equals 68.229%. White plus black equals 100% at every row because the output holds only those two values.

White share of the batch, by level level 32 67.701% level 64 59.735% level 96 52.096% level 128 42.697% level 160 31.347% level 192 15.454% level 224 3.735% Bar width linear to 100 percent. Black is the remainder.
The same batch at seven levels. Every row changes the same 68.229% of pixels; only the white and black split moves.
Your call: whether a given split is right is visual, and the table cannot decide it for you. Two folders with the same white share can look nothing alike — one might be a bright page with dark text, the other a dark photo with a few highlights — so pick the level after looking at one frame at full size.

3. A third of the frame can never change

Between level 32 and level 224 there is a band of pixels that does move: on the landscape photo, 7,449,145 pixels, 62.076% of the frame, flipped from white to black as the level rose. The other 37.924% did not move at all, because 309,996 were at 255 in both runs and 4,240,859 were at 0 before the first run started.

FilePixelsWhite to black, 32→224ShareNever moved
photo_square.png9,000,0007,444,67182.719%17.281%
small_icon.png16,38410,54764.374%35.626%
screenshot.webp1,440,000906,23062.933%37.067%
exif_orient6.jpg3,000,0001,870,91562.364%37.636%
photo_landscape.jpg12,000,0007,449,14562.076%37.924%
gray_8bit.jpg12,000,0007,367,73661.398%38.602%
logo_alpha.png960,000352,42036.71%63.29%
animation.gif120,00010,0008.333%91.667%
gray_16bit.png480,0001,4060.293%99.707%

White to black counts pixels that were 255 at level 32 and 0 at level 224. Never moved counts pixels at 255 in both runs plus pixels at 0 in both. The thirteen-row maths: the two byte-identical portrait JPEGs are omitted here because they repeat the same row, 7,447,749 white to black and 37.935% never moved.

Share that never moves, level 32 to 224 gray_16bit 99.707% animation.gif 91.667% logo_alpha 63.29% photo_landscape 37.924% screenshot.webp 37.067% photo_square.png 17.281% small_icon.png 35.626% Bar width linear to 100. Six of the eleven readable files.
Pixels already at 0 or 255 at both ends of the sweep. The more of these a file has, the less the slider can do to it.

4. Which part of the slider does anything

A level only reaches the pixels whose luma sits in the band between the lowest and highest setting you try. On the landscape photo, 50.524% of pixels are below luma 96 and 30.197% are at or above 160, which leaves 19.278% in the band that a sweep from 96 to 160 actually touches. The rest of the range is decoration.

FileBelow luma 96Luma 96 to 159Luma 160 and up
photo_landscape.jpg50.524%19.278%30.197%
photo_square.png34.025%25.747%40.228%
screenshot.webp49.631%20.719%29.65%

This is the number to look at before dragging a slider across a folder. If almost nothing sits in the middle band, the slider will look dead until it suddenly flips half the frame, and no amount of fine adjustment will fix it. If a lot sits in the band, small steps matter and the difference between 128 and 132 is visible.

Where the landscape photo sits, by luma 50.524% 19.278% 30.197% dark, stays black at every level middle, moves with the slider bright, stays white at every level Segments are 50.524 / 19.278 / 30.197 percent of 12,000,000 pixels.
The blue segment is the only part of the frame a level between 96 and 160 can influence. Everything else is decided before the slider is touched.

5. Where the luma number comes from changes the result

A threshold needs one brightness per pixel, and a colour pixel has three values. Averaging the three equally, or weighting green heavily the way video standards do, gives different answers near the cut. On the square PNG the difference between an equal-weight mean and the classic 0.299 / 0.587 / 0.114 weighting put 666,434 pixels, 7.405% of the frame, on opposite sides of level 128.

FileEqual weights, white0.299/0.587/0.114, white0.2126/0.7152/0.0722, whiteEqual vs 0.299 disagreement
photo_square.png55.309%49.511%55.711%666,434 (7.405%)
photo_landscape.jpg41.497%37.138%41.781%662,952 (5.525%)
screenshot.webp41.715%37.421%42.102%82,291 (5.715%)
logo_alpha.png16.75%16.75%16.75%0 (0.0%)

White share at level 128 under three luma definitions. Disagreement counts pixels where one definition classifies the pixel above the level and the other below. The logo is flat black and white already, so no definition can disagree about it.

This is not a detail you can average away. Every pixel whose equal-weight luma falls in the narrow gap between the two formulas can switch sides at the same level, and the gap scales with how saturated the pixel is. A skin tone or a dusk sky sits exactly where the two definitions disagree, so two tools can produce visibly different black shapes from the same file at the same level.

6. Transparency survives, and so does the colour under it

The transparent logo has 607,580 fully transparent pixels, 63.29% of the frame. Their alpha bytes were identical before and after the threshold, so the file still has its cut-out shape. What changed is the colour stored in those invisible pixels: 160,800 of them now hold pure white and 446,780 hold pure black.

FileTransparent pixelsTurned whiteTurned blackAlpha bytes
logo_alpha.png607,580 (63.29%)160,800446,780identical
animation.gif000identical

That matters the moment someone reopens the file with a different background, or a downstream tool composites it on white. The visible edge was governed by alpha, which did not move; the fringe was governed by the colour, which did. If you threshold a cut-out for print, compare the edge against its final background rather than against the checkerboard.

Your call: whether white or black is the right colour to park under transparent pixels depends entirely on where the file is going — white for a page, black for a dark deck. I have not picked one for you here, because the right answer changes with the destination.

7. Frames, bit depth and orientation tags

A threshold writes a two-value image, and a two-value image fits into formats that a grayscale one does not always survive. The container is where most of the surprises are.

FileBeforeAfterNote
animation.gif6 frames, indexed1 frameReopening the saved GIF gave one frame
gray_16bit.png16-bit, 65,536 levels, 0 to 65,5358-bit, 256 levelsraw samples 0 to 65,535 became 256 distinct values after conversion to RGB
exif_orient6.jpgorientation tag 6no tag2000 x 1500 dimensions unchanged, tag dropped
logo_alpha.pngRGBA, 63.29% transparentRGBA, same alphacolour under transparency replaced

The 16-bit file is the one that behaves least like a photo. Its samples ran the full 0 to 65,535, but after conversion to 8-bit RGB only 256 values remained, and 99.805% of the frame sat above level 128. A threshold on this file at any level from 32 to 224 produced a nearly white output: 99.951% white at 32, still 99.658% at 224. That is not the tool failing, it is a bright 16-bit scan meeting a cut designed for 8-bit photos.

8. Output bytes, blur and repeatability

A two-value image compresses hard. Eleven files at level 128 wrote 2,576,292 bytes of PNG from 20,933,726 bytes of input, 0.1231 times the source. The size depends on which level you chose, because the boundary between black and white is where all the bits go: 621,401 bytes at level 32, 2,576,292 at 128 and 1,446,204 at 224.

FileInput bytesOutput at 32Output at 128Output at 224
photo_landscape.jpg2,403,704120,569480,364255,598
photo_square.png10,636,84092,703440,561237,400
photo_portrait.jpg2,443,475114,923469,342260,456
gray_8bit.jpg2,068,147109,564492,971311,937
screenshot.webp186,78818,34670,00133,089
small_icon.png22,2145101,471589

All outputs were written as 8-bit RGBA PNG. The totals are 2,576,292 bytes at level 128 against 20,933,726 bytes of input across the same eleven files; 2,576,292 divided by 20,933,726 equals 0.1231. The portrait row is repeated for its byte-identical twin and counted once in the total.

Blurring before the cut changes the cost in a way the level alone does not. A one-pixel gaussian blur then a threshold of 128 moved only 1.814% of the landscape frame compared with a hard cut, 2.973% of the screenshot and 4.401% of the small icon. The white share barely shifted: 41.512% to 41.58% on the landscape, 41.638% to 40.192% on the icon. What the blur buys is a softer edge, not a different image.

Your call: whether a 0.1231 output ratio counts as a win depends on what you need next. Binarized scans print cleanly and OCR tools accept them, but the grays are gone for good, so keep the originals until the downstream step has been checked on one file.

Two independent passes at level 128 produced byte-identical output: 2,576,292 bytes both times, SHA-256 1bd5cf14fb0979a0ca9baf8bb601404f990ef702c4d93c47848f20a9f56854d4 over the eleven PNG files in order. The first pass took 6.15 seconds and the second 6.19 seconds of wall clock for the folder. Treat those as scale, not as a benchmark.

See all measured guides

Frequently asked questions

How do I apply a threshold filter to an image?

Pick one level between 0 and 255 and apply it to every file at once. On this batch a level of 32 turned 64.660% of a 4000 x 3000 landscape JPEG pure white and 35.340% pure black; the same 32 turned 86.217% of a square PNG white. No pixel keeps a middle value, which is what separates a threshold from a black and white conversion.

How do I binarize an image online?

Binarizing and thresholding are the same operation: every output sample becomes either 0 or 255. This batch wrote 11 files at 2,576,292 bytes of PNG from 20,933,726 bytes of input, 0.1231 times the source, because the deep grays are for the first time encoded once instead of 256 times.

What is the difference between threshold and black and white?

A black and white conversion keeps the grays and removes the colour. A threshold removes the grays too. The test is in the output: after thresholding there are exactly two values, 0 and 255, and the changed-pixel count on photo_landscape.jpg was 7,922,051 at level 32 and the same 7,922,051 at level 224, a difference of zero.

What threshold value should I use?

There is no universal number. Across this batch level 128 left 57.303% of all pixels black and 42.697% white, while the same level on the 16-bit grayscale file produced 99.805% white. Watch the white share rather than the slider: it moved from 64.660% to 2.583% on the landscape photo between level 32 and level 224.

Why does part of my scan go solid black?

Because one level is applied to the whole frame, and a shadowed corner can sit below it. On the screenshot file the pixels between luma 96 and 159 were 20.719% of the frame, and those are the only ones a level sweep can move; everything at or below 96 stayed black at every setting from 32 to 224.

Is my image uploaded to a server?

That depends on the tool, not on the operation. The measurements on this page ran on 12 local files that never left the machine: Pillow 13.0.0 and numpy 2.5.4 read them from disk and wrote PNG output to disk. Whether a browser tool uploads is a separate question you can answer only by reading that tool's own page.

Does threshold keep the transparent background?

The alpha bytes can survive untouched while the colour under them does not. On the transparent logo, 607,580 pixels were fully transparent and their alpha bytes were identical before and after; 160,800 of those transparent pixels were still assigned pure white, so the file now carries white data in places nothing can see.

Does it work on a batch of photos?

It runs, but one level rarely suits a mixed folder. The same level 128 changed 87.532% of a square PNG and 0.388% of a 16-bit grayscale file, and 8.333% of a six-frame GIF whose darkest frame values never reached 128 at all. Sort by brightness before you pick the number, because the number is global.

Does the level change how many pixels are affected?

No. All seven levels from 32 to 224 changed 42,995,243 of 63,016,384 pixels, 68.229%, because any pixel that is not already pure black or pure white gets rewritten whichever side of the cut it lands on. What changes is the split: the batch went from 67.701% white at level 32 to 3.735% at level 224.

What happens to a 16-bit grayscale scan?

It is squeezed to 256 levels before the cut is applied. This file carried 65,536 distinct sample values from 0 to 65,535, and after conversion to 8-bit RGB only 256 remained; 99.805% of the frame sat above level 128, so every level from 32 to 224 produced a nearly white result. Convert at the bit depth you intend to keep, not after.