This paper proposes a generalized technique for computing the factor of encircled energy (FEE) in a diffraction image from the optical transfer function (OTF) of the imaging system. This technique is applicable to diffraction-limited optical systems as well as to systems suffering from any aberrations, provided the transfer function of the same is known. It is also applicable to any kind of rotationally symmetric or asymmetric apertures. The accuracy of the results depends on the precision with which the OTF of the system can be determined. The FEE values are obtained using this technique for an aberration-free spherical lens as well as for the same having primary spherical aberration. The results are computed for the Gaussian image plane and other observation planes and are compared with the previously reported results. A numerical technique for computing the FEE in a diffraction pattern formed by a conventional lens suffering from off-axis aberrations and that formed by rotationally asymmetric apertures is also depicted.