日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【youcans 的 OpenCV 例程200篇】117. 形态学操作之顶帽运算

發(fā)布時(shí)間:2025/3/15 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【youcans 的 OpenCV 例程200篇】117. 形态学操作之顶帽运算 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

歡迎關(guān)注 『youcans 的 OpenCV 例程 200 篇』 系列,持續(xù)更新中
歡迎關(guān)注 『youcans 的 OpenCV學(xué)習(xí)課』 系列,持續(xù)更新中


【youcans 的 OpenCV 例程 200 篇】117. 形態(tài)學(xué)操作之頂帽運(yùn)算


形態(tài)學(xué)的基本思想是利用結(jié)構(gòu)元素測量或提取輸入圖像中的形狀或特征,以便進(jìn)行圖像分析和目標(biāo)識(shí)別。形態(tài)學(xué)操作都是基于各種形狀的結(jié)構(gòu)元,結(jié)構(gòu)元對(duì)輸入圖像進(jìn)行操作得到輸出圖像。



2. 形態(tài)學(xué)基本操作

2.5 頂帽運(yùn)算和底帽運(yùn)算

頂帽變換和底帽變換用結(jié)構(gòu)元通過開操作或閉操作從一副圖像中刪除物體,得到僅保留已刪除分量的圖像。頂帽變換用于暗背景上的亮物體,而底帽變換則用于用于亮背景上的暗物體,常用于校正不均勻光照的影響。

結(jié)構(gòu)元 B 對(duì)集合 A 的頂帽運(yùn)算定義為原圖像減去圖像開運(yùn)算結(jié)果:
That(A)=A?(A°B)=A?(A?B)⊕BT_{hat}(A) = A - (A \circ B) = A - (A \ominus B) \oplus B That?(A)=A?(A°B)=A?(A?B)B

開運(yùn)算可以刪除暗背景下的亮區(qū)域,頂帽變換可以得到原圖中的亮區(qū)域,因此又稱白頂帽變換。

頂帽運(yùn)算可以提取圖像的噪聲信息,也用于校正不均勻光照的影響,用來分離比鄰近點(diǎn)亮的斑塊。

OpenCV 中的函數(shù) cv.morphologyEx 可以實(shí)現(xiàn)圖像的頂帽運(yùn)算和底帽運(yùn)算,參數(shù) op 則要分別設(shè)為 MORPH_TOPHAT、MORPH_BLACKHAT。

函數(shù)說明:

cv.morphologyEx(src, op, kernel[, dst[, anchor[, iterations[, borderType[, borderValue]]]]] )→ dst

參數(shù)說明:

  • src:輸入圖像,可以為單通道或多通道,圖像深度必須為 CV_8U, CV_16U, CV_16S, CV_32F 或 CV_64F 。
  • op:形態(tài)學(xué)運(yùn)算類型
    • cv.MORPH_OPEN:開運(yùn)算, 先腐蝕再膨脹
    • cv.MORPH_CLOSE:閉運(yùn)算, 先膨脹再腐蝕
    • cv.MORPH_GRADIENT:形態(tài)學(xué)梯度, 膨脹圖與腐蝕圖之差
    • cv.MORPH_TOPHAT:頂帽變換, 原圖像與開運(yùn)算之差
    • cv.MORPH_BLACKHAT:黑帽變換, 閉運(yùn)算圖與原圖像之差
  • kernel:結(jié)構(gòu)元(卷積核),null 時(shí)使用 3*3 矩形卷積核

例程 10.5:形態(tài)學(xué)之頂帽運(yùn)算

# 10.5 形態(tài)學(xué)之頂帽運(yùn)算# 讀取原始圖像imgGray = cv2.imread("../images/Fig0726a.tif", flags=0) # flags=0 讀取為灰度圖像ret, imgBin = cv2.threshold(imgGray, 205, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU) # 二值化處理kernel = np.ones((5, 5), np.uint8) # 卷積核imgOpen = cv2.morphologyEx(imgBin, cv2.MORPH_OPEN, kernel) # 開運(yùn)算imgThat = cv2.morphologyEx(imgBin, cv2.MORPH_TOPHAT, kernel) # 頂帽運(yùn)算plt.figure(figsize=(9, 5))plt.subplot(131), plt.axis('off'), plt.title("Origin")plt.imshow(imgBin, cmap='gray', vmin=0, vmax=255)plt.subplot(132), plt.title("MORPH_OPEN"), plt.axis('off')plt.imshow(imgOpen, cmap='gray', vmin=0, vmax=255)plt.subplot(133), plt.title("MORPH_TOPHAT"), plt.axis('off')plt.imshow(imgThat, cmap='gray', vmin=0, vmax=255)plt.tight_layout()plt.show()




(本節(jié)完)


版權(quán)聲明:

