米琪卡哇伊
使用 Cryckx 提到的形态很好,但您也可以使用距离变换,这会削弱薄部分(如故事),因此可以轻松切割。这是我得到的结果(我裁剪图像只是为了更好地可视化):Opencv C++ 代码:Mat im1 = imread("E:/1/2.jpg", 0);Mat im2, im3;threshold(im1, im2, 250, 255, THRESH_OTSU);imshow("Initial Thresholding", im2);Mat dist;distanceTransform(im2, dist, DIST_L2, 3);normalize(dist, dist, 0, 255.0, NORM_MINMAX);dist.convertTo(dist, CV_8U);imshow("Distance Transform Image", dist);Mat mask1, mask2, mask3;threshold(dist, mask1, 50, 255,THRESH_BINARY); // A suitable threshold to cut the weak taledilate(mask1, mask1, Mat::ones(9,9, CV_8U));imshow("Threshold on Distance Transform", mask1);bitwise_and(im2, mask1, mask2);imshow("mouse", mask2);subtract(im2, mask2, mask3);imshow("tale", mask3);waitKey(0);
慕标琳琳
形状分割的可靠方法是使用形状模型。本文给出了合理的介绍:https ://pdfs.semanticscholar.org/ebc2/ceba03a0f561dd2ab27c97b641c649c48a14.pdf 。这个想法是从一组图像(平均鼠标形状和该平均形状周围的变形)中学习统计模型。然后您可以使用该模型通过将其注册到看不见的形状来进行分割。只是为了好玩,我尝试了形态数学(侵蚀/膨胀),这似乎在你的图像上效果很好:)使用的 Python 代码:import numpy as npimport mathimport cv2 as cvmouse = cv.imread("mouse.jpg")kernel7 = np.ones((7,7),np.uint8)body = cv.morphologyEx(mouse, cv.MORPH_OPEN, kernel7)bodyErrode = cv.dilate(body,kernel7)mask= cv.bitwise_not( bodyErrode );mask2, tr = cv.threshold(mask, 120, 255, cv.THRESH_BINARY) tail = cv.bitwise_and(mouse,tr)cv.imshow("tail",tail)cv.imshow('body',body)cv.waitKey()