Statistics for Autofocusing and image segmentation in microscopy for automatic detection of tuberculosis in sputum smears