Spectral filtering suppresses the amplification of errors when computing solutions to ill-posed inverse problems; however, selecting good regularization parameters is often expensive. In many applications, data are available from calibration experiments. In this paper, we describe how to use such data to precompute optimal spectral filters. We formulate the problem in an empirical Bayes risk minimization framework and use efficient methods from stochastic and numerical optimization to compute optimal filters. Our formulation of the optimal filter problem is general enough to use a variety of assessments of goodness of the solution estimate, not just the mean square error. The relationship with the Wiener filter is discussed, and numerical examples from signal and image deconvolution illustrate that our proposed filters perform consistently better than well-established filtering methods. Furthermore, we show how our approach leads to easily computed uncertainty estimates for the pixel values.