We describe an optical-scanning-based imaging system for directly acquiring various spatial derivatives of images, using spatiotemporal modulation techniques in conjunction with electronic heterodyne detection. The technique, which in principle may be adapted to a realtime parallel detection scheme, offers the ability to acquire a variety of first-order and higher-order spatial derivatives. In addition, spatial resolution may be dynamically controlled in a simple electronic fashion. We demonstrate detection of first-order (directional gradients) and second-order spatial derivatives. We also discuss an application that utilizes our gradient detection technique, in a closed feedback system, to achieve contouring and tracking of stationary and moving objects. Experimental results are presented.