0

I am working with a 12bit monochrome camera. It can do 8bit but I need the extra bits of data for some calculation around certain pixels. So I am using the camera generating a 16 bit grayscale TIFF file (the only way to get the 12 bit of data that I need).

the content of each pixel (per manufacturer) is: 11111111 1111XXXX - white 00000000 0000XXXX - black

where X is random (again per manufacturer).

the file doesn't look as if the last 4 bits are random but that's another matter (out of topic).

What I am trying to do is open that file, read the pixel value (first 12 bits) for a given pixel (say X, Y).

I looked online but all I could find were projects that will read the all 16 bits...

edit: I was able to directly read the camera buffer which gives me access to the whole 16 bits. I end up with a UInt16 which I need to transform into a 12 bit number.

user3617652
  • 143
  • 2
  • 12

1 Answers1

2

There is no way to read parts of bytes directly from a file. You'll need to read each pixel you want and just get rid of the last 4 bits. E.g.

int i; // some pixel from the image int pixel = i >> 4; // pixel > 0 for white

This uses bit shifting to get rid of the bottom 4 bits.

OSborn
  • 895
  • 4
  • 10
  • Thanks.. My pixel value is of a type UInt16. PixelValue = NewValue >> 4 doesn't work. I am not sure what I am missing. – user3617652 Jun 19 '14 at 02:59
  • According to http://stackoverflow.com/questions/3819593/c-sharp-bitwise-shift-on-ushort-uint16 you'll just need to cast from the shifted value to UInt16. `ushort pixelFromImage = /*get from image*/; ushort pixel = (ushort)(pixelFromImage >> 4);` – OSborn Jun 19 '14 at 03:06