Theory of cathodoluminescence contrast from localized defects in semiconductors