2022最新計算機視覺學(xué)習(xí)路線(入門篇)
圖像變換
圖像變換包括平移、旋轉(zhuǎn)、縮放、裁剪和翻轉(zhuǎn)圖像。
img=cv.imread('../input/images-for-computer-vision/tiger1.jpg')
width, height, _=img.shape
# Translating
M_translate=np.float32([[1,0,200],[0,1,100]]) # 200=> Translation along x-axis and 100=>translation along y-axis
img_translate=cv.warpAffine(img,M_translate,(height,width))
# Rotating
center=(width/2,height/2)
M_rotate=cv.getRotationMatrix2D(center, angle=90, scale=1)
img_rotate=cv.warpAffine(img,M_rotate,(width,height))
# Scaling
scale_percent = 50
width = int(img.shape[1] * scale_percent / 100)
height = int(img.shape[0] * scale_percent / 100)
dim = (width, height)
img_scale = cv.resize(img, dim, interpolation = cv.INTER_AREA)
# Flipping
img_flip=cv.flip(img,1) # 0:Along horizontal axis, 1:Along verticle axis, -1: first along verticle then horizontal
# Shearing
srcTri = np.a(chǎn)rray( [[0, 0], [img.shape[1] - 1, 0], [0,img.shape[0] - 1]] ).a(chǎn)stype(np.float32)
dstTri = np.a(chǎn)rray( [[0, img.shape[1]*0.33], [img.shape[1]*0.85, img.shape[0]*0.25], [img.shape[1]*0.15, img.shape[0]*0.7]] ).a(chǎn)stype(np.float32)
warp_mat = cv.getAffineTransform(srcTri, dstTri)
img_warp = cv.warpAffine(img, warp_mat, (height, width))
myplot([img, img_translate, img_rotate, img_scale, img_flip, img_warp],
['Original Image', 'Translated Image', 'Rotated Image', 'Scaled Image', 'Flipped Image', 'Sheared Image'])
圖像預(yù)處理
閾值處理:在閾值處理中,小于閾值的像素值變?yōu)?0(黑色),大于閾值的像素值變?yōu)?255(白色)。
我將閾值設(shè)為 150,但你也可以選擇任何其他數(shù)字。
# For visualising the filters
import plotly.graph_objects as go
from plotly.subplots import make_subplots
def plot_3d(img1, img2, titles):
fig = make_subplots(rows=1, cols=2,
specs=[[{'is_3d': True}, {'is_3d': True}]],
subplot_titles=[titles[0], titles[1]],
)
x, y=np.mgrid[0:img1.shape[0], 0:img1.shape[1]]
fig.a(chǎn)dd_trace(go.Surface(x=x, y=y(tǒng), z=img1[:,:,0]), row=1, col=1)
fig.a(chǎn)dd_trace(go.Surface(x=x, y=y(tǒng), z=img2[:,:,0]), row=1, col=2)
fig.update_traces(contours_z=dict(show=True, usecolormap=True,
highlightcolor="limegreen", project_z=True))
fig.show()
img=cv.imread('../input/images-for-computer-vision/simple_shapes.png')
# Pixel value less than threshold becomes 0 and more than threshold becomes 255
_,img_threshold=cv.threshold(img,150,255,cv.THRESH_BINARY)
plot_3d(img, img_threshold, ['Original Image', 'Threshold Image=150'])
應(yīng)用閾值后,150 的值變?yōu)榈扔?255
過濾: 圖像過濾是通過改變像素的值來改變圖像的外觀。每種類型的過濾器都會根據(jù)相應(yīng)的數(shù)學(xué)公式更改像素值。我不會在這里詳細介紹數(shù)學(xué),但我將通過在 3D 中可視化它們來展示每個過濾器的工作原理。
limg=cv.imread('../input/images-for-computer-vision/simple_shapes.png')
# Gaussian Filter
ksize=(11,11) # Both should be odd numbers
img_guassian=cv.GaussianBlur(img, ksize,0)
plot_3d(img, img_guassian, ['Original Image','Guassian Image'])
# Median Filter
ksize=11
img_medianblur=cv.medianBlur(img,ksize)
plot_3d(img, img_medianblur, ['Original Image','Median blur'])
# Bilateral Filter
img_bilateralblur=cv.bilateralFilter(img,d=5, sigmaColor=50, sigmaSpace=5)
myplot([img, img_bilateralblur],['Original Image', 'Bilateral blur Image'])
plot_3d(img, img_bilateralblur, ['Original Image','Bilateral blur'])
高斯濾波器:通過去除細節(jié)和噪聲來模糊圖像。
中值濾波器:非線性過程可用于減少脈沖噪聲或椒鹽噪聲
雙邊濾波器:邊緣保留和降噪平滑。
簡單來說,過濾器有助于減少或去除亮度或顏色隨機變化的噪聲,這稱為平滑
特征檢測
特征檢測是一種通過計算圖像信息的抽象,在每個圖像點上做出局部決策的方法。例如,對于一張臉的圖像,特征是眼睛、鼻子、嘴唇、耳朵等,我們嘗試識別這些特征。
讓我們首先嘗試識別圖像的邊緣。
邊緣檢測
img=cv.imread('../input/images-for-computer-vision/simple_shapes.png')
img_canny1=cv.Canny(img,50, 200)
# Smoothing the img before feeding it to canny
filter_img=cv.GaussianBlur(img, (7,7), 0)
img_canny2=cv.Canny(filter_img,50, 200)
myplot([img, img_canny1, img_canny2],
['Original Image', 'Canny Edge Detector(Without Smoothing)', 'Canny Edge Detector(With Smoothing)'])
這里我們使用 Canny 邊緣檢測器,它是一種邊緣檢測算子,它使用多階段算法來檢測圖像中的各種邊緣。它由 John F. Canny 于 1986 年開發(fā)。我不會詳細介紹 Canny 的工作原理,但這里的關(guān)鍵點是它用于提取邊緣。
在使用 Canny 邊緣檢測方法檢測邊緣之前,我們平滑圖像以去除噪聲。正如你從圖像中看到的,平滑后我們得到清晰的邊緣。
輪廓
img=cv.imread('../input/images-for-computer-vision/simple_shapes.png')
img_copy=img.copy()
img_gray=cv.cvtColor(img,cv.COLOR_BGR2GRAY)
_,img_binary=cv.threshold(img_gray,50,200,cv.THRESH_BINARY)
#Edroing and Dilating for smooth contours
img_binary_erode=cv.erode(img_binary,(10,10), iterations=5)
img_binary_dilate=cv.dilate(img_binary,(10,10), iterations=5)
contours,hierarchy=cv.findContours(img_binary,cv.RETR_TREE, cv.CHAIN_APPROX_SIMPLE)
cv.drawContours(img, contours,-1,(0,0,255),3) # Draws the contours on the original image just like draw function
myplot([img_copy, img], ['Original Image', 'Contours in the Image'])
侵蝕,使用用于探測和降低包含在圖像中的形狀的結(jié)構(gòu)元素的侵蝕操作。
膨脹:將像素添加到圖像中對象的邊界,與侵蝕相反
Hull
simg=cv.imread('../input/images-for-computer-vision/simple_shapes.png',0)
_,threshold=cv.threshold(img,50,255,cv.THRESH_BINARY)
contours,hierarchy=cv.findContours(threshold,cv.RETR_TREE, cv.CHAIN_APPROX_SIMPLE)
hulls=[cv.convexHull(c) for c in contours]
img_hull=cv.drawContours(img, hulls,-1,(0,0,255),2) #Draws the contours on the original image just like draw function
plt.imshow(img)
總結(jié)
我們看到了如何讀取和顯示圖像、在圖像上繪制形狀、文本、混合兩個圖像、旋轉(zhuǎn)、縮放、平移等變換圖像,使用高斯模糊、中值模糊、雙邊模糊過濾圖像,以及檢測使用 Canny 邊緣檢測和在圖像中查找輪廓的特征。
原文標題 : 2022最新計算機視覺學(xué)習(xí)路線(入門篇)

