9 Format Conversion

 9.1 CONVERT
 9.2 PBMplus
 9.3 Image Resizing

9.1 CONVERT

The Starlink CONVERT package is used to convert data files between Starlink’s Extensible n-dimensional Data Format (NDF), which is used by most Starlink applications, and a number of other common data formats. Using these utilities, astronomers can process their data selecting the best applications from a variety of Starlink or other packages. The package is discussed in depth in SUN/55.

Starting up the CONVERT package will also set up defaults for the automatic NDF conversion facilities to enable applications which use the NDF library to read and write most of the file formats handled by the CONVERT package.

An application to convert NDF to a PBMplus format PGM file is one of the conversion utilities available, so further conversion (to formats not handled by CONVERT) can be carried out using the PBMplus package.

9.1.1 NDF2GIF

The NDF2GIF application (part of the Starlink CONVERT package, can be used to convert an NDF into the common (and therefore portable) GIF format. Usage:

 ndf2gif in [ out ] [ scale ] {high=? low=?
                             {percentiles=[?,?], [numbin=?]
                             {sigmas=[?,?]

The application converts the imput NDF image into a 256 grey-level GIF image, e.g. 

  % ndf2gif image scale=percentiles

will convert the file image.sdf into a GIF file scaling the image between the values corresponding to two percentiles. In this case, since the thresholds were not provided, the program would prompt for the percentile values between which the image should be scaled.

9.2 PBMplus

The PBMplus package is a command line toolkit for fonverting a large slection of image formats to and from a portable internal format. In addition to the converters the package includes some (simple) tools for manipulation of the images while in the portable format. PBMplus compiles out of the box, however you may want to add support for TIFF, JPEG and PNG format images by installing the relevant libraries, see http://www.acme.com/software/pbmplus/ for details.

A quick example, if you want to convert a Sun raster file to a Postscript file you’d use something that looks like:

  % rasttopnm < infile | pnmtops > outfile
9.2.1 PBM, PGM, PPM or PNM images?

The PBMplus package is split into four distinct suites. PBM programs to handle bitmaps (1 bit per pixel), PGM programs to handle grayscale images, PPM programs to handle full colour images and lastly PNM programs which carry out content-independent manipulations on any of the three internal formats. PBM stands for Portable Bit Map, PGM stands for Portable Gray Map, PPM stands for Portable Pixel Map and PNM stands for Portable Any Map

The suites are upwardly compatible, e.g. PGM programs can read both PGM and PBM files, but only write PGM files, and PPM programs can read all three formats, butu only write PPM files. PNM programs will read all three formats and , in general, write out the same type as they read in. Understanding this realtionship is fundamental to understanding the way the package works. for instance if you want to convert an xwd to a gif file you would read the xwd image in using xwdtopnm and then convert to gif using ppmtogif. Since ppmtogif is a PPM program it can read whichever of the three formats xwdtopnm writes.

9.3 Image Resizing

A common task linked with format conversion is image resizing. Traditionally under UNIX most people tend to use the XV package to carry out this task, unfortunately this package has poor dithering capabilities and resized images tend to be badly pixelated. I’d personally recommend the ImageMagick display application which does a superior job of dithering the final resized image to avoid pixelization.