首页 技术 正文
技术 2022年11月15日
0 收藏 535 点赞 4,751 浏览 1134 个字

1. 基本原理

在灰度图中,像素值的范围为[0, 255],即共有256级灰度。在计算机中,我们使用8比特数来表示每一个像素值。因此可以提取出不同比特层面的灰度图。比特层面分层可用于图片压缩:只储存较高比特层(为什么使用较高层,而不是较低层?通过二进制转换,我们知道较高层在数值中的贡献更大);如使用高四位比特层表示原有的八层比特平面。

2. 测试结果

比特平面分层(一些基本的灰度变换函数)基本原理及Python实现

图源自skimage

3. 代码

 def extract_bit_layer(input_image, layer_num):
'''
提取比特层
:param input_image: 原图像
:param layer_num: 提取层
:return: 提取到的比特层
'''
input_image_cp = np.copy(input_image) # 输入图片的副本 if layer_num == 1:
input_image_cp = np.where((input_image_cp >= 0) & (input_image_cp < 2), 255, 0)
elif layer_num == 2:
input_image_cp = np.where((input_image_cp >= 2) & (input_image_cp < 4), 255, 0)
elif layer_num == 3:
input_image_cp = np.where((input_image_cp >= 4) & (input_image_cp < 8), 255, 0)
elif layer_num == 4:
input_image_cp = np.where((input_image_cp >= 8) & (input_image_cp < 16), 255, 0)
elif layer_num == 5:
input_image_cp = np.where((input_image_cp >= 16) & (input_image_cp < 32), 255, 0)
elif layer_num == 6:
input_image_cp = np.where((input_image_cp >= 32) & (input_image_cp < 64), 255, 0)
elif layer_num == 7:
input_image_cp = np.where((input_image_cp >= 64) & (input_image_cp < 128), 255, 0)
elif layer_num == 8:
input_image_cp = np.where((input_image_cp >= 128) & (input_image_cp < 256), 255, 0)
else:
print("please enter the number of bit layers from 1 to 8") output_image = input_image_cp return output_image
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,983
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,500
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,344
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,127
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,761
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,838