Colorimetric detection using microfluidic paper-based analytical devices (µPADs) and smartphones enable low-cost mobile chemical analysis solutions. However, variable illumination conditions and phone characteristics (i.e. camera hardware and software capabilities) limit the accurate interpretation and reproducibility of quantitative results. In this paper, we describe a method to automatically compensate an image captured by a smartphone camera under variable illumination conditions. By incorporating a two-step algorithm, we approximate the mobile camera picture color distribution to resemble a laboratory-grade measurement under reference illumination conditions. For every test image, the algorithm first applies a color mapping step that performs histogram matching of a set of color reference spots printed on the device to a laboratory reference measurement. After this initial correction step, a transformation matrix is computed via a least-square fit to minimize the differences between the device and the laboratory references. This matrix is then applied to the RGB channel values obtained from a µPAD to correct for illumination variations. The methodology was tested by correcting a test dataset captured using a smartphone to approximate to a calibration dataset acquired using a lab-grade camera. After correction, the relative error between the datasets fell to 10-20%, leading to an increase in classification accuracy between 12-33%. This approach enables colorimetric chemical analysis with smartphones outside the lab, removing the need to control external lighting conditions.