欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python實(shí)現(xiàn)位圖分割的效果

 更新時(shí)間:2021年11月19日 14:40:55   作者:小斌斌_Plus  
目前網(wǎng)絡(luò)上大多為用C++或者M(jìn)atlab編寫實(shí)現(xiàn)位圖分割,所以本文將使用Python實(shí)現(xiàn)位圖分割這一效果,代碼簡(jiǎn)單易懂,感興趣的小伙伴可以關(guā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)了這篇博客。

話不多說(shuō),直接來(lái)代碼。

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的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評(píng)論