Surfaces that are not flat

Counting cloud by counting pixels

A sky camera looks up and something counts the white pixels. On an equal-area fisheye that answer is right to 0.01%, which is the grid's own error. On an equidistant one it is 9% low, on stereographic 27% low, and on an ordinary flat lens 77% low — against a cover that is known exactly, because the clouds here are caps whose solid angles add. Weighting each pixel by the surface's area scale repairs every one of them to better than a fifth of a per cent.

Worth reading first: The third column is area.

A camera points at the sky. Something thresholds the image and counts the pixels that came out white. The number it reports is called cloud cover, and it is a fraction of the sky.

Every part of that sentence is fine except the last clause, which is true on exactly one kind of lens.

Counting cloud by counting pixels, on four picture surfacesOne sky, four cameras. The cloud really covers 10.31% of the 70° field, exactly, because it is made of caps whose solid angles add. Counting the pixels inside it gives 10.31%, 9.37%, 7.56%, 2.40% — right on the equal-area fisheye to 0.01%, which is the grid's own error, and out by -9%, -27%, -77% on the others. Weighting each pixel by the surface's area scale brings every one of them back to within 0.11%.share of the 70° field counted as cloud — the truth is 10.31%equal-area fisheye10.31% (-0.0%)equidistant fisheye9.37% (-9.1%)stereographic7.56% (-26.6%)flat plane2.40% (-76.8%)401² of picture, four caps of cloud0.01% on the equal-area rule, -77% on the flat plane
Fig. 1 One sky, four cameras, and a cover that is known exactly rather than estimated. Counting pixels gives the right answer on the equal-area fisheye and is out by up to three-quarters on the others.

This essay is a measurement rather than an argument, and the thing that makes it a measurement is that the true answer comes from somewhere other than a count.

Making the truth knowable

The problem with testing a counting method is that the reference is usually another count. Comparing two counts establishes that they disagree and not which is wrong.

So the sky here is built from spherical caps. A cap of angular radius ρ\rho subtends a solid angle of exactly 2π(1cosρ)2\pi(1 - \cos\rho), and if the caps do not overlap, their solid angles add. That gives the cover as a closed form, with no sampling anywhere in it.

Two conditions have to hold for that to be true, and both are asserted rather than arranged: each cap lies wholly inside the field being counted, and no two caps overlap. If either failed, the “true” answer would be an over-count and the entire comparison would be measuring the arithmetic instead of the surfaces.

Over a field of 70° from the zenith, the four caps used here cover 10.31% of it. Exactly, to as many digits as anyone wants.

The count

The counting is done exactly as an image-processing script does it, because that is the operation under test.

A square grid is laid over the picture. Each cell’s centre is turned back into a direction through the surface’s inverse map. Cells whose direction falls in the counted field are tallied; those whose direction is in a cloud are tallied separately. The ratio is the reported cover.

The grid is the same size for every surface, and the field counted is the same 70° for every surface — the picture’s radius is taken at whatever radius that surface puts 70° at, so every camera is being asked about the same piece of sky. Without that the comparison would be between fields of view as much as between rules.

The results:

surface reports error
equal-area fisheye 10.31% −0.01%
equidistant fisheye 9.37% −9.1%
stereographic 7.56% −26.6%
flat plane 2.40% −76.8%

Reading the table

The first row is the grid’s own error and nothing else. 0.01% relative, on a 401-square grid over a round field with curved cloud boundaries — the cells that straddle a boundary are the whole of it. That number is what every other row has to be judged against, and stating it is what turns “the equal-area one is right” from a claim into a measurement with a bound.

Every error is negative, and it is worth seeing why before the numbers. The clouds here sit near the middle of the field, and every surface except the equal-area one inflates the outer part of the picture relative to the inner. So the clouds occupy a smaller share of a picture that has been stretched at its rim, and the count comes out low. Move the clouds to the horizon ring and every sign flips — which is the point about the error being systematic rather than random. It has a direction, and the direction depends on where in the sky the thing being counted is.

The flat plane’s 77% is not a bad lens. It is the correct behaviour of a rectilinear projection asked about a 70° field: sec3θ\sec^3\theta at 70° is about 25, so the rim of that picture is enormously over-weighted and everything near the axis is drowned. An ordinary wide-angle photograph is not a slightly biased instrument for this job; it is the wrong instrument.

