做性的网站有哪些内容,wordpress页码颜色变更,公关公司排行,网站seo自己怎么做欢迎关注 『youcans 的 OpenCV 例程 200 篇』 系列#xff0c;持续更新中 欢迎关注 『youcans 的 OpenCV学习课』 系列#xff0c;持续更新中 【youcans 的 OpenCV 例程200篇】168.图像分割之区域生长 4. 区域分割的基本方法
4.1 区域生长
区域生长方法将具有相似性质的像素… 欢迎关注 『youcans 的 OpenCV 例程 200 篇』 系列持续更新中 欢迎关注 『youcans 的 OpenCV学习课』 系列持续更新中 【youcans 的 OpenCV 例程200篇】168.图像分割之区域生长 4. 区域分割的基本方法
4.1 区域生长
区域生长方法将具有相似性质的像素或子区域组合为更大区域。
区域生长方法是以区域为处理对象基于区域内部和区域之间的同异性尽量保持区域中像素的临近性和一致性的统一 。
区域生长的基本方法是对于一组“种子”点通过把与种子具有相同预定义性质如灰度或颜色范围的邻域像素合并到种子像素所在的区域中再将新像素作为新的种子不断重复这一过程直到没有满足条件的像素为止。
种子点的选取经常采用人工交互方法实现也可以寻找目标物体并提取物体内部点或利用其它算法找到的特征点作为种子点。
区域增长方法的步骤 1对图像自上而下、从左向右扫描找到第 1 个还没有访问过的像素将该像素作为种子 (x0, y0) 2以 (x0, y0) 为中心, 考虑其 4 邻域或 8 邻域像素 (x, y)如果其邻域满足生长准则 则将 (x, y) 与 (x0, y0) 合并到同一区域同时将 (x, y) 压入堆栈 3从堆栈中取出一个像素作为种子 (x0, y0) 继续步骤2 4当堆栈为空时返回步骤1; 5重复步骤1-4直到图像中的每个点都被访问过算法结束。 例程 11.25图像分割之区域生长 # # 11.25 图像分割之区域生长def getGrayDiff(image, currentPoint, tmpPoint): # 求两个像素的距离return abs(int(image[currentPoint[0], currentPoint[1]]) - int(image[tmpPoint[0], tmpPoint[1]]))# 区域生长算法def regional_growth(img, seeds, thresh5):height, weight img.shapeseedMark np.zeros(img.shape)seedList []for seed in seeds:if (0seed[0]height and 0seed[1]weight): seedList.append(seed)label 1 # 种子位置标记connects [(-1,-1), (0,-1), (1,-1), (1,0), (1,1), (0,1), (-1,1), (-1,0)] # 8 邻接连通while (len(seedList) 0): # 如果列表里还存在点currentPoint seedList.pop(0) # 将最前面的那个抛出seedMark[currentPoint[0], currentPoint[1]] label # 将对应位置的点标记为 1for i in range(8): # 对这个点周围的8个点一次进行相似性判断tmpX currentPoint[0] connects[i][0]tmpY currentPoint[1] connects[i][1]if tmpX0 or tmpY0 or tmpXheight or tmpYweight: # 是否超出限定阈值continuegrayDiff getGrayDiff(img, currentPoint, (tmpX, tmpY)) # 计算灰度差if grayDiffthresh and seedMark[tmpX,tmpY]0:seedMark[tmpX, tmpY] labelseedList.append((tmpX, tmpY))return seedMark# 区域生长 主程序img cv2.imread(../images/Fig1051a.tif, flags0)# # 灰度直方图# histCV cv2.calcHist([img], [0], None, [256], [0, 256]) # 灰度直方图# OTSU 全局阈值处理ret, imgOtsu cv2.threshold(img, 127, 255, cv2.THRESH_OTSU) # 阈值分割, threshT# 自适应局部阈值处理binaryMean cv2.adaptiveThreshold(img, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 5, 3)# 区域生长图像分割# seeds [(10, 10), (82, 150), (20, 300)] # 直接给定 种子点imgBlur cv2.blur(img, (3,3)) # cv2.blur 方法_, imgTop cv2.threshold(imgBlur, 250, 255, cv2.THRESH_BINARY) # 高百分位阈值产生种子区域nseeds, labels, stats, centroids cv2.connectedComponentsWithStats(imgTop) # 过滤连通域获得质心点 (x,y)seeds centroids.astype(int) # 获得质心像素作为种子点imgGrowth regional_growth(img, seeds, 8)plt.figure(figsize(8, 6))plt.subplot(221), plt.axis(off), plt.title(Origin)plt.imshow(img, gray)plt.subplot(222), plt.axis(off), plt.title(OTSU(T{}).format(ret))plt.imshow(imgOtsu, gray)plt.subplot(223), plt.axis(off), plt.title(Adaptive threshold)plt.imshow(binaryMean, gray)plt.subplot(224), plt.axis(off), plt.title(Region grow)plt.imshow(255-imgGrowth, gray)plt.tight_layout()plt.show()本节完 版权声明
youcansxupt 原创作品转载必须标注原文链接(https://blog.csdn.net/youcans/article/details/124472048)
Copyright 2022 youcans, XUPT Crated2022-4-30 欢迎关注 『youcans 的 OpenCV 例程 200 篇』 系列持续更新中 欢迎关注 『youcans 的 OpenCV学习课』 系列持续更新中 【youcans 的 OpenCV 例程200篇】168.图像分割之区域生长 【youcans 的 OpenCV 例程200篇】169.图像分割之区域分离 【youcans 的 OpenCV 例程200篇】170.图像分割之K均值聚类 更多内容请见 【OpenCV 例程200篇 总目录-202206更新】