目录
- 灰度级分层
灰度级分层
-
二值图像
-
将感兴趣范围内的所有灰显示为一个值(白色),而将其它灰度值显示为另一个值(黑色)
-
其他灰度级不变
-
使期望的灰度范围变量(或变暗),但保持图像中的其它灰度级不变
x = np.arange(0, 256)
y_1 = np.where(x, x >= 100, 0)
y_1 = np.where(y_1, x < 200, 0) * 150a = 70
b = 150
y_2 = np.zeros_like(x)
for i in range(len(x)):if a <= x[i] <= b:y_2[i] = 220else:y_2[i] = x[i]plt.figure(figsize=(10, 5))
plt.subplot(121), plt.plot(x, y_1), plt.ylim([-1, 255]), plt.xlim([0, 255])
plt.subplot(122), plt.plot(x, y_2), plt.ylim([1, 255]), plt.xlim([0, 255])
plt.show()
# 灰度分层
img = cv2.imread('DIP_Figures/DIP3E_Original_Images_CH03/Fig0312(a)(kidney).tif')a = 155# binary image
img_transform = img.copy()
img_transform[img_transform < a] = 0
img_transform[img_transform >= a] = 255# grayscale image
img_transform_2 = img.copy()
img_transform_2[img_transform_2 < a] = 0.plt.figure(figsize=(18, 15))
plt.subplot(1, 3, 1), plt.imshow(img, cmap='gray'), plt.title('Original')
plt.subplot(1, 3, 2), plt.imshow(img_transform, cmap='gray'), plt.title(f'Binary Image')
plt.subplot(1, 3, 3), plt.imshow(img_transform_2, cmap='gray'), plt.title(f'Grayscale Image')
plt.tight_layout()
plt.show()