And 9% on the equidistant fisheye is the dangerous row, because it is the lens most people counting a sky actually own, and 9% is small enough to look like a real result.

Counting cloud by counting pixels, on four picture surfacesOne sky, four cameras. The cloud really covers 10.31% of the 70° field, exactly, because it is made of caps whose solid angles add. Counting the pixels inside it gives 10.31%, 9.34%, 7.54%, 2.39% — right on the equal-area fisheye to 0.02%, which is the grid's own error, and out by -9%, -27%, -77% on the others. Weighting each pixel by the surface's area scale brings every one of them back to within 0.27%.share of the 70° field counted as cloud — the truth is 10.31%equal-area fisheye10.31% (-0.0%)equidistant fisheye9.34% (-9.4%)stereographic7.54% (-26.8%)flat plane2.39% (-76.8%)241² of picture, four caps of cloud0.02% on the equal-area rule, -77% on the flat plane
Fig. 2 The same measurement on a coarser grid. The equal-area row’s error grows — it is the grid’s error, so it must — while the other three barely move, because theirs is not about the grid.

The repair

The count is recoverable, and the repair is exactly what the third column of the surface table says it should be.

Solid angle per unit picture area is the reciprocal of the area scale. So weight each cell by the reciprocal of its surface’s area scale at that cell’s direction, and the sum is a solid angle rather than an area. That is ordinary quadrature with the right Jacobian in it, and it is the thing an unweighted count is silently omitting.

Weighted, all four surfaces return the cover to better than a fifth of a per cent — the flat plane included.

That is worth stating plainly because it changes the practical advice. A count made on the wrong surface is not lost, provided the rule is known. It costs one multiplication per pixel and it is exact.

What is lost is a count made on an unknown surface. “Fisheye” is not a rule; there are four in common use and they differ by up to 42% in area weight at 80°. A dataset of sky images with no lens model attached cannot be turned into cover fractions afterwards, and no amount of processing supplies what was never recorded.

What each picture surface does to areaA square degree of world, printed at each angle off the axis, against what the same square degree prints in the middle of the picture. The equal-area fisheye is flat at 1 to 8.3e-8 across 70°; the equidistant one reaches 1.30×, the cylinder 2.40×, stereographic 2.22× and the flat plane 25×. The sweep runs at 45° to the axes on purpose: straight across, the cylinder reads a perfect 1.00 and is not equal-area at all.00.50011.500204060angle off the axis (degrees)area printed per solid angle, against its value on axis (log₁₀)equal-areaequidistantcylinderstereographicplaneswept at 45° to the axes, out to 70°equal-area 1.000 · flat plane 25×
Fig. 3 The weights the repair uses, which are the reciprocals of these curves. The flat plane’s is the one that does the most work: by 70° it is dividing the rim of the picture by twenty-five.

Why the answer comes out low, in detail

The sign of every error is worth an argument rather than an observation, because it is the part a practitioner can reason about without recomputing anything.

Write the reported cover as a ratio of two sums: picture area inside the clouds, over picture area inside the field. Each of those sums is the corresponding solid angle multiplied by the local area scale, integrated. If the area scale were constant the two factors would cancel and the ratio would be right, which is the equal-area case.

When the area scale grows outward, the denominator is inflated more than the numerator whenever the clouds sit inside the field rather than at its rim, because the outer annulus — which contains no cloud — is where the inflation lives. So the ratio falls. Put the clouds at the rim instead and the numerator is inflated more, and the ratio rises.

The general statement is that the bias is the correlation between where the thing being counted is and where the area scale is large. That is why the error is not a fixed correction that can be tabulated once: it depends on the sky, not only on the lens.

It also explains a case that would otherwise look paradoxical. A completely uniform sky — cover spread evenly over the whole field — is counted correctly on any surface, because then the numerator and denominator inflate together. So a test made on uniform cloud would find nothing wrong with any of these lenses, and would be exactly the wrong test.

