Saving images with > 8 bits per pixel

Can someone point me into the right direction, please? What is the best way to save images with more than 8 bits per pixel into a file. I’m aware that there are a few formats supported by Common Vision Blox that can - in principle - store more than 8 bits per pixel, but each seems to have its disadvantages: MIO is proprietary and only usable by those who use Common Vision Blox, TIF always saves black images for me, J2K takes a long time to compress plus it’s not a very widespread format. :angry:

Hi,

as you pointed out, there is currently no “perfect” format for storing any image data, therefore the “best” format strongly depends on the criteria that you apply. You’ve summarized most of it already, but let me break it down once more:

  • The MIO format is by far the most flexible format supported in Common Vision Blox. It covers all the possible bit-depths and pixel formats, so it would even be possible to save, say, images with 64 bit floating point pixels.
    However, MIO is an entirely proprietary format whose (undocumented) structure is determined by the way an IMG object in Common Vision Blox is serialized/deserialized, and there is no chance to exchange MIO files between people using something other than Common Vision Blox.
  • TIFF on the other hand is a very wide-spread format that covers a surprisingly large variety of formats. However, finding a piece of software that supports more or less the entire TIFF standard is difficult. Common Vision Blox is no exception: It supports TIFF files with 8 or 16 bits per pixel monochrome or RGB single page TIFF files. Nothing more. Bit depths from >8 and <16 are stored as 16 bit TIFF file for the sake of compatibility (in principle, TIFF also knows 10 and 12 bit per pixel formats but few programs will actually read them).
    The latter is most likely also the reason why your saved TIFF files appear black: If your image source provides for example 10 bits per pixel, the most significant byte of each pixel will not have more than two bits set. If the viewer you are using simply downshifts 16 bit pixels by 8 bit, the result will appear almost black.
  • PNG also supports 8 and 16 bits per pixel and color component, and like with TIFF the bit depths >8 and <16 are stored as a 16 bits per pixel file.
  • J2K (JPEG2000) in Common Vision Blox is supported with 8, 10, 12 and 16 bits per pixel. The component information is stored in the file, so bit depths >8 and <16 are not simply treated as 16 bit formats. However, as you correctly pointed out, the compression process for JPEG2000 is very time consuming, making saving image data in J2K files probably the computationally most expensive approach.

Apart from these defined formats, there is also a possibility to store the raw pixel data into a file. However, in that case it is entirely up to you how you make the additional (and required!) information about the image available to the user (namely: width, height, number of pixel components, number of bits per pixel component). Raw data access is easiest with the function ImageToMemoryRaw:

// assumption: img is a handle pointing to a valid CVB image...
auto bufferSize = ImageToMemoryRawSize(img);
std::vector<uint8_t> buffer(bufferSize);
ImageToMemoryRaw(img, buffer.data(), buffer.size(), RFL_Interleaved);
// buffer now contains the raw pixel data of the image as a byte sequence;
// this may now be saved to a blunt binary file
std::ofstream output("pathtomyfile", std::ios::binary);
output.write(buffer.data(), buffer.size());
// don't forget about width, height, #components and #bitspercomponent!
1 Like

Not a great solution, but a solution… And you were actually right: The TIFF file only appears black - but it does so in almost every viewer I tried…

The Common Vision Blox Viewer can display 16Bit information (e.g. 16Bit TIFF images) using auto mapping functions.

Under View -> High Bit Scale Mode you can choose between

  • On (Global), where the 16Bit Grey Values are mapped to 8Bit independant of the range of the grey values in the current image from 0 to 65535.
  • On (View Port), where the 16Bit Grey Values are mapped to 8Bit within the range of the min and max grey value, visible in the current view of the image display.
  • Off (Wrap Around), where the 16Bit Grey Values are mapped to repetitive segments of 8Bit from 0 to 65535.

So for your images where only the lower values of the 16Bit information are present, mode View Port or Wrap Around should help to make the information visible.

1 Like