youcans@xupt 原創(chuàng)作品,轉(zhuǎn)載必須標(biāo)注原文鏈接:(https://blog.csdn.net/youcans/article/details/123305803)

Copyright 2022 youcans, XUPT
Crated:2022-3-5


歡迎關(guān)注 『youcans 的 OpenCV 例程 200 篇』 系列,持續(xù)更新中
歡迎關(guān)注 『youcans 的 OpenCV學(xué)習(xí)課』 系列,持續(xù)更新中

【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. 圖像的創(chuàng)建(np.zeros)
【youcans 的 OpenCV 例程200篇】08. 圖像的復(fù)制(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. 圖像的加法運(yùn)算(cv2.add)
【youcans 的 OpenCV 例程200篇】14. 圖像與標(biāo)量相加(cv2.add)
【youcans 的 OpenCV 例程200篇】15. 圖像的加權(quán)加法(cv2.addWeight)
【youcans 的 OpenCV 例程200篇】16. 不同尺寸的圖像加法
【youcans 的 OpenCV 例程200篇】17. 兩張圖像的漸變切換
【youcans 的 OpenCV 例程200篇】18. 圖像的掩模加法
【youcans 的 OpenCV 例程200篇】19. 圖像的圓形遮罩
【youcans 的 OpenCV 例程200篇】20. 圖像的按位運(yùn)算
【youcans 的 OpenCV 例程200篇】21. 圖像的疊加
【youcans 的 OpenCV 例程200篇】22. 圖像添加非中文文字
【youcans 的 OpenCV 例程200篇】23. 圖像添加中文文字
【youcans 的 OpenCV 例程200篇】24. 圖像的仿射變換
【youcans 的 OpenCV 例程200篇】25. 圖像的平移
【youcans 的 OpenCV 例程200篇】26. 圖像的旋轉(zhuǎn)(以原點(diǎn)為中心)
【youcans 的 OpenCV 例程200篇】27. 圖像的旋轉(zhuǎn)(以任意點(diǎn)為中心)
【youcans 的 OpenCV 例程200篇】28. 圖像的旋轉(zhuǎn)(直角旋轉(zhuǎn))
【youcans 的 OpenCV 例程200篇】29. 圖像的翻轉(zhuǎn)(cv2.flip)
【youcans 的 OpenCV 例程200篇】30. 圖像的縮放(cv2.resize)
【youcans 的 OpenCV 例程200篇】31. 圖像金字塔(cv2.pyrDown)
【youcans 的 OpenCV 例程200篇】32. 圖像的扭變(錯(cuò)切)
【youcans 的 OpenCV 例程200篇】33. 圖像的復(fù)合變換
【youcans 的 OpenCV 例程200篇】34. 圖像的投影變換
【youcans 的 OpenCV 例程200篇】35. 圖像的投影變換(邊界填充)
【youcans 的 OpenCV 例程200篇】36. 直角坐標(biāo)與極坐標(biāo)的轉(zhuǎn)換
【youcans 的 OpenCV 例程200篇】37. 圖像的灰度化處理和二值化處理
【youcans 的 OpenCV 例程200篇】38. 圖像的反色變換(圖像反轉(zhuǎn))
【youcans 的 OpenCV 例程200篇】39. 圖像灰度的線性變換
【youcans 的 OpenCV 例程200篇】40. 圖像分段線性灰度變換
【youcans 的 OpenCV 例程200篇】41. 圖像的灰度變換(灰度級(jí)分層)
【youcans 的 OpenCV 例程200篇】42. 圖像的灰度變換(比特平面分層)
【youcans 的 OpenCV 例程200篇】43. 圖像的灰度變換(對(duì)數(shù)變換)
【youcans 的 OpenCV 例程200篇】44. 圖像的灰度變換(伽馬變換)
【youcans 的 OpenCV 例程200篇】45. 圖像的灰度直方圖
【youcans 的 OpenCV 例程200篇】46. 直方圖均衡化
【youcans 的 OpenCV 例程200篇】47. 圖像增強(qiáng)—直方圖匹配
【youcans 的 OpenCV 例程200篇】48. 圖像增強(qiáng)—彩色直方圖匹配
【youcans 的 OpenCV 例程200篇】49. 圖像增強(qiáng)—局部直方圖處理
【youcans 的 OpenCV 例程200篇】50. 圖像增強(qiáng)—直方圖統(tǒng)計(jì)量圖像增強(qiáng)
【youcans 的 OpenCV 例程200篇】51. 圖像增強(qiáng)—直方圖反向追蹤
【youcans 的 OpenCV 例程200篇】52. 圖像的相關(guān)與卷積運(yùn)算
【youcans 的 OpenCV 例程200篇】53. Scipy 實(shí)現(xiàn)圖像二維卷積
【youcans 的 OpenCV 例程200篇】54. OpenCV 實(shí)現(xiàn)圖像二維卷積
【youcans 的 OpenCV 例程200篇】55. 可分離卷積核
【youcans 的 OpenCV 例程200篇】56. 低通盒式濾波器
【youcans 的 OpenCV 例程200篇】57. 低通高斯濾波器
【youcans 的 OpenCV 例程200篇】58. 非線性濾波—中值濾波
【youcans 的 OpenCV 例程200篇】59. 非線性濾波—雙邊濾波
【youcans 的 OpenCV 例程200篇】60. 非線性濾波—聯(lián)合雙邊濾波
【youcans 的 OpenCV 例程200篇】61. 導(dǎo)向?yàn)V波(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. 空間域圖像增強(qiáng)的綜合應(yīng)用
【youcans 的 OpenCV 例程200篇】68. 空間域圖像增強(qiáng)的綜合應(yīng)用
【youcans 的 OpenCV 例程200篇】69. 連續(xù)非周期信號(hào)的傅立葉系數(shù)
【youcans 的 OpenCV 例程200篇】70. 一維連續(xù)函數(shù)的傅里葉變換
【youcans 的 OpenCV 例程200篇】71. 連續(xù)函數(shù)的取樣
【youcans 的 OpenCV 例程200篇】72. 一維離散傅里葉變換
【youcans 的 OpenCV 例程200篇】73. 二維連續(xù)傅里葉變換
【youcans 的 OpenCV 例程200篇】74. 圖像的抗混疊
【youcans 的 OpenCV 例程200篇】75. Numpy 實(shí)現(xiàn)圖像傅里葉變換
【youcans 的 OpenCV 例程200篇】76. OpenCV 實(shí)現(xiàn)圖像傅里葉變換
【youcans 的 OpenCV 例程200篇】77. OpenCV 實(shí)現(xiàn)快速傅里葉變換
【youcans 的 OpenCV 例程200篇】78. 頻率域圖像濾波基礎(chǔ)
【youcans 的 OpenCV 例程200篇】79. 頻率域圖像濾波的基本步驟
【youcans 的 OpenCV 例程200篇】80. 頻率域圖像濾波詳細(xì)步驟
【youcans 的 OpenCV 例程200篇】81. 頻率域高斯低通濾波器
【youcans 的 OpenCV 例程200篇】82. 頻率域巴特沃斯低通濾波器
【youcans 的 OpenCV 例程200篇】83. 頻率域低通濾波:印刷文本字符修復(fù)
【youcans 的 OpenCV 例程200篇】84. 由低通濾波器得到高通濾波器
【youcans 的 OpenCV 例程200篇】85. 頻率域高通濾波器的應(yīng)用
【youcans 的 OpenCV 例程200篇】86. 頻率域?yàn)V波應(yīng)用:指紋圖像處理
【youcans 的 OpenCV 例程200篇】87. 頻率域鈍化掩蔽
【youcans 的 OpenCV 例程200篇】88. 頻率域拉普拉斯高通濾波
【youcans 的 OpenCV 例程200篇】89. 帶阻濾波器的傳遞函數(shù)
【youcans 的 OpenCV 例程200篇】90. 頻率域陷波濾波器
【youcans 的 OpenCV 例程200篇】91. 高斯噪聲、瑞利噪聲、愛爾蘭噪聲
【youcans 的 OpenCV 例程200篇】92. 指數(shù)噪聲、均勻噪聲、椒鹽噪聲
【youcans 的 OpenCV 例程200篇】93. 噪聲模型的直方圖
【youcans 的 OpenCV 例程200篇】94. 算術(shù)平均濾波器
【youcans 的 OpenCV 例程200篇】95. 幾何均值濾波器
【youcans 的 OpenCV 例程200篇】96. 諧波平均濾波器
【youcans 的 OpenCV 例程200篇】97. 反諧波平均濾波器
【youcans 的 OpenCV 例程200篇】98. 統(tǒng)計(jì)排序?yàn)V波器
【youcans 的 OpenCV 例程200篇】99. 修正阿爾法均值濾波器
【youcans 的 OpenCV 例程200篇】100. 自適應(yīng)局部降噪濾波器
【youcans 的 OpenCV 例程200篇】101. 自適應(yīng)中值濾波器
【youcans 的 OpenCV 例程200篇】102. 陷波帶阻濾波器的傳遞函數(shù)
【youcans 的 OpenCV 例程200篇】103. 陷波帶阻濾波器消除周期噪聲干擾
【youcans 的 OpenCV 例程200篇】104. 運(yùn)動(dòng)模糊退化模型
【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. 形態(tài)學(xué)操作之腐蝕
【youcans 的 OpenCV 例程200篇】114. 形態(tài)學(xué)操作之膨脹
【youcans 的 OpenCV 例程200篇】115. 形態(tài)學(xué)操作之開運(yùn)算
【youcans 的 OpenCV 例程200篇】116. 形態(tài)學(xué)操作之閉運(yùn)算
【youcans 的 OpenCV 例程200篇】117. 形態(tài)學(xué)操作之頂帽運(yùn)算

總結(jié)

以上是生活随笔為你收集整理的【youcans 的 OpenCV 例程200篇】117. 形态学操作之顶帽运算的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。