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 — a solid angle, which is the third column of the surface table and not the first two.

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 — the trap a conformal reprojection sets for anybody judging a surface by how it looks.

So the sky here is built from spherical caps. A cap of angular radius ρ\rho subtends a solid angle of exactly 2π(1−cos⁡ρ)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: sec⁡3θ\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, because the weight is the reciprocal of a quantity the surface table already publishes in closed form.

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.

The bias in closed form, and the table checked against it

The argument above says the bias is a correlation. It can be written as one, and once written it predicts the table rather than describing it.

The reported cover is picture area inside the clouds over picture area inside the field, and picture area is solid angle times the local area scale AA. So

reportedtrue  =  ⟨A⟩cloud⟨A⟩field,\frac{\text{reported}}{\text{true}} \;=\; \frac{\langle A\rangle_{\text{cloud}}}{\langle A\rangle_{\text{field}}},

the mean area scale over the clouds divided by the mean over the whole field, each averaged by solid angle. Everything the essay says qualitatively is in that ratio: it is one when AA is constant, which is the equal-area row; it is less than one when the clouds sit where AA is small, which is why every error here is negative; and it is exactly one for a uniform sky whatever AA does, which is the paradoxical case.

The averages are elementary because each AA integrates in closed form against sin⁡θ\sin\theta. Over a field to 70°:

surface ⟨A⟩field\langle A\rangle_{\text{field}}
plane 5.737
stereographic 1.490
equidistant 1.134
equal-area 1

Now use one row to locate the clouds and predict the rest. The flat plane reports 2.40 against a true 10.31, a ratio of 0.2328, which needs ⟨A⟩cloud=1.336\langle A\rangle_{\text{cloud}} = 1.336 — that is sec⁡3θ=1.336\sec^{3}\theta = 1.336, or clouds sitting at about 25° from the zenith, which is where the figure puts them.

Everything else follows with nothing further supplied:

surface ⟨A⟩cloud\langle A\rangle_{\text{cloud}} predicted measured
equidistant 1.032 9.38% 9.37%
stereographic 1.101 7.61% 7.56%
equal-area 1.000 10.31% 10.31%

Two independent rows predicted to under one per cent from a single inferred cloud position, which is about as much as a 401-cell grid over curved boundaries supports. The table is not four measurements; it is one measurement and a ratio of two integrals.

That form is more useful than the table because it says what to do when the sky is different. The bias is not a property of the lens — it is the lens’s area scale sampled where the subject happens to be, so it changes from photograph to photograph on the same camera. A sky whose cloud is at the horizon ring inverts every sign in the table; a sky with cloud at 45° on the equidistant lens has ⟨A⟩cloud=1.111\langle A\rangle_{\text{cloud}} = 1.111 and a bias of −2.0-2.0 per cent rather than −9-9; and a broken sky with cloud everywhere has almost none. Quoting a lens’s counting error as a single number is quoting the average sky it was measured on.

It also says something about which correction is worth making. Weighting each pixel by 1/A1/A removes the whole thing exactly, as the repair above shows — but a reader who cannot reprocess the pixels can still correct a published figure, provided the distribution of the subject over the field is known, because the correction factor is a ratio of two averages and both are computable from the lens rule alone. That is the same structure an area recovered from one photograph meets on the ground plane, where the two error laws are also a property of where the patch is rather than of the camera, and it is why the surface has to be chosen before anything is counted rather than after.

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 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. 6 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.

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. 7 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 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. 8 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 links here

Computed from the collection, not written here: the essays that point at this one.

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