# Imshow() not showing image for CV\_16UC3

**URL:** <https://forum.opencv.org/t/imshow-not-showing-image-for-cv-16uc3/12663>\
**Category:** C++\
**Tags:** highgui, qt\
**Created:** [April 4, 2023, 12:35pm UTC](https://forum.opencv.org/t/imshow-not-showing-image-for-cv-16uc3/12663 "2023-04-04T12:35:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![pralhad](https://avatars.discourse-cdn.com/v4/letter/p/a88e57/32.png) [@pralhad](https://forum.opencv.org/u/pralhad)\
**Post date:** [April 4, 2023, 12:35pm UTC](https://forum.opencv.org/t/imshow-not-showing-image-for-cv-16uc3/12663/1 "2023-04-04T12:35:00Z")

</div>

Hi,  
I am trying to display BGR/RGB image of 3 channels. Each channel size is 16 bits.  
I tried following code snippet and it shows blank image without any pixel value. But if I change “CV\_16UC3” to “CV\_8UC3”, it works.

Am I missing something here?  
#include   
#include   
#include   
#include \<opencv2/core.hpp\>  
#include \<opencv2/imgproc.hpp\>  
#include \<opencv2/highgui.hpp\>  
using namespace std;

int main()  
{  
int width = 640, height = 480;  
cv::Mat src(height, width, CV\_8UC3, cv::Scalar(255,255,255));  
cv::imshow(“image1 16UC3”, src);  
cv::waitKey(0);  
return 0;  
}

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [April 4, 2023, 1:01pm UTC](https://forum.opencv.org/t/imshow-not-showing-image-for-cv-16uc3/12663/2 "2023-04-04T13:01:22Z")

</div>

problem is not really imshow() here (more like maths):

255 == 0xff == 1 \<\< 8 == white for an 8bit image

to achieve the same for 16bits, you need to initialize it with 0xffff or 1 \<\< 16

---

<div class="post-metadata">

**Author:** ![pralhad](https://avatars.discourse-cdn.com/v4/letter/p/a88e57/32.png) [@pralhad](https://forum.opencv.org/u/pralhad)\
**Post date:** [April 4, 2023, 1:12pm UTC](https://forum.opencv.org/t/imshow-not-showing-image-for-cv-16uc3/12663/3 "2023-04-04T13:12:16Z")

</div>

Thank you, Berek, for quick reply. Basically, I am seeing issue with any pixel value I specify, and I am not seeing an image for CV\_16CU3. I mean blank window appears and when I move mouse cursor, it doesn’t show even co-ordinates. I changed the pixel value as you suggested to 1 \<\< 16 = 65535 and still see the issue.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/1/18b6f800145e8af0082175f04cfc4363cbbcf3f7.png)

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [April 4, 2023, 3:11pm UTC](https://forum.opencv.org/t/imshow-not-showing-image-for-cv-16uc3/12663/4 "2023-04-04T15:11:04Z")

</div>

remove the opencv package you got from conda-forge, then install with pip

the Qt backend for OpenCV’s GUI might have issues. it’s kinda deprecated and hopefully soon will be obsolete.

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [April 4, 2023, 3:11pm UTC](https://forum.opencv.org/t/imshow-not-showing-image-for-cv-16uc3/12663/5 "2023-04-04T15:11:43Z")

</div>

> [@pralhad](#):
>
> 1 \<\< 16

that is wrong. it must be `(1<<16) - 1` because `(1<<16) == 65536` and `(u16)(65536) == 0`.

same goes for `1<<8 == 256`, which is `0` when cast to uint8

---

<div class="post-metadata">

**Author:** ![pralhad](https://avatars.discourse-cdn.com/v4/letter/p/a88e57/32.png) [@pralhad](https://forum.opencv.org/u/pralhad)\
**Post date:** [April 5, 2023, 4:13am UTC](https://forum.opencv.org/t/imshow-not-showing-image-for-cv-16uc3/12663/6 "2023-04-05T04:13:47Z")

</div>

Thanks for your help.

Now I am seeing image for white or black. I see issue, sometimes image window appears but does not show x, y co-ordinates on bottom bar of the image when I move mouse cursor on the image. As you suggested, let me try installing QT backend for opencv again.

We can close the ticket now. Thank you so much.

---

<div class="post-metadata">

**Author:** ![pralhad](https://avatars.discourse-cdn.com/v4/letter/p/a88e57/32.png) [@pralhad](https://forum.opencv.org/u/pralhad)\
**Post date:** [April 12, 2023, 8:16am UTC](https://forum.opencv.org/t/imshow-not-showing-image-for-cv-16uc3/12663/7 "2023-04-12T08:16:15Z")

</div>

I am able to see images of 6 bpc, 8 bpc, 10, 12, 14 and 16 bpc.

the issue is for 10, 12, 14 bpc I am not getting exact white image though I created white image.  
Example

6 BPC = 63 Max value;  
8 BPC = 255;  
10 BPC = 1023;  
12 BPC = 4095;  
14 BPC = 16383;  
16 BPC = 65535;

// I am creating image for 10 bpc, Meaning Red 10 bits, Green 10 bits and Blue 10 bits.  
// WHITE image  
#include  
#include  
#include  
#include \<opencv2/core.hpp\>  
#include \<opencv2/imgproc.hpp\>  
#include \<opencv2/highgui.hpp\>  
using namespace std;

int main()  
{  
int width = 640, height = 480;  
// Creating white image  
cv::Mat src(height, width, CV\_16UC3, cv::Scalar(1023, 1023, 1023)); // for 10 bpc  
cv::imshow(“image1 16UC3”, src);  
cv::waitKey(0);  
return 0;  
}

It is not showing white image exactly. Same I see with 12 bits, 14 bits. But for 16 bits it shows correctly.  
am I missing something here?  
Also not displaying X, Y co-ordinates at bottom bar of the imshow() window.
