【youcans 的 OpenCV 例程200篇】147. 图像分割之孤立点检测
歡迎關注 『youcans 的 OpenCV 例程 200 篇』 系列,持續更新中
歡迎關注 『youcans 的 OpenCV學習課』 系列,持續更新中
【youcans 的 OpenCV 例程200篇】147. 圖像分割之孤立點檢測
1. 圖像分割基本概念
圖像分割就是把圖像分成若干個特定的、具有獨特性質的區域并提出感興趣目標的技術和過程。圖像分割是由圖像處理到圖像分析的關鍵步驟,是計算機視覺的基礎,也是圖像理解的重要組成部分。
所謂圖像分割是指根據灰度、彩色、空間紋理、幾何形狀等特征把圖像劃分成若干個互不相交的區域,使得這些特征在同一區域內表現出一致性或相似性,而在不同區域間表現出明顯的不同。簡單的說就是在一副圖像中,把目標從背景中分離出來。
從數學角度來看,圖像分割是將數字圖像劃分成互不相交的區域的過程。圖像分割的過程也是一個標記過程,即把屬于同一區域的像索賦予相同的編號。
圖像分割的基本方法是基于圖像灰度值的不連續性和相似性。基于不連續性的圖像分割,是根據灰度的突變檢測邊界,將圖像分割為多個區域;基于相似性的圖像分割,是根據預定義的準則將圖像分割為多個相似的區域。
常用的圖像分割方法有:基于閾值的分割方法、基于區域的分割方法、基于邊緣的分割方法以及基于特定理論的分割方法等。
2. 點、線和邊緣檢測
本節基于圖像灰度的不連續性,討論根據灰度的突變檢測邊界,以此為基礎進行圖像分割。
- 邊緣像素是圖像中灰度突變的像素,而邊緣是相連邊緣像素的集合。
- 線是一條細邊緣線段,其兩側的背景灰度與線段的像素灰度存在顯著差異。
- 孤立的點是一個被背景像素圍繞的前景像素,或一個被前景像素圍繞的背景像素。
導數可以用來檢測灰度的局部突變:
- 一階導數通常產生粗邊緣;
- 二階導數對精細細節(如細線、孤立點和噪聲)的響應更強;
- 二階導數在灰度斜坡和臺階過渡處會產生雙邊緣響應,即二階導數在進入和離開邊緣時的符號相反;
- 二階導數的符號可用于確定邊緣的過渡是從亮到暗還是從暗到亮。
計算圖像中每個像素位置的一階導數和二階導數的方法是空間卷積。對一個 3*3 模板,計算模板區域內灰度值與模板系數的卷積。
2.1 圖像的孤立點檢測
孤立點的檢測,是檢測嵌在一幅圖像的恒定區域或亮度幾乎不變的區域里的孤立點。孤立點的檢測以二階導數為基礎。
二階導數的計算可以采用拉普拉斯二階有限差分公式:
?2f=?2f?x2+?2f?y2?2f(x,y)=f(x+1,y)+f(x?1,y)+f(x,y+1)+f(x,y?1)?4f(x,y)\begin{aligned} \nabla ^2 f &= \dfrac{\partial ^2 f}{\partial x ^2} + \dfrac{\partial ^2 f}{\partial y ^2} \\ \nabla ^2 f(x,y) &= f(x+1,y) + f(x-1,y) + f(x,y+1) + f(x,y-1) - 4f(x,y) \end{aligned} ?2f?2f(x,y)?=?x2?2f?+?y2?2f?=f(x+1,y)+f(x?1,y)+f(x,y+1)+f(x,y?1)?4f(x,y)?
拉普拉斯差分公式可以用拉普拉斯核的卷積來實現:
K1=[0101?41010],K2=[1111?81111],K3=[0?10?14?10?10],K4=[?1?1?1?18?1?1?1?1]\begin{aligned} &K1 = \begin{bmatrix} 0 & 1 &0\\ 1 & -4 &1\\ 0 & 1 &0\\ \end{bmatrix}, \ &K2 = \begin{bmatrix} 1 & 1 & 1\\ 1 & -8 & 1\\ 1 & 1 & 1\\ \end{bmatrix}, \\ &K3 = \begin{bmatrix} 0 & -1 &0\\ -1 & 4 &-1\\ 0 & -1 &0\\ \end{bmatrix}, \ &K4 = \begin{bmatrix} -1 & -1 &-1\\ -1 & 8 &-1\\ -1 & -1 &-1\\ \end{bmatrix} \end{aligned} ?K1=???010?1?41?010????,?K3=???0?10??14?1?0?10????,??K2=???111?1?81?111????,K4=????1?1?1??18?1??1?1?1?????
當孤立點在卷積模板的中心時,拉普拉斯濾波器的響應很強烈,而孤立點在非模板中心時,拉普拉斯濾波器響應為零。當濾波器在一個點的響應超過設定閾值 T,則認為在卷積核的中心檢測到了孤立點,標記為 1,而其它點都被標記為 0,從而產生一副二值圖像。
g(x,y)={1,∣Z(x,y)∣>T0,elseg(x,y) = \begin{cases} 1, \quad |{Z(x,y)}| > T \\ 0, \quad else \end{cases} g(x,y)={1,∣Z(x,y)∣>T0,else?
注意:
(1)本節所稱的孤立點檢測,是絕對意義上的孤立點,即一個孤立的像素。人眼所能感知、識別的孤立點,通常來說其實是一個微小的區域,而不是孤立的一個像素,因此并不能用這種方法檢測。
(2)使用 Laplace 算子進行圖像孤立點檢測,推薦使用 scipy.signal 實現卷積運算,不建議使用 cv2.filter2D 實現。后者自動將卷積結果進行歸一化處理,不便于通過閾值 T 檢測孤立點。
例程 11.1:圖像的孤立點檢測
# 11.1 圖像孤立點檢測 (Laplace 算子)imgGray = cv2.imread("../images/Fig1004.tif", flags=0)hImg, wImg = imgGray.shape# scipy.signal 實現卷積運算 (注意:不能用 cv2.filter2D 處理)from scipy import signalkernelLaplace = np.array([[1, 1, 1], [1, -8, 1], [1, 1, 1]]) # Laplacian kernelimgLaplace = signal.convolve2d(imgGray, kernelLaplace, boundary='symm', mode='same') # same 卷積# 在原圖上用半徑為 5 的圓圈標記角點T = 0.9 * max(imgLaplace.max(), -imgLaplace.min())imgPoint = np.zeros((hImg, wImg), np.uint8) # 創建黑色圖像for h in range(hImg):for w in range(wImg):if (imgLaplace[h, w] > T) or (imgLaplace[h, w] < -T):imgPoint[h, w] = 255 # 二值處理cv2.circle(imgPoint, (w, h), 10, 255)print(imgLaplace.shape, imgLaplace.max(), imgLaplace.min(), T)plt.figure(figsize=(9, 6))plt.subplot(131), plt.axis('off'), plt.title("Original")plt.imshow(imgGray, cmap='gray', vmin=0, vmax=255)plt.subplot(132), plt.axis('off'), plt.title("Laplacian K2")plt.imshow(imgLaplace, cmap='gray', vmin=0, vmax=255)plt.subplot(133), plt.axis('off'), plt.title("Isolated point")plt.imshow(imgPoint, cmap='gray', vmin=0, vmax=255)plt.tight_layout()plt.show()(本節完)
版權聲明:
youcans@xupt 原創作品,轉載必須標注原文鏈接:(https://blog.csdn.net/youcans/article/details/124005009)
Copyright 2022 youcans, XUPT
Crated:2022-4-1
歡迎關注 『youcans 的 OpenCV 例程 200 篇』 系列,持續更新中
歡迎關注 『youcans 的 OpenCV學習課』 系列,持續更新中
【youcans 的 OpenCV 例程200篇】01. 圖像的讀取(cv2.imread)
【youcans 的 OpenCV 例程200篇】02. 圖像的保存(cv2.imwrite)
【youcans 的 OpenCV 例程200篇】03. 圖像的顯示(cv2.imshow)
【youcans 的 OpenCV 例程200篇】04. 用 matplotlib 顯示圖像(plt.imshow)
【youcans 的 OpenCV 例程200篇】05. 圖像的屬性(np.shape)
【youcans 的 OpenCV 例程200篇】06. 像素的編輯(img.itemset)
【youcans 的 OpenCV 例程200篇】07. 圖像的創建(np.zeros)
【youcans 的 OpenCV 例程200篇】08. 圖像的復制(np.copy)
【youcans 的 OpenCV 例程200篇】09. 圖像的裁剪(cv2.selectROI)
【youcans 的 OpenCV 例程200篇】10. 圖像的拼接(np.hstack)
【youcans 的 OpenCV 例程200篇】11. 圖像通道的拆分(cv2.split)
【youcans 的 OpenCV 例程200篇】12. 圖像通道的合并(cv2.merge)
【youcans 的 OpenCV 例程200篇】13. 圖像的加法運算(cv2.add)
【youcans 的 OpenCV 例程200篇】14. 圖像與標量相加(cv2.add)
【youcans 的 OpenCV 例程200篇】15. 圖像的加權加法(cv2.addWeight)
【youcans 的 OpenCV 例程200篇】16. 不同尺寸的圖像加法
【youcans 的 OpenCV 例程200篇】17. 兩張圖像的漸變切換
【youcans 的 OpenCV 例程200篇】18. 圖像的掩模加法
【youcans 的 OpenCV 例程200篇】19. 圖像的圓形遮罩
【youcans 的 OpenCV 例程200篇】20. 圖像的按位運算
【youcans 的 OpenCV 例程200篇】21. 圖像的疊加
【youcans 的 OpenCV 例程200篇】22. 圖像添加非中文文字
【youcans 的 OpenCV 例程200篇】23. 圖像添加中文文字
【youcans 的 OpenCV 例程200篇】24. 圖像的仿射變換
【youcans 的 OpenCV 例程200篇】25. 圖像的平移
【youcans 的 OpenCV 例程200篇】26. 圖像的旋轉(以原點為中心)
【youcans 的 OpenCV 例程200篇】27. 圖像的旋轉(以任意點為中心)
【youcans 的 OpenCV 例程200篇】28. 圖像的旋轉(直角旋轉)
【youcans 的 OpenCV 例程200篇】29. 圖像的翻轉(cv2.flip)
【youcans 的 OpenCV 例程200篇】30. 圖像的縮放(cv2.resize)
【youcans 的 OpenCV 例程200篇】31. 圖像金字塔(cv2.pyrDown)
【youcans 的 OpenCV 例程200篇】32. 圖像的扭變(錯切)
【youcans 的 OpenCV 例程200篇】33. 圖像的復合變換
【youcans 的 OpenCV 例程200篇】34. 圖像的投影變換
【youcans 的 OpenCV 例程200篇】35. 圖像的投影變換(邊界填充)
【youcans 的 OpenCV 例程200篇】36. 直角坐標與極坐標的轉換
【youcans 的 OpenCV 例程200篇】37. 圖像的灰度化處理和二值化處理
【youcans 的 OpenCV 例程200篇】38. 圖像的反色變換(圖像反轉)
【youcans 的 OpenCV 例程200篇】39. 圖像灰度的線性變換
【youcans 的 OpenCV 例程200篇】40. 圖像分段線性灰度變換
【youcans 的 OpenCV 例程200篇】41. 圖像的灰度變換(灰度級分層)
【youcans 的 OpenCV 例程200篇】42. 圖像的灰度變換(比特平面分層)
【youcans 的 OpenCV 例程200篇】43. 圖像的灰度變換(對數變換)
【youcans 的 OpenCV 例程200篇】44. 圖像的灰度變換(伽馬變換)
【youcans 的 OpenCV 例程200篇】45. 圖像的灰度直方圖
【youcans 的 OpenCV 例程200篇】46. 直方圖均衡化
【youcans 的 OpenCV 例程200篇】47. 圖像增強—直方圖匹配
【youcans 的 OpenCV 例程200篇】48. 圖像增強—彩色直方圖匹配
【youcans 的 OpenCV 例程200篇】49. 圖像增強—局部直方圖處理
【youcans 的 OpenCV 例程200篇】50. 圖像增強—直方圖統計量圖像增強
【youcans 的 OpenCV 例程200篇】51. 圖像增強—直方圖反向追蹤
【youcans 的 OpenCV 例程200篇】52. 圖像的相關與卷積運算
【youcans 的 OpenCV 例程200篇】53. Scipy 實現圖像二維卷積
【youcans 的 OpenCV 例程200篇】54. OpenCV 實現圖像二維卷積
【youcans 的 OpenCV 例程200篇】55. 可分離卷積核
【youcans 的 OpenCV 例程200篇】56. 低通盒式濾波器
【youcans 的 OpenCV 例程200篇】57. 低通高斯濾波器
【youcans 的 OpenCV 例程200篇】58. 非線性濾波—中值濾波
【youcans 的 OpenCV 例程200篇】59. 非線性濾波—雙邊濾波
【youcans 的 OpenCV 例程200篇】60. 非線性濾波—聯合雙邊濾波
【youcans 的 OpenCV 例程200篇】61. 導向濾波(Guided filter)
【youcans 的 OpenCV 例程200篇】62. 圖像銳化——鈍化掩蔽
【youcans 的 OpenCV 例程200篇】63. 圖像銳化——Laplacian 算子
【youcans 的 OpenCV 例程200篇】64. 圖像銳化——Sobel 算子
【youcans 的 OpenCV 例程200篇】65. 圖像銳化——Scharr 算子
【youcans 的 OpenCV 例程200篇】66. 圖像濾波之低通/高通/帶阻/帶通
【youcans 的 OpenCV 例程200篇】67. 空間域圖像增強的綜合應用
【youcans 的 OpenCV 例程200篇】68. 空間域圖像增強的綜合應用
【youcans 的 OpenCV 例程200篇】69. 連續非周期信號的傅立葉系數
【youcans 的 OpenCV 例程200篇】70. 一維連續函數的傅里葉變換
【youcans 的 OpenCV 例程200篇】71. 連續函數的取樣
【youcans 的 OpenCV 例程200篇】72. 一維離散傅里葉變換
【youcans 的 OpenCV 例程200篇】73. 二維連續傅里葉變換
【youcans 的 OpenCV 例程200篇】74. 圖像的抗混疊
【youcans 的 OpenCV 例程200篇】75. Numpy 實現圖像傅里葉變換
【youcans 的 OpenCV 例程200篇】76. OpenCV 實現圖像傅里葉變換
【youcans 的 OpenCV 例程200篇】77. OpenCV 實現快速傅里葉變換
【youcans 的 OpenCV 例程200篇】78. 頻率域圖像濾波基礎
【youcans 的 OpenCV 例程200篇】79. 頻率域圖像濾波的基本步驟
【youcans 的 OpenCV 例程200篇】80. 頻率域圖像濾波詳細步驟
【youcans 的 OpenCV 例程200篇】81. 頻率域高斯低通濾波器
【youcans 的 OpenCV 例程200篇】82. 頻率域巴特沃斯低通濾波器
【youcans 的 OpenCV 例程200篇】83. 頻率域低通濾波:印刷文本字符修復
【youcans 的 OpenCV 例程200篇】84. 由低通濾波器得到高通濾波器
【youcans 的 OpenCV 例程200篇】85. 頻率域高通濾波器的應用
【youcans 的 OpenCV 例程200篇】86. 頻率域濾波應用:指紋圖像處理
【youcans 的 OpenCV 例程200篇】87. 頻率域鈍化掩蔽
【youcans 的 OpenCV 例程200篇】88. 頻率域拉普拉斯高通濾波
【youcans 的 OpenCV 例程200篇】89. 帶阻濾波器的傳遞函數
【youcans 的 OpenCV 例程200篇】90. 頻率域陷波濾波器
【youcans 的 OpenCV 例程200篇】91. 高斯噪聲、瑞利噪聲、愛爾蘭噪聲
【youcans 的 OpenCV 例程200篇】92. 指數噪聲、均勻噪聲、椒鹽噪聲
【youcans 的 OpenCV 例程200篇】93. 噪聲模型的直方圖
【youcans 的 OpenCV 例程200篇】94. 算術平均濾波器
【youcans 的 OpenCV 例程200篇】95. 幾何均值濾波器
【youcans 的 OpenCV 例程200篇】96. 諧波平均濾波器
【youcans 的 OpenCV 例程200篇】97. 反諧波平均濾波器
【youcans 的 OpenCV 例程200篇】98. 統計排序濾波器
【youcans 的 OpenCV 例程200篇】99. 修正阿爾法均值濾波器
【youcans 的 OpenCV 例程200篇】100. 自適應局部降噪濾波器
【youcans 的 OpenCV 例程200篇】101. 自適應中值濾波器
【youcans 的 OpenCV 例程200篇】102. 陷波帶阻濾波器的傳遞函數
【youcans 的 OpenCV 例程200篇】103. 陷波帶阻濾波器消除周期噪聲干擾
【youcans 的 OpenCV 例程200篇】104. 運動模糊退化模型
【youcans 的 OpenCV 例程200篇】105. 湍流模糊退化模型
【youcans 的 OpenCV 例程200篇】106. 退化圖像的逆濾波
【youcans 的 OpenCV 例程200篇】107. 退化圖像的維納濾波
【youcans 的 OpenCV 例程200篇】108. 約束最小二乘方濾波
【youcans 的 OpenCV 例程200篇】109. 幾何均值濾波
【youcans 的 OpenCV 例程200篇】110. 投影和雷登變換
【youcans 的 OpenCV 例程200篇】111. 雷登變換反投影重建圖像
【youcans 的 OpenCV 例程200篇】112. 濾波反投影重建圖像
【youcans 的 OpenCV 例程200篇】113. 形態學操作之腐蝕
【youcans 的 OpenCV 例程200篇】114. 形態學操作之膨脹
【youcans 的 OpenCV 例程200篇】115. 形態學操作之開運算
【youcans 的 OpenCV 例程200篇】116. 形態學操作之閉運算
【youcans 的 OpenCV 例程200篇】117. 形態學操作之頂帽運算
【youcans 的 OpenCV 例程200篇】118. 形態學操作之底帽運算
【youcans 的 OpenCV 例程200篇】119. 圖像的形態學梯度
【youcans 的 OpenCV 例程200篇】120. 擊中-擊不中變換
【youcans 的 OpenCV 例程200篇】121. 擊中-擊不中用于特征識別
【youcans 的 OpenCV 例程200篇】122. 形態算法之邊界提取
【youcans 的 OpenCV 例程200篇】123. 形態算法之孔洞填充
【youcans 的 OpenCV 例程200篇】124. 孔洞填充的泛洪算法
【youcans 的 OpenCV 例程200篇】125. 形態算法之提取連通分量
【youcans 的 OpenCV 例程200篇】126. 形態算法之凸殼
【youcans 的 OpenCV 例程200篇】127. 形態算法之細化
【youcans 的 OpenCV 例程200篇】128. 形態算法之骨架 (skimage)
【youcans 的 OpenCV 例程200篇】129. 形態算法之骨架 (重建開運算)
【youcans 的 OpenCV 例程200篇】130. 形態學之提取水平和垂直線
【youcans 的 OpenCV 例程200篇】131. 形態學重建之豎線字符提取
【youcans 的 OpenCV 例程200篇】132. 形態學重建之孔洞填充算法
【youcans 的 OpenCV 例程200篇】133. 形態學重建之邊界清除
【youcans 的 OpenCV 例程200篇】134. 形態學重建之細胞計數
【youcans 的 OpenCV 例程200篇】135. 形態學重建之粒度測定
【youcans 的 OpenCV 例程200篇】136. 灰度腐蝕和灰度膨脹
【youcans 的 OpenCV 例程200篇】137. 灰度開運算和灰度閉運算原理
【youcans 的 OpenCV 例程200篇】138. 灰度開運算和灰度閉運算
【youcans 的 OpenCV 例程200篇】139. 灰度頂帽變換校正陰影
【youcans 的 OpenCV 例程200篇】140. 灰度底帽變換校正光照
【youcans 的 OpenCV 例程200篇】141. 灰度底帽變換的三維地形圖
【youcans 的 OpenCV 例程200篇】142. 基于灰度形態學的圖像平滑
【youcans 的 OpenCV 例程200篇】143. 基于灰度形態學的粒度測定
【youcans 的 OpenCV 例程200篇】144. 基于灰度形態學的紋理分割
【youcans 的 OpenCV 例程200篇】145. 形態學之邊緣和角點檢測
【youcans 的 OpenCV 例程200篇】146. 基于灰度形態學的復雜背景圖像重建
【youcans 的 OpenCV 例程200篇】147. 圖像分割之孤立點檢測
總結
以上是生活随笔為你收集整理的【youcans 的 OpenCV 例程200篇】147. 图像分割之孤立点检测的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: jupyter(Anaconda)设置默
- 下一篇: 从您的计算机移除此产品,解决office