Converting to PGM to stdout from TIF file does not result in PGM output
Posted: 2019-04-02T11:19:07-07:00
I am confused about how to convince "convert" to provide the output I need. I want to convert images to PGM format for script processing of images as plain numbers using pipes.
I found out that outputting to a stdout and to a file will not always result in the same format. The last should be P3 (color) but is actually P2 (gray).
Also, TIFF images are not being converted to PGM when output is stdout. Converting the rose to TIFF, then converting the rose TIFF to PGM will not provide PGM of ony kind but will continue to be a TIFF.
How do I obtain PGM (P2/P3) data on stdout from a TIFF file?
Thanks
ImageMagick 7.0.8-36 Q16 on gentoo linux
I found out that outputting to a stdout and to a file will not always result in the same format. The last should be P3 (color) but is actually P2 (gray).
Code: Select all
convert rose: -depth 8 -set colorspace Gray -compress none -format pgm - | head -n 1 # P2
convert rose: -depth 8 -set colorspace RGB -compress none -format pgm - | head -n 1 # P3
convert rose: -depth 8 -set colorspace Gray -compress none -format pgm test.pgm ; head -n 1 test.pgm # P2
convert rose: -depth 8 -set colorspace RGB -compress none -format pgm test.pgm ; head -n 1 test.pgm # P2 -- why???
Code: Select all
convert rose: rose.tif
convert rose.tif -depth 8 -set colorspace RGB -compress none -format pgm - > test.dat
identify test.dat # test.dat TIFF 70x46 70x46+0+0 8-bit sRGB 9924B 0.000u 0:00.000
Thanks
ImageMagick 7.0.8-36 Q16 on gentoo linux