At least one image of the environment is taken using either an image capturing device of the monitoring system. Based on the image of the environment, at least one background image is generated. The background image, which comprises a plurality of pixels, is divided into pixel blocks. In each pixel block, at least one data cluster is formed using at least one feature of the pixels in the pixel block. The data cluster formed in each pixel block is described as a data distribution having a mean value and a standard deviation from the mean value. After generating the background image, a subsequent image is taken by the monitoring system. Each pixel of the subsequent image is compared with the data cluster of the block of the background image correspond to the pixel, and a first discrepancy value is generated accordingly. The pixel of the subsequent image is further compared with the data distribution of at least another pixel block which is adjacent to the pixel block of the background image corresponding to the pixel, and a second discrepancy value is generated as a result of this comparison. Based on the first and second discrepancy value, the pixel of the subsequent image is determined to be either a background pixel or a foreground pixel. After all the pixels in the subsequent image have been determined as either a background or a foreground pixel, a binary map is generated. The connected foreground pixels in the binary map are marked to form a foreground object, which is the detected objected in the environment according to the invention.