This paper introduces an adaptive threshold algorithm based on variational methods which generalizes the Mumford-Shah and Chan-Vese functionals. It assumes a piecewise smooth model of the image and a closed contour, realized as the zero level set of a function. This functional is built upon an adaptive threshold surface coupled with the smoothed image. The algorithm uses the image boundaries found during the process of calculating the adaptive threshold surface to also smooth the image while preserving object boundaries, thus also improving the thresholding result. The resulting adaptive threshold surface provides a good approximation of the illumination function and thus can also be used to flatten the image. This method provides good smoothing results even in cases where the image can't be segmented using adaptive thresholding techniques.