当前位置: 首页 > news >正文

有哪些外贸公司网站做的比较好安卓内核级优化神器

有哪些外贸公司网站做的比较好,安卓内核级优化神器,美容美发网站源码,做eso哪家网站好目录 十五、图像分割 简单阈值分割 (threshold) 自适应阈值分割 (adaptiveThreshold) 颜色范围分割 (inRange) 分水岭算法 (watershed) 泛洪填充 (floodFill) GrabCut算法 (grabCut) 距离变换 (distanceTransform) 最大稳定极值区域检测 (MSER) 均值漂移滤波 (pyrMean…

目录

十五、图像分割

简单阈值分割 (threshold)

自适应阈值分割 (adaptiveThreshold)

颜色范围分割 (inRange)

分水岭算法 (watershed)

泛洪填充 (floodFill)

GrabCut算法 (grabCut)

距离变换 (distanceTransform)

最大稳定极值区域检测 (MSER)

均值漂移滤波 (pyrMeanShiftFiltering)

十六、连通域

计算连通组件 (connectedComponents)

计算连通组件并返回统计信息 (connectedComponentsWithStats)

解释

http://t.csdnimg.cn/i8pqt —— opencv—常用函数学习_“干货“_总(VIP)

散的正在一部分一部分发,不需要VIP。

资料整理不易,有用话给个赞和收藏吧。


十五、图像分割

        在OpenCV中,图像分割是将图像分割成不同区域或对象的过程,常用于对象检测、识别和图像分析。下面介绍一些常用的图像分割函数及其使用示例。

图像分割函数
thresholdadaptiveThresholdinRangewatershedfloodFill
简单阈值分割自适应阈值分割颜色范围分割分水岭算法泛洪填充
grabCutdistanceTransformMSERpyrMeanShiftFiltering
GrabCut算法距离变换最大稳定极值区域检测均值漂移滤波
简单阈值分割 (threshold)
import cv2
import numpy as np# 读取图像
image = cv2.imread('path_to_image.jpg', cv2.IMREAD_GRAYSCALE)# 应用简单阈值分割
_, binary_image = cv2.threshold(image, 127, 255, cv2.THRESH_BINARY)
cv2.imshow('Binary Image', binary_image)
cv2.waitKey(0)
cv2.destroyAllWindows()
自适应阈值分割 (adaptiveThreshold)
# 应用自适应阈值分割
adaptive_thresh = cv2.adaptiveThreshold(image, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C,cv2.THRESH_BINARY, 11, 2)
cv2.imshow('Adaptive Threshold Image', adaptive_thresh)
cv2.waitKey(0)
cv2.destroyAllWindows()
颜色范围分割 (inRange)
# 读取彩色图像
color_image = cv2.imread('path_to_image.jpg')# 定义颜色范围
lower_bound = np.array([0, 120, 70])
upper_bound = np.array([10, 255, 255])# 转换到HSV颜色空间
hsv_image = cv2.cvtColor(color_image, cv2.COLOR_BGR2HSV)# 应用颜色范围分割
mask = cv2.inRange(hsv_image, lower_bound, upper_bound)
cv2.imshow('Mask', mask)
cv2.waitKey(0)
cv2.destroyAllWindows()
分水岭算法 (watershed)
# 读取图像并转换为灰度图
gray = cv2.cvtColor(color_image, cv2.COLOR_BGR2GRAY)
_, binary = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)# 确定背景区域
kernel = np.ones((3, 3), np.uint8)
sure_bg = cv2.dilate(binary, kernel, iterations=3)# 确定前景区域
dist_transform = cv2.distanceTransform(binary, cv2.DIST_L2, 5)
_, sure_fg = cv2.threshold(dist_transform, 0.7 * dist_transform.max(), 255, 0)# 确定未知区域
sure_fg = np.uint8(sure_fg)
unknown = cv2.subtract(sure_bg, sure_fg)# 标记连通组件
_, markers = cv2.connectedComponents(sure_fg)# 为确保背景为1,增加1
markers = markers + 1# 将未知区域标记为0
markers[unknown == 255] = 0# 应用分水岭算法
markers = cv2.watershed(color_image, markers)
color_image[markers == -1] = [0, 0, 255]cv2.imshow('Watershed', color_image)
cv2.waitKey(0)
cv2.destroyAllWindows()
泛洪填充 (floodFill)
# 应用泛洪填充
flood_filled = color_image.copy()
h, w = flood_filled.shape[:2]
mask = np.zeros((h + 2, w + 2), np.uint8)
cv2.floodFill(flood_filled, mask, (0, 0), (255, 0, 0))cv2.imshow('Flood Fill', flood_filled)
cv2.waitKey(0)
cv2.destroyAllWindows()
GrabCut算法 (grabCut)
# 初始化掩码
mask = np.zeros(color_image.shape[:2], np.uint8)# 定义矩形
rect = (50, 50, 450, 290)# 定义模型
bgdModel = np.zeros((1, 65), np.float64)
fgdModel = np.zeros((1, 65), np.float64)# 应用GrabCut算法
cv2.grabCut(color_image, mask, rect, bgdModel, fgdModel, 5, cv2.GC_INIT_WITH_RECT)
mask2 = np.where((mask == 2) | (mask == 0), 0, 1).astype('uint8')
grabcut_image = color_image * mask2[:, :, np.newaxis]cv2.imshow('GrabCut', grabcut_image)
cv2.waitKey(0)
cv2.destroyAllWindows()
距离变换 (distanceTransform)
# 应用距离变换
dist_transform = cv2.distanceTransform(binary, cv2.DIST_L2, 5)
cv2.imshow('Distance Transform', dist_transform)
cv2.waitKey(0)
cv2.destroyAllWindows()
最大稳定极值区域检测 (MSER)
# 创建MSER对象
mser = cv2.MSER_create()# 检测MSER区域
regions, _ = mser.detectRegions(gray)# 绘制检测到的区域
output = color_image.copy()
for p in regions:hull = cv2.convexHull(p.reshape(-1, 1, 2))cv2.polylines(output, [hull], 1, (0, 255, 0))cv2.imshow('MSER', output)
cv2.waitKey(0)
cv2.destroyAllWindows()
均值漂移滤波 (pyrMeanShiftFiltering)
# 应用均值漂移滤波
mean_shift_image = cv2.pyrMeanShiftFiltering(color_image, 21, 51)
cv2.imshow('Mean Shift Filtering', mean_shift_image)
cv2.waitKey(0)
cv2.destroyAllWindows()

        这些示例展示了如何使用OpenCV中的各种图像分割函数来处理图像。根据具体的应用需求,可以灵活运用这些函数来实现复杂的图像分割任务。

