3D pgm output support

I am working with 3D pgm files which are supported as input in gmic but it seems output is not supported. The following is an example. Is there a way to force the output to be a 3D pgm?

gmic foo.labels.pgm -replace 1,0 -o labels.pgm
[gmic]-0./ Start G’MIC interpreter.
[gmic]-0./ Input file ‘foo.labels.pgm’ at position 0 (1 image 256x256x456x1).
[gmic]-1./ Replace pixel values 1 with 0 in image [0].
[gmic]-1./ Output image [0] as pgm file ‘labels.pgm’ (1 image 256x256x456x1).
[gmic]-1./ End G’MIC interpreter.

Thanks,

  • Alex

Hi Alex,

try to use “output_pink3d”. However pgm files extended to 3d are not readable in other applications besides gmic.

The app package pink uses pgm images extended to 3d and larger pixel size. Under https://perso.esiee.fr/~talboth/ISBS/Morpho/pink/doc/ you can find the format description.

Here is a format description from the pink package, which is partially implemented in gmic.

formats.txt (7.11 KB)

Many thanks Karo. This is indeed the intent of the 3D pgm, to use with pink. I was not aware of the output_pink3d option in gmic. I double checked and it seems it is not documented. Thanks also for the documentation links. I will peruse them.

I did a simple IO test to make sure this is working on my side,

gmic foo.labels.pgm -output_pink3d test.pgm -quit

but test.pgm is saved in 8 bits, max of 255, which is not sufficient to represent all labels in the input foo.labels.pgm (this is a connected component image with 611 different labels, one for each region). It does save a 3D pgm but the quantization is not correct. Any thoughts?

Thats the default P5 type

gmic h output_pink3d

