改正此代码import cv2 import numpy as np import matplotlib.pyplot as plt image1 = cv2.imread(r'E:\\postgraduate\\three\\DIP3E_Original_Images_CH03\\3.12.tif') img = cv2.imread(r'E:\\postgraduate\\three\\DIP3E_Original_Images_CH03\\3.12.tif',0) def bit_plane_slicing(src,high): height, width,high = src.shape dst = np.zeros((height, width), np.uint8) for i in range(0, height): for j in range(0, width): dst= plt.dec2bin(src[i,j],8) for high = 1 : 8: if str(high) == '0': dst(x, y, 9 - high) = 0; else: dst(x, y, 9 - high) = 1; return dst image2 = bit_plane_slicing(img,1) image3 = bit_plane_slicing(img, 2) plt.figure(figsize=(100,100)) plt.subplot(131) plt.imshow(image1,cmap='gray') plt.axis('off') plt.subplot(132) plt.imshow(image2,cmap='gray') plt.axis('off') plt.subplot(133) plt.imshow(image3,cmap='gray') plt.axis('off') plt.show()
时间: 2024-03-15 18:42:56 浏览: 24
import cv2
import numpy as np
import matplotlib.pyplot as plt
image1 = cv2.imread(r'E:\\postgraduate\\three\\DIP3E_Original_Images_CH03\\3.12.tif')
img = cv2.imread(r'E:\\postgraduate\\three\\DIP3E_Original_Images_CH03\\3.12.tif',0)
def bit_plane_slicing(src,high):
height, width = src.shape
dst = np.zeros((height, width, 8), np.uint8)
for i in range(0, height):
for j in range(0, width):
binary = format(src[i,j], '08b')
for bit in range(0, 8):
dst[i, j, bit] = binary[bit]
return dst[:, :, high]
image2 = bit_plane_slicing(img, 1)
image3 = bit_plane_slicing(img, 2)
plt.figure(figsize=(10,10))
plt.subplot(131)
plt.imshow(image1,cmap='gray')
plt.axis('off')
plt.subplot(132)
plt.imshow(image2,cmap='gray')
plt.axis('off')
plt.subplot(133)
plt.imshow(image3,cmap='gray')
plt.axis('off')
plt.show()
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)