Automatic Correction of Intensity Nonuniformity from Sparseness of Gradient Distribution in Medical Images