Inkscape.org
Beginners' Questions inkscape 1.0: Export SVG to PNG, using 16 bit per monochrome pixel
  1. #1
    Bjo X Bjo X @xbjo

    Dear Community,

    Since a lot of years I am using Inkscape for generating vector drawings.

    Now with inkscape version 1.0 I have found a new feature I was waiting for:
    https://wiki.inkscape.org/wiki/index.php?title=File:Png-export-options_1.0.png

    Advanced features during export to PNG.
    For a current project I really need 16 bit precision / bit depth.
    Manually it works fine, but I need to automatize it from the command line, because of more than 1000 files ( I am simply too lazy ;-) )
    Currently I am using this call to inkscape in the command line :

    inkscape --export-type=png --export-area-snap --export-background=rgb(0,0,0) --export-area=0:0:200:200 --export-width 1024 --export-height 1024 Image.SVG

    How to use the 16 bit grayscale option and NO Anti-Aliasing from the command line for PNG generation.

    I looked into the action/verb lists, but I found no approach.
    Can you please help me out of this?

  2. #2
    Bjo X Bjo X @xbjo

    Related screenshot of intended export function that needs to become scripted/automatized...

    Inkscape Pngexport 16Bit Noaa
  3. #3
    Bjo X Bjo X @xbjo

    Dear Community,

    I reviewed the rastered 16bit gray images and they look exactly like 8bit exports. It is like a left 8 bit-shift of the 8-bit data.
    is it possible that the rasterization supports only 8bit?
    Does someone know how to get real 16bit values using the 16bit value range?

    I would really appreciate your feedback.

    Best regards,
    Bjo

  4. #4
    Xav Xav @Xav👹

    Pure speculation here, but I would imagine that they are just a left-shift of the 8-bit data. Bear in mind that Inkscape uses SVG as its native format, and SVG basically uses CSS for its colour definitions. Unfortunately the CSS colour model(s) are very limited and don't generally support higher bit depths (or other useful things like CMYK or Spot Colours). You can see from the XML editor that Inkscape uses RGB hex notation for its colours, even if you set them via the HSL or CMYK tabs in the UI. CSS hex notation is limited to 8-bits per channel.

    All of which makes me wonder what the benefit of the Bit Depth popup in the export dialog is. I can think of several possible reasons for allowing 16-bit export:

    • To make it easier to use the exported files in a workflow that can use larger bit depths without accidentally reducing the bit depth when overwriting the file.
    • To support more precision in gradients (I haven't confirmed if it does this).
    • To support linked or embedded content that is 16 bpp without quantising the values when exporting (also unconfirmed).
    • As a first step towards better colour support in future, especially if colour formats other than CSS hex RGB are ever supported (speculation).
    • Because the PNG library offered the options, so the developers thought they'd make them available (most likely reason!).

    In short: Inkscape colours are stored as 8-bit values. Where colours are interpolated (e.g. gradients, blurs) you might get full resolution values in the export, but I haven't tested. But for basic colours there's no way to set a full 16-bit value, so the values are likely to just be left-shifted to suit.

  5. #5
    Bjo X Bjo X @xbjo

    Dear Xav,

    Thank you for your detailed answer and the additional hints regarding the topic.

    In some of my test images I use 3 svg rectangle objects being filled by RadialGradients from red (rgb(100%,0%,0%)), green (rgb(0%,100%,0%)), blue (rgb(0%,0%,100%)) to all black (rgb(0%,0%,0%)).
    Independent of the target resolution I do not see more than 220 different pixel values in grayscale 16bit png.
    The gradient could potentially deliver that 16 bit per target pixel precision...
    I was hoping to get a full range of grayscale values, a later processing step (numpy) requires the precision of 16 bit per pixel.

    Attached you can find an example svg file that I used. While it describes some objects in color, my intention is to produce grayscale images of it as several resolutions in the target output.

    My intention in short words:
    SVG internal gradients should represent the object precision that is required for the target pixel depth of 16 bit.
    So I described the object in vector format in order to produce series of target PNG (or TIFF) that get used in a later numpy/python processing.

    In case someone knows a way how to get a 16 bit monochrome (or 16 bit per color plane) raster image from a svg input, please let me know.
    It is not only about the pixel target format of 16 bit, the value range of 16 bit ir required.

    Best regards,
    Bjo

  6. #6
    Xav Xav @Xav👹

    As you've confirmed that gradients aren't using the full 16-bit precision, I don't think there's anything more you can do other than open a feature request.

  7. #7
    Bjo X Bjo X @xbjo
    *

    Thank you, I am still hoping to find a nice solution within Inkscape.

    For my basic question "how to automatize 16 bit grayscale output" I could not find a solution by myself.
    But I am still interested in getting some hints on it...

Inkscape Inkscape.org Inkscape Forum Beginners' Questions inkscape 1.0: Export SVG to PNG, using 16 bit per monochrome pixel