Recent advances in imaging techniques offer the possibility of visualizing the three-dimensional structure of soils at very fine scales. To make use of such information, a thresholding process is commonly implemented to separate the image into solid particles and pores. Despite the multitude of thresholding algorithms available, their performance is being challenged by the complexity of the soil structure. Experience shows that, to improve thresholding performance, existing methods require significant input from a skilled operator, making the thresholding subjective. In this context, this article proposes a new, operator-independent thresholding technique based on the analysis of the intraclass grayscale variance. The method extends the well-established Otsu technique, by applying first a preclassification of the voxels corresponding to the solid phase. Then, a threshold value is determined through minimization of the intraclass variance of the unclassified voxels. The method was implemented globally, then locally for a range of window sizes, with the optimal window size selected as that for which the standardized grayscale variances of the two voxel populations are equal. Results on the three-dimensional soil images investigated suggest that the proposed method performs noticeably better than Otsu’s method, and in particular is robust enough to variations in image contrast and soil structure. Tested on a synthetic image, the new method produces a misclassification of only 2% of voxels, compared to 4.9% with Otsu’s method. These results suggest that the proposed method can be very useful in the analysis of images of a variety of heterogeneous media, including soils.