A Robust Hit-or-Miss Transform for Template Matching in Very Noisy Astronomical Images