Python實(shí)現(xiàn)位圖分割的效果
最近重溫了一下位圖分割的相關(guān)內(nèi)容,發(fā)現(xiàn)網(wǎng)絡(luò)上位圖分割原理講得已經(jīng)很清楚了,但是代碼多為C++實(shí)現(xiàn)或者M(jìn)atlab實(shí)現(xiàn),因?yàn)樾枰狿ython的版本,于是出現(xiàn)了這篇博客。
話不多說,直接來代碼。
import cv2
import numpy as np
import matplotlib.pyplot as plt
img = cv2.imread('Fig3.13.jpg', 0)
imgBS = np.zeros_like(img)
plt.figure("Image")
plt.subplot(2, 4, 1)
plt.imshow(img, cmap='gray')
plt.axis('off')
plt.title('original')
for n in range(1, 8):
for x in range(img.shape[0]):
for y in range(img.shape[1]):
gray = img[x, y] & pow(2, n-1)
if gray == pow(2, n-1):
imgBS[x, y] = 255
else:
imgBS[x, y] = 0
plt.subplot(2, 4, n+1)
plt.imshow(imgBS, cmap='gray')
plt.axis('off')
plt.title(str(n) + 'bit')
plt.show()

結(jié)果:

以上就是Python實(shí)現(xiàn)位圖分割的效果的詳細(xì)內(nèi)容,更多關(guān)于Python的資料請關(guān)注本站其它相關(guān)文章!
版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非maisonbaluchon.cn所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。
關(guān)注官方微信