請輸入評論內(nèi)容...
請輸入評論/評論長度6~500個字
最新活動更多
推薦專題
-
9 每日AI全球觀察
- 1 特斯拉工人被故障機器人打成重傷,索賠3.6億
- 2 【行業(yè)深度研究】退居幕后四年后,張一鳴終于把算法公司變成AI公司?
- 3 AI 時代,阿里云想當(dāng)“安卓” ,那誰是“蘋果”?
- 4 拐點已至!匯川領(lǐng)跑工控、埃斯頓份額第一、新時達海爾賦能扭虧為盈
- 5 硬剛英偉達!華為發(fā)布全球最強算力超節(jié)點和集群
- 6 隱退4年后,張一鳴久違現(xiàn)身!互聯(lián)網(wǎng)大佬正集體殺回
- 7 00后華裔女生靠兩部AI電影狂賺7.8億人民幣,AI正式進軍好萊塢
- 8 谷歌“香蕉”爆火啟示:國產(chǎn)垂類AI的危機還是轉(zhuǎn)機?
- 9 機器人9月大事件|3家國產(chǎn)機器人沖刺IPO,行業(yè)交付與融資再創(chuàng)新高!
- 10 美光:AI Capex瘋投不止,終于要拉起存儲超級周期了?
- 生產(chǎn)部總監(jiān) 廣東省/廣州市
- 資深管理人員 廣東省/江門市
- Regional Sales Manager 廣東省/深圳市
- 銷售總監(jiān) 廣東省/深圳市
- 結(jié)構(gòu)工程師 廣東省/深圳市
- 光器件研發(fā)工程師 福建省/福州市
- 自動化高級工程師 廣東省/深圳市
- 技術(shù)專家 廣東省/江門市
- 激光器高級銷售經(jīng)理 上海市/虹口區(qū)
- 封裝工程師 北京市/海淀區(qū)