Counting cloud by counting pixels, on four picture surfacesOne sky, four cameras. The cloud really covers 10.31% of the 70° field, exactly, because it is made of caps whose solid angles add. Counting the pixels inside it gives 10.32%, 9.37%, 7.57%, 2.39% — right on the equal-area fisheye to 0.08%, which is the grid's own error, and out by -9%, -27%, -77% on the others. Weighting each pixel by the surface's area scale brings every one of them back to within 0.49%.share of the 70° field counted as cloud — the truth is 10.31%equal-area fisheye10.32% (+0.1%)equidistant fisheye9.37% (-9.2%)stereographic7.57% (-26.6%)flat plane2.39% (-76.9%)321² of picture, four caps of cloud0.08% on the equal-area rule, -77% on the flat plane
Fig. 4 The measurement again at a third grid size. What is being read here is not the cover but the differences between the rows, and those are unchanged — which is the sense in which the table is about the surfaces.

Two errors that are not this one

Two things people reach for when a sky count comes out wrong are not the problem here, and separating them is useful.

Vignetting is not this. A lens darkens toward the rim and a threshold applied to a darkened rim misclassifies pixels. That is a photometric error, it affects which pixels are called cloud, and it is corrected with a flat field. The error in this essay is geometric: every pixel is classified correctly and the pixels are the wrong size.

And distortion in the lens sense is not this either. A fisheye’s rule is not an error to be corrected; it is the design. Applying a barrel-distortion correction to an equal-area fisheye does not improve the count, it converts the surface to another one — usually rectilinear — and makes the count much worse.

The distinction is worth carrying because both mistakes produce a plausible pipeline that quietly measures the wrong thing.

A rectangular grid through a lens with k₁ = -0.24The faint grid is what a pinhole would have drawn. The solid one is the same grid through barrel distortion: the centre line is untouched, and the outermost bows by 11.8 px.principal pointk₁ = -0.240, k₂ = 0.110 — barrel distortioncentre line 0e+0 px of sag, outermost 11.8 px
Fig. 5 The other kind of distortion, for contrast. A lens’s departure from a pinhole is a defect with a correction; a picture surface’s rule is a choice with a Jacobian. Treating the second as the first is how a sky count gets processed into uselessness.
The patch a pixel sees, the light reaching it, and what the picture recordsThe patch one pixel covers grows as the square of the distance and the light per unit area falls as the square of the distance, so their product is flat — 2e-16 across a fiftyfold change. A surface does not get darker as it goes away, which is why aerial perspective has to be the air.00.50011020304050distance from the camera to the wall (m)relative to the value at 1 mthe patch, growing as d²the light per unit area, falling as 1/d²their product — what the picture records2500× the footprint at the far endproduct flat to 2e-16
Fig. 6 And the photometric neighbour, from the light field. A surface does not get dimmer with distance, because the solid angle a pixel subtends shrinks at exactly the rate that compensates — which is the same Jacobian this essay is weighting by, met as a fact about brightness rather than about counting.

The same weight, everywhere else

Once stated, the Jacobian turns up in every measurement made by counting picture, and it is worth listing them because the sky is only the most obvious.

Canopy cover, from a fisheye pointed up through trees, has exactly this structure and the same one-sided bias — worse, because the obstruction of interest is concentrated near the horizon where the weight is furthest from 1.

Sky-view factor, the fraction of the hemisphere a point in a street can see, is a solid-angle integral and is routinely computed by counting pixels in an upward fisheye.

Illuminance from a source of known shape is an integral of a cosine against solid angle, so it needs the same weight and a second one on top of it.

And coverage of a projected image — what fraction of a dome or a wall a projector’s frame reaches — is the same integral run the other way, from a flat picture surface onto a curved receiver.

In every case the operation is “sum something over the picture”, and in every case the sum is a solid-angle integral wearing a pixel count’s clothes.

How much of a ball a source lightsThe curve is (1 − R/D)/2 and the dots are a quadrature over the surface that tests each patch by whether it can see the source. A lamp 2 radii away lights 25.00% of the ball, not 50% — the half is the limit and nothing finite reaches it.0204051015distance from the source to the ball, in radiifraction of the ball's surface that is lit (%)one half — the source at infinity25.0% at 2 radiicurve: the closed form · dots: quadratureagreeing to 5e-4
Fig. 7 The neighbouring integral in the light field. What fraction of a ball a lamp lights is a solid-angle question answered by integrating over the sphere, and the answer is less than half for any lamp at a finite distance.
What keystone correction actually costsA projector turned 12° from square throws its rectangular panel as a quadrilateral. Correction cannot add light outside it, so it shrinks the picture until it fits — and 14.7% of the projector's pixels are thrown away. The fraction is measured on the panel rather than on the wall, because turning the projector makes the wall picture larger while making the panel usage smaller.12° of yaw, 6° of pitch, 1.50 throw ratio85.3% of the panel reaches the corrected rectangleouter: the thrown quadrilateral · inner: what correction can keep14.7% of the panel discarded
Fig. 8 And the coverage version. Turning a projector off square costs a measurable fraction of its panel, and the fraction is an area ratio computed on the receiving surface rather than on the projector’s own.

