This paper presents a new method for segmenting medical images is based on Hamiltonian quaternions and the associative algebra, method of the active contour model and LPA-ICI (local polynomial approximation - the intersection of confidence intervals) anisotropic gradient. Since for segmentation tasks, the image is usually converted to grayscale, this leads to the loss of important information about color, saturation, and other important information associated color. To solve this problem, we use the quaternion framework to represent a color image to consider all three channels simultaneously when segmenting the RGB image. As a method of noise reduction, adaptive filtering based on local polynomial estimates using the ICI rule is used. The presented new approach allows obtaining clearer and more detailed boundaries of objects of interest. The experiments performed on real medical images (Z-line detection) show that our segmentation method of more efficient compared with the current state-of-art methods.