% function to calculate the energy of a 2D image function E = energy (a) E = sum(sum(a.*a));