gmic: GREYC’s Magic for Image Computing.

    ([https://gmic.eu](https://gmic.eu)) 



    Version 2.7.2 

    Copyright (c) 2008-2019, David Tschumperle / GREYC Lab / CNRS. 

    ([https://www.greyc.fr](https://www.greyc.fr))

output_pink3d:

    filename,_type

  Save selected images as _type-coded (P5,P8,P9) PPM files (PINK extension for 3d volumetric images).

In worst case do

gmic e $$output_pink3d

to see what happens.

Here is what I got

gmic run “e $$output_pink3d”

[gmic]-0./ Start G’MIC interpreter.
[gmic]-0./run/ Input file ‘“e’ at position 0
[gmic]-0./run/ *** Error *** Unknown command or filename ‘“e’ (did you mean ‘done’ ?).

My gmic version is 2.3.6. Do I need an update for the code to understand that I need to save in P8 not P5 format?

gmic h output_pink3d

gmic: GREYC’s Magic for Image Computing.

    Version 2.3.6, Copyright (c) 2008-2018, David Tschumperle. 
    (https://gmic.eu)

output_pink3d:
    filename,_type

  Save selected images as _type-coded (P5,P8,P9) PPM files (PINK extension for 3d volumetric images).

ok, my command was wrong, see my change.

No, no update necessary, however, it would be good, there are changes possibly in the pink calls too.

Yes P8 is the one you need for integers.

In fact, pink package was moved some time ago into my user gmic file, still added into the regular update files loaded by “gmic up”. Unluckily the documentation disappeared with this move.

I’ll see what I can do…

Here is a piece of the pink documentation. I am generating it for my own usage. The most important command is pink… For many pink programs the wrapper fits!
e.g.
pink. asf,5

pink cares for 2 or three dim data. For parameters call the pink exec without parameter

$ pink.asf

usage: pink.asf in.pgm [rayonmin] rayonmax out.pgm

**** PINK-library operators:

_xpink:
    pink_cmd,p1, ... ,pn

  Packs the list of parameters to a string with spaces,
  generates the pink input image in tmp and executes the pink command and reads the result image
  If $GMIC_PINK_VERBOSE is true, the command and sysout is printed
  If $GMIC_PINK_NO_RM is true, the temporary files are not removed

_xpinks:
    pink_cmd,parameter_string(with spaces)

  Splits c channel if necessary and executes "_xpink pink_cmd,parameter_string" to each image

output_pink3d:
    filename,_type

  Save selected images as _type-coded (P5,P8,P9) PPM files (PINK extension for 3d volumetric images).

pinkxipo:
    [b1],..[bn],name,pn+2, .. ,pm

  Pink wrapper pinkxipo[a] [b1,..bn,]name(pn+1)[,pn+2, .. ,pm] (requires the PINK library to be 
    installed).
  Executables with 1, 2-n input image files (xi), pos. parameters (p), output file (o)
  (https://perso.esiee.fr/~talboth/ISBS/Morpho/pink/doc/)
  prepares input, calls external "name inputa [inputb1 ... inputbn] [pn+2 ... pm] output" and 
    reads output (/tmp)
  Add. images are located before the pink executable name. If images are replaced by a parameter,
  e.g. null, than it has to be located after the executable name!

pink:

  Pink wrapper name,p1,...,pn (requires the PINK library to be installed).
  (https://perso.esiee.fr/~talboth/ISBS/Morpho/pink/doc/)
  prepares input, calls external "name input p1...pn output" and reads output (/tmp)

pink_grayskel:
    _connectivity={ 4 }, _lambda=0

  (https://perso.esiee.fr/~talboth/ISBS/Morpho/pink/doc/grayskel_8c.html)
  Grayscale homotopic skeleton (requires the PINK library to be installed).
  Default values: 'connectivity=4' and 'lambda=0'.

pink_heightmaxima:
    _connectivity={ 4 | 8 | 6 | 26 },_height=1

  (https://perso.esiee.fr/~talboth/ISBS/Morpho/pink/doc/heightmaxima_8c.html)
  Heightmaxima filtering (requires the PINK library to be installed).
  Default values: 'connectivity=4' and 'height=1'.

pink_heightminima:
    _connectivity={ 4 | 8 | 6 | 26 },_height=1

  (https://perso.esiee.fr/~talboth/ISBS/Morpho/pink/doc/heightminima_8c.html)
  Heightminima filtering (requires the PINK library to be installed).
  Default values: 'connectivity=4' and 'height=1'.

pink_htkern:
    _connectivity={ 4 | 8 | 6 | 26 }, _type={""|u}

  (https://perso.esiee.fr/~talboth/ISBS/Morpho/pink/doc/htkern_8c.html)
  (https://perso.esiee.fr/~talboth/ISBS/Morpho/pink/doc/htkernu_8c.html)
  Grayscale ultimate homotopic thinning/thickening without condition (requires the PINK library 
    to be installed).
  Default values: 'connectivity=4' and 'type=""'.

pink_lvkern:
    _connectivity={ 4 | 8 | 6 | 26 }, _type={""|u}

  (https://perso.esiee.fr/~talboth/ISBS/Morpho/pink/doc/lvkern_8c.html)
  (https://perso.esiee.fr/~talboth/ISBS/Morpho/pink/doc/lvkernu_8c.html)
  Grayscale ultimate leveling thinning/thickening without condition (requires the PINK library to 
    be installed).
  Default values: 'connectivity=4' and 'type=""'.

pink_reg_minima:
    _connectivity={ 4 | 8 | 6 | 26 }

  (https://perso.esiee.fr/~talboth/ISBS/Morpho/pink/doc/minima_8c.html)
  Regional minima (requires the PINK library to be installed).
  Default values: 'connectivity=4'.

pink_skelcurv:
    _prio={0|1|2|3|4|8|6|26},_connectivity={ 4 | 8 | 6 | 26 },_inhibit={""}

  (https://perso.esiee.fr/~talboth/ISBS/Morpho/pink/doc/skelcurv_8c.html)
  Curvilinear binary skeleton guided by a priority function or image (requires the PINK library 
    to be installed).
  Default values: 'prio=0', 'connectivity=4' and 'inhibit=""'.

pink_skelend:
    _connectivity={ 4 | 8 | 6 | 26 },_n=0

  (https://perso.esiee.fr/~talboth/ISBS/Morpho/pink/doc/skelend_8c.html)
  Homotopic skeleton of a 2d or 3d binary image with dynamic detection of end points (requires 
    the PINK library to be installed).
  Default values: 'connectivity=4' and 'n=0'.

pink_skeleton:
    _prio={0|1|2|3|4|8|6|26},_connectivity={ 4 | 8 | 6 | 26 },_inhibit={""}

  (https://perso.esiee.fr/~talboth/ISBS/Morpho/pink/doc/skeleton_8c.html)
  Ultimate binary skeleton guided by a priority image (requires the PINK library to be installed).
  Default values: 'prio=0', 'connectivity=4' and 'inhibit=""'.

pink_skelpar:
    _algorithm={0...29},_nsteps=_1,_inhibit=""

  (https://perso.esiee.fr/~talboth/ISBS/Morpho/pink/doc/skelpar_8c.html)
  Parallel binary skeleton (requires the PINK library to be installed).
  Default values: 'algorithm=4', 'nsteps=-1' and 'inhibit=""'.

pink_wshed:
    _connectivity={ 4 | 8 | 6 | 26 },_inverse={ 0 | 1 },_height=0

  (https://perso.esiee.fr/~talboth/ISBS/Morpho/pink/doc/wshedtopo_8c.html)
  Watershed (requires the PINK library to be installed).
  Default values: 'connectivity=4', 'inverse=0' and 'height=0'.

output_pinklist:
    _filename (def. $TMPDIR/pink.list)

  Write a pink list file from (2,n) or (3,n) coordinate list image

input_pinklist:
    file_name, _mode

  Read a pink list file (type G from pink.delaunay) at file_name and prepare
  _mode == 0 a 3d object or
  _mode != 0 the vertice, hull, edge lists and the adjacency matrix
  Other list file types are still not implemented

pink_delaunay:
    _mode

  Prepare the delaunay triangulation from a list of coordimates (vertices)
  using the external program pink.delaunay
  _mode == 0 a 3d object or
  _mode != 0 the vertice, hull, edge lists and the adjacency matrix

Thanks. This now works:

gmic e $$output_pink3d
[gmic]-0./ Start G’MIC interpreter.
[gmic]-0./ 28166output_pink3d
[gmic]-0./ End G’MIC interpreter.

How do I get gmic and/or pink understand that my output needs to be P8, not P5? Using output_pink3d as you suggested is only giving me a P5 pgm file, with one byte per voxel, not sufficient to accommodate labels beyond 255.

Thanks,

  • Alex

The PINK extension to the .pnm format is not a part of the .pnm standard, so in G’MIC, it’s better to use the .pnk extension to load/save this kind of file, when possible.

I have missed that I can add _type (=P8) on the call to ouput_pink3d,

gmic foo.labels.pgm -replace 1,0 -output_pink3d labels.pgm,P8

Now labels.pgm has the right voxels! Thanks.

The simple pink wrapper cares a bit for that for output. It is looking for the max value. Unluckily for input you have to look into the documentation

E.g.

gmic osteo +pink. label,4,min

gives a label image with more than 255 labels! To use pink binaries you should have open the documentation. The input and output formats are described. osteo is a test function from me with a grayscale image.

to look into gmic routines you have to quote $!

gmic e \$\$output_pink3d

This is my last message. I have to leave for more than two weeks. Best trials, pink is a certain challenge!

Thanks! I have already done a test. With .pnk the output filename does not need a qualifier, it is already inferred from the data. Nice!

Thanks for all the input and documentation pointers.

And if you really want to keep a .pgm extension when you save it, then

$ gmic ... output pnk:filename.pgm 

should also do the trick !

Thanks for the tip!

On a similar PINK topic, how to make calls to pink from gmic when the pink command requires two images? I tried the following but it failed, the syntax seems to be correct, or so I think!

gmic foo.pgm +pink heightminima,6,10 +pink[-1] minima,6 +pink[0] watershed,[2],6

gmic foo.pgm +pink heightminima,6,10 +pink[-1] minima,6 +pink[0] watershed,[2],6
[gmic]-0./ Start G’MIC interpreter.
[gmic]-0./ Input file ‘foo.pgm’ at position 0 (1 image 256x256x456x1).
[gmic]-1./ Call pink package on image [0] with cmd: “heightminima [img] 6 10 [img]”.
[gmic]-1./ Call pink package on image [1] with cmd: “minima [img] 6 [img]”.
[gmic]-1./ Call pink package on image [0] with cmd: “watershed [img] [2] 6 [img]”.
[gmic]-1./pink/*repeat/*local/_xpinks/*repeat/*local/_xpink/*if/ *** Error *** Exec status is 256.

I am sure I am doing something wrong!

Pink is only a wrapper for simple infile parameter outfile apps.
What you can do, create a pnk file and add the file name as positional parameter.

Thanks for the tip. I will give it a try.

I wonder why we can’t use more than one in memory image with -pink. It certainly knows how to use one image, why not two or more? Just curious.

Yes, why not allow image parameter in routine pink? The answer is, at the time pink was written, there was no image parameter possible and no pass of images.
Its now only a question of time and ability.

Thanks Karo for the information. I will follow your suggestion to load the image using a file name as positional parameter.