How much of the sky a camera can see at all

There is a prior question that the field-of-view convention above hides, and it decides whether any of this is available.

A sky camera measuring cloud cover wants the whole hemisphere: 90° from the zenith, a solid angle of 2π2\pi. A flat lens cannot reach it at any focal length, because the picture is unbounded as the field approaches 180° — so a rectilinear sky camera is not a badly weighted instrument for a hemisphere, it is an instrument that does not cover the domain.

That is why the comparison here is run at 70° rather than at 90°. It is the widest field every one of the four surfaces can hold, and comparing them over a field one of them cannot reach would be comparing coverage rather than weighting.

The practical consequence is a two-stage question, in order. Can this surface hold the field? and only then does it weight the field correctly? The four rules all pass the first out to 180° and beyond; the flat plane fails it well before, and no Jacobian repairs a direction that has no image.

How wide the picture gets as the field of view opensOn a flat plane the picture's half-width is tan(θ/2): it multiplies by 6.6 between 120° and 170° and is unbounded at 180°. On a cylinder it multiplies by 1.42 over the same range and keeps going past 180° without incident.0246850100150field of view across the picture (degrees)half-width of the picture, in focal lengthsplanecylinderstereographicequidistantcut off at eight focal lengthsthe plane crosses it at 166°
Fig. 9 The first question, answered. On a flat plane the picture’s half-width is tan(θ/2)\tan(\theta/2) and is unbounded at 180°; on a cylinder it grows gently and continues past 180° without incident.

What the grid error bounds

There is one more number worth pinning down, because a measurement with an unstated resolution is not finished.

The grid error is the whole of the equal-area row’s departure from truth, and it comes from cells straddling a cloud’s boundary. It therefore scales like the ratio of boundary length to area — inversely with the grid’s linear size — and doubling the grid roughly halves it, which is what the coarser-grid figure shows.

That gives the claim a bound with a slope. At 401 squares the error is 0.01% relative; at 241 it is larger; and there is no grid at which the other three rows come right, because their error is not a discretisation at all.

Distinguishing those two is the useful skill. A number that shrinks when the grid is refined is a numerical artefact. A number that does not is the physics, or in this case the geometry.

Where the sample sits inside the pixel, and what a recovery calls the differenceSampling at the pixel's corner instead of its centre translates every mark by half a pixel in each axis — 0.7071 px — and the site's own recovery reads that as a principal point 0.707 px from where it should be, with the focal length changed by 4.5e-13 px. The other half-pixel error, mapping the viewport onto W−1 pixels instead of W, does the opposite: it leaves the principal point alone and shortens the focal length by 1.30 px.one pixel is an areacentrescornersprincipal point moves0.707 pxfocal length changes by4.5e-13 pxan edge-versus-centre viewport1.303 pxa half-pixel convention is a principal-point error; an off-by-one viewport is a focal-length error8 vertices, all shifted by the same 0.7071 pxspread across marks 0.0e+0 px
Fig. 10 The other place a half-pixel decides an answer on this site. Sampling at cell centres rather than corners is a choice with a consequence, and the consequence is exactly the boundary effect that bounds the count above.
The gap between walking the page and walking the surfaceFor a surface receding from 2 m to 8 m, the departure peaks at 0.3333 of the whole range — over half of it — at s = 0.6667. The closed form is (√k−1)/(√k+1) with k the depth ratio, and the marked point is where it says the peak is.-0.300-0.200-0.100000.2000.4000.6000.8001position across the drawn surfacehow far along the real surface, minus how far along the drawn one(√k−1)/(√k+1) = 0.3333at the page's midpoint, 30.0%depth ratio 4 : 1peak 0.3333 at s = 0.667
Fig. 11 And a systematic error for contrast, from the machine field: the gap between walking a page and walking the surface it depicts, which peaks at a third of the whole range and has a closed form. It does not shrink with a finer grid, because it is not a grid error.

