Conversion from Mono12 to Mono16 - Flir

Hi,

I am using a Flir BlackflyS (BFS-U3-51S5) which is acquiring in Mono12p with a 12bit ADC. Looking at the FLIR docs (link below) I see how the bits are packed into bytes. We are looking to Unpack them into 16bit. I have made an unpacking script (below) which outputs what looks like a correct image but the min value is 5. We have taken the same images and converted them with the Flir SDK and see that the min value should be about 2 or 3, so there appears to be something wrong with how we are converting.

http://softwareservices.flir.com/BFS-U3-51S5P/latest/Model/public/ImageFormatControl.html

raw = np.array(tree["camera"]["frames"][str(i+1)])
first8, mid8, last8 = np.reshape(raw, (raw.shape[0] // 3, 3)).astype(np.uint16).T
first12 = first8 + ((mid8 & 0b1111) << 8)
last12 = (mid8 >> 4) + (last8 << 4)
out = np.reshape(np.concatenate((first12[:, None], last12[:, None]), axis=1),
                             [cam.attrs["frame_height"], cam.attrs["frame_width"]])

Any assistance would be much appreciated.
Thanks.

I’m not a python user, but it looks fine. An example of the image you get would be interesting. If the image seems correct, I don’t see why your calculation would give you a minimum value just off by just 2 or 3.

When the camera sensor is saturated, do you get a maximum value of (2^12 - 1) ?

Yeah very strange. No we get a max value of 4094 which is also odd.