Add median filtering and labeling.