简体   繁体   English

Python:如何使用16位通道保存图像(例如48 RGB)?

[英]Python: How to save image with 16 bit channels (e.g. 48 RGB)?

I'm working scientifically with images from a microscope, where each of the 3 RGB channels are encoded as uint16 (0-65536). 我正在科学地使用显微镜中的图像,其中3个RGB通道中的每一个都被编码为uint16(0-65536)。 Currently I use OpenCV2 and NumPy to work with the images, and using the flag "cv2.IMREAD_UNCHANGED" everything works fine with the reading, and I can do some work on the image and return it to uint16, 目前我使用OpenCV2和NumPy来处理图像,使用标志“cv2.IMREAD_UNCHANGED”一切都可以正常阅读,我可以对图像做一些工作并将其返回给uint16,

img = cv2.imread('dummy.tif',cv2.IMREAD_UNCHANGED )
#do some work here
img = img.astype(numpy.uint16)
cv2.imwrite('processed.tif',img )

However, so far I can't seem to find any way to save the processed images as 16bit RGB again. 但是,到目前为止,我似乎无法找到任何方法将处理后的图像再次保存为16位RGB。 Using the cv2.imwrite command just convert the image to uint8, thus turning everything white (that is, everything is truncated to 255, the max for uint8 channels). 使用cv2.imwrite命令只需将图像转换为uint8,从而将所有内容都变为白色(即,所有内容都被截断为255,uint8通道的最大值)。

Any idea how to proceed? 知道怎么办吗?

Maybe it helps if the numpy.uint16 is replace by cv2.CV_16U. 如果numpy.uint16被cv2.CV_16U替换,也许会有所帮助。 In some example the parameter is passed in as a string eg 'uint16'. 在一些示例中,参数作为字符串传递,例如'uint16'。

Sry, reputation too low for a comment. Sry,声誉太低,无法发表评论。

OpenCV does support writing 16 Bit TIFF images. OpenCV支持写入16位TIFF图像。

Make sure you are using a current version (>= 2.2). 确保使用的是当前版本(> = 2.2)。

The truncation probably happens to img in your code before saving with OpenCV. 在使用OpenCV保存之前,截断可能恰好发生在您的代码中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM