How to convert a 16 bit to an 8 bit image in OpenCV?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have a 16bit grayscale image and I want to convert it to a 8bit grayscale image in OpenCV for python to use it with various functions (like findContours etc.). Is it possible to do it in python or I have to switch to C++? 回答1: You can use numpy conversion methods as an OpenCV mat is a numpy array. This works: img8 = ( img16 / 256 ). astype ( 'uint8' ) 回答2: You can do this in Python using NumPy by mapping the image trough a lookup table. import numpy as np def map_uint16_to_uint8 ( img , lower_bound = None , upper_bound = None ):