91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 5KB
    文件類型: .py
    金幣: 1
    下載: 0 次
    發(fā)布日期: 2021-05-29
  • 語言: Python
  • 標(biāo)簽: 圖像分割??

資源簡介

主要是對(duì)一張圖像上的多目標(biāo)區(qū)域進(jìn)行切割的一系列算法,其中涉及彩色圖像的閾值分割、圖像二值化、雙邊濾波去噪、圖像孔洞填充、面積閾值去噪、邊緣顆粒去除、對(duì)比原圖的遍歷替換、目標(biāo)區(qū)域的位置檢測(cè)以及輪廓檢測(cè)、最小外接矩形畫框以及按照框的大小對(duì)框選目標(biāo)進(jìn)行切割。

資源截圖

代碼片段和文件信息

#?-*-?coding:?utf-8?-*-
“““
Created?on?Fri?Oct?18?16:06:32?2019

@author:?大浪淘沙
“““

def?delect(image):
????
????for?i?in?range(3000):
????????for?j?in?range(4096):
????????????for?k?in?range(3):
????????????????#img[i][j][k]?=?255
????????????
????????????????if?int(image[i][j][1])-int(image[i][j][0])?>=22:
????????????????????image[i][j]?=?0
????????????????????if?int(image[i][j][0])?<=?20:
????????????????????????image[i][j]?=?0
????????????????????????
????return?image
img1?=?delet(img)
cv2.namedWindow(‘Image‘?0)
cv2.resizeWindow(‘Image‘?682?500)
#在窗口中顯示圖像
cv2.imshow(‘Image‘?img1)
#最后還要一句代碼,使窗口可以一直保持住
cv2.waitKey(0)



#整體圖像分割算法

import?cv2?
import?numpy?as?np
from?PIL?import?Image

img?=?cv2.imread(‘K:/opencv/delet739.png‘?0)
img1?=?cv2.imread(‘K:/test_png/1.4/739.png‘)


#縮放
rows?cols?channels?=?img1.shape



#二值化
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)


#雙邊濾波+填充
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)


#腐蝕膨脹
dilate=cv2.dilate(fill_out?None?iterations=1)
cv2.namedWindow(‘pengzhang‘?0)
cv2.resizeWindow(‘pengzhang‘?682?500)
cv2.imshow(‘pengzhang‘?dilate)
cv2.waitKey(0)

erode=cv2.erode(dilateNoneiterations=1)

cv2.namedWindow(‘fushi‘?0)
cv2.resizeWindow(‘fushi‘?682?500)
cv2.imshow(‘fushi‘?erode)
cv2.waitKey(0)

def?baweraopen(imagesize):
????‘‘‘
????@image:單通道二值圖,數(shù)據(jù)類型uint8
????@size:欲去除區(qū)域大小(黑底上的白區(qū)域)
????‘‘‘
????output=image.copy()
????nlabels?labels?stats?centroids?=?cv2.connectedComponentsWithStats(image)
????for?i?in?range(1nlabels-1):
????????regions_size=stats[i4]
????????if?regions_size????????????x0=stats[i0]
????????????y0=stats[i1]
????????????x1=s

評(píng)論

共有 條評(píng)論