  Detection of templates (e.g., sources) embedded in low-number count Poisson
noise is a common problem in astrophysics. Examples include source detection in
X-ray images, gamma-rays, UV, neutrinos, and search for clusters of galaxies
and stellar streams. However, the solutions in the X-ray-related literature are
sub-optimal -- in some cases by considerable factors. Using the lemma of
Neyman-Pearson we derive the optimal statistics for template detection in the
presence of Poisson noise. We demonstrate that this method provides higher
completeness, for a fixed false-alarm probability value, compared with
filtering the image with the point-spread function (PSF). In turn, we find that
filtering by the PSF is better than filtering the image using the Mexican-hat
wavelet (used by wavedetect). For some background levels, our method improves
the sensitivity of source detection by more than a factor of two over the
popular Mexican-hat wavelet filtering. This filtering technique can also be
used also for fast PSF photometry and flare detection, and it is efficient, as
well as straight forward to implement. We provide an implementation in MATLAB.
