Recorded surface waves often provide reasonable estimates of the S-wave velocity in the near surface. However, existing algorithms are mainly based on the 1D layered-model assumption and require picking the dispersion curves either automatically or manually. We propose a wave-equation based inversion algorithm that inverts for S-wave velocities using fundamental- and higher-modes Rayleigh waves, without picking an explicit dispersion curve. The proposed method aims to maximize the similarity of the phase velocity (f – v) spectrum of the observed and predicted surface waves with all-Rayleigh wave modes (if they exist) included in the inversion. The f – v spectrum is calculated using the linear Radon transform applied to a local similarity-based objective function, and thus, we do not need to pick velocities in spectrum plots. As a result, the best match between the predicted and observed f – v spectrum provides the optimal estimation of the S-wave velocity. We derive S-wave velocity updates using the adjoint-state method and solve the optimization problem using an LBFGS algorithm. Our method excels in cases where the S-wave velocity have vertical reversals and lateral variations, as we utilize all-modes dispersion, and it can suppress the local minimum problem often associated with full waveform inversion applications. Synthetic and field examples are used to verify the effectiveness of the proposed method.