A method for calculating stored magnetic energy in a thin superconducting film based on quantitative magneto-optical imaging is developed. Energy and magnetic moment are determined with these calculations for full hysteresis loops in a thin film of the superconductor NbN. Huge losses in energy are observed when dendritic avalanches occur. Magnetic energy, magnetic moment, sheet current and magnetic flux distributions, all extracted from the same calibrated magneto-optical images, are analyzed and discussed. Dissipated energy and the loss in moment when dendritic avalanches occur are related to each other. Calculating these losses for specific spatially-resolved flux avalanches is a great advantage, because of their unpredictable and non-reproducible nature. The relative losses in energy are much higher than the relative losses in moment.