首页 > 解决方案 > 如何使用 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))

上面的代码不起作用。

标签: pythonopencvimage-processingbitmap

解决方案


推荐阅读