alliedvision / VimbaPython

Old Allied Vision Vimba Python API. The successor to this API is VmbPy
BSD 2-Clause "Simplified" License
93 stars 40 forks source link

Convert Mono12 Frame to Bitmap #176

Closed lefevre-dev closed 9 months ago

lefevre-dev commented 9 months ago

Hello,

I changed Pixel format to Mono12, which lead to sensordepth of 12bpp. Vimba NET manual indicate that the Frame.Fill() method can only convert Mono12 Frames to Format8bppIndexed format Bitmap. It seems like the conversion will lose data since it converts 12 bits data to 8 bits data. Tell my if I am wrong. So I am wondering how to convert Mono12 Frame to bitmap without loosing data ? Why it is not possible to convert to Format16bppGrayScale, since 12 bits could fit into 16 bits ? Thanks

Teresa-AlliedVision commented 9 months ago

This is the repository for the VimbaPython API, not .NET. For questions regarding .NET, please contact support. https://www.alliedvision.com/en/about-us/contact-us/technical-support-repair-/-rma/ In general term though, to save 12bit nto 16bit, you need to normalize the values into the new value range to convert them to 16bit. If there is no available transformation. Such a conversion could look like this for an array with 3 values:

def convert_12_to_16(val):
    max_12_bit = pow(2, 12)
    max_16_bit = pow(2, 16)
    return int(float(val) / max_12_bit * max_16_bit)

values = [0, 2048, 4095]

for v in values:
    c = convert_12_to_16(v)
    print(f"""{v} --> {c}""")
lefevre-dev commented 9 months ago

Thank you very much for your response. Sorry for asking at the wrong place, I will contact the support as you said. Thank you for suggesting a conversion method.

Teresa-AlliedVision commented 9 months ago

No worries, we just need to make sure, that this isn't a general support forum, since we have a proper support structure, that works much better in helping with individual topics and applications fast.