Given the initial segmentation, then, boundaries are refined by examining each boundary pixel iteratively. The ratio of the likelihood function p(Y,Q) for the 3x3 neighborhood of the each boundary pixel is computed. The label of the boundary pixel is changed, if necessary, to the label of the neighbor that maximizes the ratio. The algorithm is stopped when the number of boundary labels altered is less than a threshold.