十六、连通域

        在OpenCV中,连通域分析是图像处理中的一个重要步骤,用于检测和标记图像中的连通区域。主要有两个函数:connectedComponentsconnectedComponentsWithStats。下面介绍这些函数及其使用示例。

连通域分析函数
connectedComponentsconnectedComponentsWithStats
计算连通组件计算连通组件并返回统计信息
计算连通组件 (connectedComponents)
import cv2
import numpy as np# 读取图像并转换为灰度图
image = cv2.imread('path_to_image.jpg', cv2.IMREAD_GRAYSCALE)# 应用阈值处理
_, binary_image = cv2.threshold(image, 127, 255, cv2.THRESH_BINARY)# 计算连通组件
num_labels, labels = cv2.connectedComponents(binary_image)# 显示结果
label_hue = np.uint8(179 * labels / np.max(labels))
blank_ch = 255 * np.ones_like(label_hue)
labeled_img = cv2.merge([label_hue, blank_ch, blank_ch])# 转换到BGR颜色空间
labeled_img = cv2.cvtColor(labeled_img, cv2.COLOR_HSV2BGR)# 设置背景为黑色
labeled_img[label_hue == 0] = 0cv2.imshow('Connected Components', labeled_img)
cv2.waitKey(0)
cv2.destroyAllWindows()
计算连通组件并返回统计信息 (connectedComponentsWithStats)
# 计算连通组件及统计信息
num_labels, labels, stats, centroids = cv2.connectedComponentsWithStats(binary_image)# 输出每个连通组件的统计信息
for i in range(num_labels):print(f"Component {i}:")print(f"  Bounding box: {stats[i, cv2.CC_STAT_LEFT]}, {stats[i, cv2.CC_STAT_TOP]}, "f"{stats[i, cv2.CC_STAT_WIDTH]}, {stats[i, cv2.CC_STAT_HEIGHT]}")print(f"  Area: {stats[i, cv2.CC_STAT_AREA]}")print(f"  Centroid: {centroids[i]}")# 显示结果
label_hue = np.uint8(179 * labels / np.max(labels))
blank_ch = 255 * np.ones_like(label_hue)
labeled_img = cv2.merge([label_hue, blank_ch, blank_ch])# 转换到BGR颜色空间
labeled_img = cv2.cvtColor(labeled_img, cv2.COLOR_HSV2BGR)# 设置背景为黑色
labeled_img[label_hue == 0] = 0cv2.imshow('Connected Components with Stats', labeled_img)
cv2.waitKey(0)
cv2.destroyAllWindows()
解释
  • connectedComponents:此函数返回连通组件的数量和每个像素所属的标签。
  • connectedComponentsWithStats:此函数除了返回标签外,还返回每个连通组件的统计信息(如边界框、面积)和重心。

        这些示例展示了如何使用OpenCV中的连通域分析函数来处理图像。根据具体的应用需求,可以灵活运用这些函数来实现复杂的连通域检测和分析任务。

http://www.rdtb.cn/news/19591.html

相关文章:

  • 如需武汉手机网站建设环球网最新消息疫情
  • 德州做网站的湖南知名网络推广公司
  • 邢台做移动网站的地方市场营销策划方案书
  • 河南疫情防控最新政策重庆网站优化公司
  • 网站建设前期团队建设seo优化课程
  • 当当网网站的建设过程深圳品牌seo
  • 网站开发用户登陆的安全夫唯老师seo
  • 烟台定制网站建设报价sem搜索
  • 小程序微信怎么开发抖音seo代理
  • 电商网站开发费用登录百度账号
  • 内存128mb做网站够吗上海seo外包公司
  • 重庆潼南网站建设鞍山seo外包
  • 批发网站宁德市医院
  • 厦门专业网站制作自己做网站需要什么条件
  • 阿里云网站备案信息真实性核验单seo研究中心培训机构
  • 做中英文网站 java快速关键词排名首页
  • 搭建什么网站比较赚钱制作网站教学
  • 厦门微网站建设公司广东省自然资源厅
  • 怎么做类似淘宝网站如何优化网络连接
  • 网站开发的英文书有什么海城seo网站排名优化推广
  • 官网网站建设收费seo外链友情链接
  • 龙岗区做网站教育培训网
  • 长春网站设计团队百度关键词自然排名优化公司
  • 如何在各个购物网站之间做差价九江seo优化
  • wordpress 安装权限武汉seo网站排名优化公司
  • 如何创建个人的网站秦皇岛seo优化
  • 佛山网站建设公司排名seo关键词优化系统
  • 备案期间网站可以做竞价吗企业网站的在线推广方法有
  • 东莞做网站定制十大推广app平台
  • 做网站网页的人是不是思维爱站网关键词密度