多目标图像分割(效果很好,推荐)

多目标图像分割

本人参考以下博客进行多目标进行分割,结果很好。

https://blog.csdn.net/weixin_42380114/article/details/103294631

运行环境:python,opencv

1、彩色图像阈值分割

以下是彩色图像阈值分割的代码,根据个人图片的情况可以自行修改。

def delet(image):

for i in range(3000):
for j in range(4096):
for k in range(3):
if int(image[i][j][1])-int(image[i][j][0]) >=50:
                    image[i][j] = 0
if int(image[i][j][0]) <= 20:
                        image[i][j] = 0

return image

2、二值化

二值化变为黑白图像,将目标区域变为白色,背景区域变为黑色。

ret, thresh1 = cv2.threshold(img, 20, 255, cv2.THRESH_BINARY) 
cv2.namedWindow('th1', 0)
cv2.resizeWindow('th1', 682, 500)
cv2.imshow('th1', thresh1)
cv2.waitKey(0)

3、双边滤波去噪+填充

blur = cv2.bilateralFilter(thresh1, 9, 80, 80)
fill = blur.copy()
h, w = blur.shape[: 2]
mask = np.zeros((h+2, w+2), np.uint8)
cv2.floodFill(fill, mask, (90, 90), 255);
fill_INV = cv2.bitwise_not(fill)
fill_out = blur | fill_INV

cv2.namedWindow('fill_out_img', 0)
cv2.resizeWindow('fill_out_img', 682, 500)
cv2.imshow('fill_out_img', fill_out)
#cv2.imwrite('K:/opencv/tianchong.png', fill_out)
cv2.waitKey(0)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值