On the perturbation of the electromagnetic energy due to the presence of inhomogeneities with small diameters