python - 如何使用 python 将 8 位转换为 4 位?
问题描述
对于 GLCM 方法,我需要将图像转换为 4 位。Opencv 和类似的库至少有 8 位。我应该怎么办?你有转换公式吗?
使用 16 位到 8 位的 opencv:
import numpy as np
import cv2
imagePath = "--"
img_8bit = cv2.imread(imagePath).astype(np.uint8)
在 Opencv 中没有转换为 4 位。
以 skimage 为例:
import cv2
from skimage import exposure
from skimage import img_as_ubyte
src = cv2.imread("cicek.png",0)
print("type: ",src.dtype,"min: ", src.min(),"max: ", src.max(),"size: ",src.shape)
img = exposure.rescale_intensity(src, in_range=(0,15))
上面的代码不起作用。
解决方案
推荐阅读
- r - 在 R 中排列 4 个 plotly 饼图
- qt - 如何在 QML 5.14 中使用 Markdown 格式
- html - 将响应按钮放置在 TextArea 内
- javascript - ReactJS:如何传递字符串以用作函数名?
- android - 如何重新生成 android_gradle_build.json 以使我的 NDK 项目从 Gradle 构建?
- mongodb - 可以在 Mongo 中有效索引的列表的最佳方法
- python - pytorch nn.L1Loss 与 Sklearn 的 l1 损失 - 优化结果非常不同?
- javascript - 如何使用 socket.io 在与多个用户的会话中保留变量?
- android - android 应用程序中的泄漏:SmoothScroller 的一个实例被启动了不止一次
- c++ - Windows 后台服务(系统配置文件)无法使用 C++ 访问 win 10 上的用户 appData 文件夹?