Imshow() not showing image for CV_16UC3

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;
}

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

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.

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.

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

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.

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.