Search code examples
imagemagickimagemagick-convert

Convert 15-bit color space PNG image to text file


I'm unsure if imagemagick is able to do this, or if I need to write something myself; but I'd like to convert an image such as the below to a text file such that each line represents a single pixel (reading left to right, top to bottom) and has 15-bits of data on each line (5 bits for R, G, and B).

So for example the below image would have 256x224 = 57,344 lines of 15-bits.

Is imagemagick capable of doing this? If not is there another resource? Appreciate any help.

enter image description here


Solution

  • Just use the ".txt" output format:

    magick U4zI6.png U4zI6.txt
    

    This will have more voluminous information for each line, but you can use a text editor such as "sed" to extract the RGB values.

    $ head -6 U4Zi6.txt
    # ImageMagick pixel enumeration: 256,224,65535,srgb
    0,0: (28784,45232,53456)  #70B0D0  srgb(112,176,208)
    1,0: (28784,45232,53456)  #70B0D0  srgb(112,176,208)
    2,0: (28784,45232,53456)  #70B0D0  srgb(112,176,208)
    3,0: (28784,45232,53456)  #70B0D0  srgb(112,176,208)
    4,0: (28784,45232,53456)  #70B0D0  srgb(112,176,208)