We present a compressed sensing based approach to remove gain field from magnetic resonance (MR) images of the human brain. During image acquisition, the inhomogeneity present in the radio-frequency (RF) coil appears as shading artifact in the intensity image. The inhomogeneity poses problem in any automatic algorithm that uses intensity as a feature. It has been shown that at low field strength, the shading can be assumed to be a smooth field that is composed of low frequency components. Thus most inhomogeneity correction algorithms assume some kind of explicit smoothness criteria on the field. This sometimes limits the performance of the algorithms if the actual inhomogeneity is not smooth, which is the case at higher field strength. We describe a model-free, nonparametric patch-based approach that uses compressed sensing for the correction. We show that these features enable our algorithm to perform comparably with a current state of the art method N3 on images acquired at low field, while outperforming N3 when the image has non-smooth inhomogeneity, such as 7T images.