OpenCV中的imshow函数深度剖析

版权声明:如需转载,请注明出处。 https://blog.csdn.net/Young__Fan/article/details/82999274

imshow函数OpenCV官方注释文档有一部分如下:

Displays an image in the specified window.

The function imshow displays an image in the specified window. If the window was created with the cv::WINDOW_AUTOSIZE flag, the image is shown with its original size, however it is still limited by the screen resolution.Otherwise, the image is scaled to fit the window. 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 or 64-bit floating-point, the pixel values are multiplied by 255. That is, the value range [0,1] is mapped to [0,255].

 翻译:

在指定窗口中显示图像。

函数imshow在指定的窗口中显示图像。如果窗口是使用cv::WINDOW_AUTOSIZE标志创建的,则图像显示为其原始大小,但仍受屏幕分辨率的限制。否则,图像将按比例缩放以适合窗口。该函数可以缩放图像,取决于其深度:

-如果图像是8位无符号的,它将按原样显示。
-如果图像是16位无符号或32位整数,像素就除以256。也就是说,值范围[0,255*256]被映射到[0,255]。
-如果图像是32位或64位浮点数,像素值将乘以255。也就是说,值范围[0,1]被映射到[0,255]。

总结:

       1.imshow可以直接显示8位无符号整型图像,像素值范围位(0,255)。

       2.imshow也是可以直接正常显示浮点型图像(32位或64位)的,当inshow函数遇到浮点型图像时,像素值将乘以255。也就是说,值范围[0,1]被映射到[0,255],然后就能正常显示了(这个过程是内部自动完成的)。前提是浮点型图像(即像素值范围为(0,1)),而不是随意取值范围浮点型矩阵。

扫描二维码关注公众号,回复: 4666621 查看本文章

      3.如果你计算得到一个矩阵,想让其显示为图像,若是8位无符号整型,像素值要在(0,255)区间内,如若不是需要进行范围归一化为(0,255)。若是浮点型的不在(0,1)范围,则要归一化范围为(0,1),或者直接转为8位无符号整型(如:用normalize函数归一 化为 0,255)范围后,再用convertScaleAbs函数将归一化后的图线性变换成8位无符号整型)。

 CV_32FC3类型的浮点型图像,用ImageWatch查看如下:

                        

猜你喜欢

转载自blog.csdn.net/Young__Fan/article/details/82999274