Ask Your Question

write / display binary data

asked 2015-05-14 03:49:54 -0600

jai gravatar image

updated 2015-05-14 03:59:35 -0600


i have read binary data using read function. Assigned this data to Mat object say image. If i am printing this image using<short>. i ; i am getting the desired elements values.

But now if i am trying to show it using imshow , i am getting a blank image. and if i am trying to write it imwrite , i am getting 0 byte data

please help to resolve this.

short *data;
int size= 512*512;

read(f, size, sizeof(short));

Mat image(512,512,3,data);
for(int i=0; i<512; i++)

imshow("image",image); //Blank\
imwrite ()// blank
edit retag flag offensive close merge delete


please add relevant code snippet, and maybe, a smallish example image.

berak gravatar imageberak ( 2015-05-14 03:54:35 -0600 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2015-05-14 04:25:51 -0600

berak gravatar image

updated 2015-05-14 04:28:16 -0600

if you really got [0..1] data in a short array, you won't see any difference in imshow(). try:

imshow("image",image * 1000);

or similar. in general, binary images in opencv are 0 or ~0 (255 for uchar, (2^16)-1 for short)

also, unsigned short (CV_16U) might be a better choice for binary

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2015-05-14 03:49:54 -0600

Seen: 2,306 times

Last updated: May 14 '15