A general approach for calculating tip-sample capacitance variation in near-field scanning microwave microscopy is presented. It can be applied to arbitrary tip shapes, thick and thin films, and variation due to inhomogeneous perturbation. The computation domain for the tip-sample interaction problem is reduced to a block perturbation area by applying Green's theorem, and thus it can save substantial time and memory during calculating either electric field or contrast capacitance for three-dimensional models of near-field microwave microscopy. We show that this method can accurately calculate capacitance variation due to inhomogeneous perturbation in insulating or conductive samples, as verified by finite-element analysis results of commercial software and experimental data from microwave impedance microscopy. More importantly, the method in this paper also provides a rigorous framework to solve the inverse problem, which has great potential to improve resolution by deconvolution.Index Terms-Inhomogeneous perturbation, microwave impedance microscopy (MIM), near-field scanning microwave microscopy (NSMM), tip-sample interaction.