Convolutional neural networks (CNNs) have achieved prominent performance in a series of image processing problems. CNNs become the first choice for dense classification problems such as semantic segmentation. However, CNNs predict the class of each pixel independently in semantic segmentation tasks, spatial regularity of the segmented objects is still a problem for these methods. Especially when given few training data, CNN could not perform well in the details, isolated and scattered small regions often appear in all kinds of CNN segmentation results. In this paper, we propose a method to add spatial regularization to the segmented objects. In our method, the spatial regularization such as total variation (TV) can be easily integrated into CNN network and it produces smooth edges and eliminate isolated points. We apply our proposed method to Unet and Segnet, which are well-established CNNs for image segmentation, and test them on WBC and CamVid datasets, respectively. The results show that the details of predictions are well improved by regularized networks.