Several rod-shaped pathogens including Escherichia coli, Salmonella spp. and Klebsiella pneumonia are capable of adopting highly filamentous cell shapes under certain circumstances. This phenomenon occurs as a result of continued cell elongation during growth without the usual septation into single rod-shaped cells. Evidence has emerged over the past decade suggesting that this morphological transformation is controlled and reversible and provides selective advantages under certain growth conditions, such as during infection in humans. In order to identify the factors which induce filamentation of bacterial pathogens and study the advantages of bacterial morphological plasticity, methods are needed to accurately quantify changes in bacterial cell shape. In this study, we present a method for quantification of bacterial filamentation based on automatic detection and measurement of bacterial units in focus-stacked microscopy images. Used in combination with a flow-chamber based in vitro cystitis model, we study the factors involved in filament formation by uropathogenic E. coli (UPEC) during infection. The influence of substratum surface, intracellular proliferation and flow media on UPEC filamentation is evaluated. We show that reversible UPEC filamentation during cystitis is not dependent on intracellular infection, which previous studies have suggested. Instead, we find that filamentation can be induced by contact with surfaces, both biological and artificial. Lastly our data indicate that UPEC filamentation is induced by trace-amounts of specific components in urine, rather than being a generic stress-response to high urine salt concentrations. The study shows that the combined methodology is generally useful for investigation of bacterial morphological transitions during cell infection.