corrected = (raw − dark) ÷ (flat − dark) × mean(flat − dark)
The dark frameLoading... is subtracted first from both the image and the reference, because the camera's offset is not light and must not be divided. Dividing by the dark-subtracted flat then removes the illumination pattern: a pixel that receives 70% of the center's light in the flat is divided by 0.7. Multiplying by the mean of the flat restores the original units, so blank glass in the corrected image reads the same average brightness it did before.
The correction is applied per channel in a color image, which also removes small color differences between center and edge.