New applications such as printing on demand and personalized printing have increased the need for efficient lossless halftone image compression algorithms to lower the transmission time and the storage costs. State-of-the-art lossless bilevel image compression schemes like JBIG achieve only moderate compression ratios because they do not fully take into account the special image characteristics. In this paper, we present an improvement on the context modeling scheme by adapting the context template to the special patterns of halftone images. This is a nontrivial problem for which we propose a fast and efficient context template selection scheme based on the sorted autocorrelation function of a part of the image. We have experimented with classical halftones of different resolutions and sizes, screened under different angles, as well as with stochastic halftones. For classical halftones, the global improvement with respect to JBIG in its best mode is about 30%–50%. For stochastic halftones, the autocorrelation-based template gives no improvement, though a much slower exhaustive search technique shows that gains up to 70% are feasible using a suboptimal template. Binary tree modeling increases the compression ratio by another 5%–10%. Context modeling can also be used for other types of halftone image processing.