We introduce TREM, an algorithm for resolving clusters of nearly identical objects. TREM builds on generative model incorporating a template representing the object. Algorithm applied to microscopy data of the diatom Seminavis robusta. TREM is evaluated against three alternative algorithms.