Solution (source code)

= Solution

Let $k=m/2$. After offset subtraction, each summed image has mean $N$ <analogue-to-digital units> per <detector pixel>. For a constant <detector conversion gain> $g$ and independent <Poisson distribution> detected counts, $\operatorname{Var}(A)=\operatorname{Var}(B)=N/g$: summing $k$ independent frames adds both their means and <variances>. Here $N$ is the mean of the sum, not one frame.

Write $A=N+a$, $B=N+b$. At high counts, the <delta method> gives $A/B\simeq1+a/N-b/N$. Independence therefore gives
$$
E^2\simeq\frac{\operatorname{Var}(A)+\operatorname{Var}(B)}{N^2}=\frac{2}{gN},\qquad
\boxed{g\simeq\frac{2}{NE^2}.}
$$
Thus the formula is a high-signal <gain estimation from flat-field ratios>, not an exact identity for a ratio of <random variables>. A <Poisson distribution> denominator can even be zero at low counts. The exposures must be linear and unsaturated, offsets removed, and <read noise> negligible. Being close to saturation increases the signal but does not establish linearity; clipping or charge-induced correlations biases a <variance> estimate. A large ensemble of suitable <detector pixels> supplies the measured <standard deviation>. In normal <photodetector> terminology $g$ is collected <electrons> per <ADU>, consistent with detected <photons> here only under the stated unit-yield convention; see https://hst-docs.stsci.edu/wfc3dhb/chapter-5-wfc3-uvis-sources-of-error/5-1-gain-and-read-noise[the instrument gain definition].