Where the true answer could have come from instead

The caps are a device and it is worth saying what the alternatives would have cost, because the choice is the reason this essay is a measurement.

A dense direction sample. Scatter a few million directions uniformly over the field and count how many fall in cloud. That is a Monte Carlo estimate with its own error of order one over the square root of the count, and comparing a pixel count against it would be comparing two approximations. Better than nothing and not a reference.

A finer version of the same pixel count. Circular, obviously: it assumes the thing under test.

A closed form for an arbitrary painted mask. There isn’t one, which is why the mask is not arbitrary.

Caps. A cap’s solid angle is elementary and disjoint caps add, so the cover is exact and the only conditions are geometric ones that can be checked. The cost is that the clouds are round, which is a loss of realism and no loss of generality: nothing in the counting operation knows the shape of the region it is summing over.

That is a pattern worth naming, because this site uses it constantly. When a measurement needs a reference, arrange the scene so the reference is a closed form — even if that makes the scene artificial — rather than compare two estimates and call the difference an error.

What to do

Know the rule. Not the brand, not the word fisheye: the function from angle to radius. Fit it from a photograph of known angular structure if it was not supplied.

Weight by the reciprocal of the area scale, unless the rule is already equal-area, in which case the weight is 1 and a plain count is correct.

State the field being counted and count the same field on every instrument being compared, or the comparison includes the field of view.

And report the grid error. It is the only part of the answer that improves with effort, and knowing its size is what says whether more effort is worth spending.

Counting cloud by counting pixels, on four picture surfacesOne sky, four cameras. The cloud really covers 10.31% of the 70° field, exactly, because it is made of caps whose solid angles add. Counting the pixels inside it gives 10.31%, 9.36%, 7.57%, 2.40% — right on the equal-area fisheye to 0.01%, which is the grid's own error, and out by -9%, -27%, -77% on the others. Weighting each pixel by the surface's area scale brings every one of them back to within 0.03%.share of the 70° field counted as cloud — the truth is 10.31%equal-area fisheye10.31% (+0.0%)equidistant fisheye9.36% (-9.2%)stereographic7.57% (-26.6%)flat plane2.40% (-76.7%)481² of picture, four caps of cloud0.01% on the equal-area rule, -77% on the flat plane
Fig. 12 The measurement at a finer grid, where the equal-area row’s error falls again and the other three do not — which is the whole diagnostic in one picture.
What each picture surface does to areaA square degree of world, printed at each angle off the axis, against what the same square degree prints in the middle of the picture. The equal-area fisheye is flat at 1 to 8.3e-8 across 50°; the equidistant one reaches 1.14×, the cylinder 1.68×, stereographic 1.48× and the flat plane 4×. The sweep runs at 45° to the axes on purpose: straight across, the cylinder reads a perfect 1.00 and is not equal-area at all.00.2000.4000.60001020304050angle off the axis (degrees)area printed per solid angle, against its value on axis (log₁₀)equal-areaequidistantcylinderstereographicplaneswept at 45° to the axes, out to 50°equal-area 1.000 · flat plane 4×
Fig. 13 And the regime where all of this nearly goes away. Inside 50° off axis every one of these surfaces is within a factor of two, which is why a count made in the middle of a frame is far less exposed than one made over the whole of it.
How wide the picture gets as the field of view opensOn a flat plane the picture's half-width is tan(θ/2): it multiplies by 6.6 between 120° and 170° and is unbounded at 180°. On a cylinder it multiplies by 1.42 over the same range and keeps going past 180° without incident.0246850100150field of view across the picture (degrees)half-width of the picture, in focal lengthsplanecylinderstereographicequidistantcut off at eight focal lengthsthe plane crosses it at 166°
Fig. 14 And why a flat lens is not a candidate for this job at any resolution. Its picture is unbounded as the field approaches 180°, and the area weight runs away with it.

Shares its objects with

Essays that name at least two of the same things, and that neither author linked.

Named objects

A flat tag is an object no other essay names yet.

Area scaleEquidistantEquisolidFisheyeinstrument limitJacobiannecessary, not sufficientQuadraturesingle-view metrologySolid angleStereographic