0

## OPENCV影像疊加越來越淡

KAN~ 2020-03-23 00:27:551948 瀏覽

``````i=7
while(i-1>=0):
r[:,:,7] = cv2.bitwise_and(r[:,:,7],r[:,:,i-1])
cv2.imshow(str(i), r[:,:,7])
showImage(str(i), r[:,:,7])
i=i-1

cv2.waitKey()
cv2.destroyAllWindows()
``````
``````import cv2
import numpy as np

def showImage(title, img):
ishow = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) # for plt.imshow()
plt.imshow(ishow)
plt.axis('off')
plt.title(title)
plt.show()

#讀取灰階影像
cv2.imshow("lena", lena)
showImage("lena", lena)

#取出影像 rows and cols
r, c = lena.shape

#產生 8 個 bit-plane 對應的 mask
x = np.zeros((r,c,8), dtype = np.uint8)
for i in range(8):
x[:,:,i] = 2**i

#建立 8 個空白的 bit-planes
r = np.zeros((r,c,8), dtype = np.uint8)

#建立相對應的 bit-planes
for i in range(8):
r[:,:,i] = cv2.bitwise_and(lena, x[:,:,i])
cv2.imshow(str(i), r[:,:,i])
showImage(str(i), r[:,:,i])

i=7
while(i-1>=0):
cv2.imshow(str(i), r[:,:,7])
showImage(str(i), r[:,:,7])
i=i-1

cv2.waitKey()
cv2.destroyAllWindows()

``````

Kevin iT邦新手 4 級 ‧ 2020-03-23 09:04:09 檢舉
KAN~ iT邦新手 5 級 ‧ 2020-03-23 13:03:53 檢舉

KAN~ iT邦新手 5 級 ‧ 2020-03-23 13:06:39 檢舉

fillano iT邦超人 1 級 ‧ 2020-03-23 15:07:18 檢舉
KAN~ iT邦新手 5 級 ‧ 2020-03-23 16:10:03 檢舉

fillano iT邦超人 1 級 ‧ 2020-03-23 16:30:43 檢舉

KAN~ iT邦新手 5 級 ‧ 2020-03-23 16:36:47 檢舉

KAN~ iT邦新手 5 級 ‧ 2020-03-23 16:37:52 檢舉

fillano iT邦超人 1 級 ‧ 2020-03-24 08:51:11 檢舉

fillano iT邦超人 1 級 ‧ 2020-03-24 09:42:21 檢舉

### 1 個回答

1
fillano
iT邦超人 1 級 ‧ 2020-03-24 10:00:07

``````import numpy as np
import cv2

cv2.imshow('lena', lena)

cv2.waitKey()

r, c = lena.shape

x = np.zeros((r, c, 8), dtype=np.uint8)
for i in range(8):
x[:, :, i] = 2 ** i

r1 = np.zeros((r, c, 8), dtype=np.uint8)

for i in range(8):
r1[:, :, i] = cv2.bitwise_and(lena, x[:, :, i])
cv2.imshow(str(i), r1[:, :, i])

cv2.waitKey()

d = np.zeros((r, c), dtype=np.uint8)

for i in range(8):
d = cv2.add(d, r1[:, :, 7-i])
cv2.imshow(str(i), d)

cv2.waitKey()

cv2.destroyAllWindows()
``````

``````    mask = r[:, :, i] > 0