It is challenging to detect foreground objects when background includes an illumination variation, shadow or structural variation due to their motion. Basically pixel-based background models suffer from statistical randomness of each pixel. This paper proposes an algorithm that incorporates Markov random field(MRF) model into pixel-based background modelling to achieve more accurate foreground detection. Under the assumptions the distance between the pixel on the input image and the corresponding background model and the difference between the scene estimates of the spatio-temporally neighboring pixels are exponentially distributed, a recursive approach for estimating the MRF regularizing parameters is proposed. The proposed method alternates between estimating the parameters with the intermediate foreground detection results and detecting the foreground with the estimated parameters, after computing them with the detection results of the pixel-based background subtraction. Extensive experiment is conducted with several videos recorded both indoors and outdoors to compare the proposed method with the codebook-based algorithm.