The function imwrite saves the image to the specified file. The image format is chosen based on the filename extension (see imread() for the list of extensions). Only 8-bit (or 16-bit unsigned (CV_16U) in case of PNG, JPEG 2000, and TIFF) single-channel or 3-channel (with ‘BGR’ channel order) images can be saved using this function.
imshow:
The function may scale the image, depending on its depth:
If the image is 8-bit unsigned, it is displayed as is.
If the image is 16-bit unsigned or 32-bit integer, the pixels are divided by 256.
That is, the value range [0,255*256] is mapped to [0,255].
If the
image is 32-bit floating-point, the pixel values are multiplied by
That is, the value range [0,1] is mapped to [0,255].
感谢梅尔尼科夫·谢尔盖简要介绍了我的解决方案。 我已经解决了这个问题使用以下语法修改在我的程序。 当我写我的图像乘以255,我得到了同样的结果。在
这可能是因为您的数据类型。
imwrite
和imshow
根据数据类型自动决定如何处理数据。如imwrite和imshow的文档所述:imwrite
:imshow
:因此,您的底层数据类型似乎不是无符号字符,而是float或32位整数。在
此外,由于操作优先级,您可能会遇到以下问题:
(255)*(nir_img-red_img)/(nir_img+red_img)
你可能会溢出。最好将值设置在[0;1]的范围内,而不是将其相乘:
(255) * ( (nir_img-red_img)/(nir_img+red_img) )
相关问题 更多 >
编程相关推荐