Nitrogen-vacancy (NV) centers show great potential for nanoscale biosensing and bioimaging. Nevertheless, their envisioned bioapplications suffer from intrinsic background noise due to unavoidable light scattering and autofluorescence in cells and tissues. Herein, we develop a unique all-optical modulated imaging method via a physically enabled classifier, for on-demand and direct access to NV fluorescence at pixel resolution while effectively filtering out background noise. Specifically, NV fluorescence can be modulated optically to exhibit sinusoid-like variations, providing a basis for classification. We validate our method in various complex biological scenarios with fluorescence interference, ranging from cells to organisms. Notably, our classification-based approach achieves an enhancement of signal-to-background ratio from 1.92 to 60.39 dB for fluorescent nanodiamonds in neural protein imaging. We also demonstrate a 4-fold contrast improvement in optically detected magnetic resonance measurements inside stained cells. Our technique offers a generic, explainable, and robust solution, applicable for realistic high-fidelity imaging and sensing in challenging noise-laden scenarios.