失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > 第3章 Python 数字图像处理(DIP) - 灰度变换与空间滤波5 - 分段线性变换 - 灰度级分层

第3章 Python 数字图像处理(DIP) - 灰度变换与空间滤波5 - 分段线性变换 - 灰度级分层

时间:2019-08-03 18:03:11

相关推荐

第3章 Python 数字图像处理(DIP) - 灰度变换与空间滤波5 - 分段线性变换 - 灰度级分层

目录

灰度级分层

灰度级分层

二值图像

将感兴趣范围内的所有灰显示为一个值(白色),而将其它灰度值显示为另一个值(黑色)

其他灰度级不变

使期望的灰度范围变量(或变暗),但保持图像中的其它灰度级不变

x = np.arange(0, 256)y_1 = np.where(x, x >= 100, 0)y_1 = np.where(y_1, x < 200, 0) * 150a = 70b = 150y_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 imageimg_transform = img.copy()img_transform[img_transform < a] = 0img_transform[img_transform >= a] = 255# grayscale imageimg_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()

如果觉得《第3章 Python 数字图像处理(DIP) - 灰度变换与空间滤波5 - 分段线性变换 - 灰度级分层》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。