Home / Alt manpages / spottopgm(1)

  • spottopgm(1)
  • User command
  • linux

Convert a SPOT Satellite Image to PGM with spottopgm

spottopgm turns a SPOT satellite image into a greyscale PGM, one band at a time, optionally cropped to a rectangle. These examples use Netpbm 11.5.2, Debian package version 2:11.05.02-1.1build1.

Allow fifteen minutes, more if the source image itself is slow to locate or copy. You need a readable SPOT image, a shell, and enough free space for the output. No elevated privileges required; only reach for sudo when the input or destination is genuinely inaccessible to your normal account.

1. Confirm the installed command

Ordinary, read-only checks before you start:

$ command -v spottopgm
/usr/bin/spottopgm
$ dpkg-query -W -f='${Package} ${Version}\n' netpbm
netpbm 2:11.05.02-1.1build1

The binary reports its Netpbm library version when given an unsupported invocation or an unusable input; on this installation that is Netpbm 11.5.2. The local manual documents no clean version-only flag, so do not build scripts around that diagnostic text.

Checkpoint

If command -v prints nothing, stop and install Netpbm the normal way. Do not drop a different spottopgm into a working directory and assume its syntax matches this guide.

2. Inspect the source without changing it

Record the path and check it is readable, swapping in your real file name:

$ INPUT='/path/to/spot-image'
$ ls -lh -- "$INPUT"
$ test -r "$INPUT" && echo 'input is readable'
input is readable

The program takes one input file after its options and writes the converted PGM to standard output, so you need a shell redirect to get a file out of it. Keep the source untouched: a failed conversion can still leave a partial destination if you redirect straight to a named file.

There is no reliable generic file-type check that covers every SPOT variant. The manual is upfront that the program has only been tested against a limited number of images, so a successful exit status just means the conversion completed, not that the source is a genuinely valid image from your collection.

3. Convert the default band and whole image

Start with the simplest form: band 1, the program's default rectangle.

$ spottopgm "$INPUT" > spot-band1.pgm
$ status=$?
$ printf 'spottopgm exit status: %s\n' "$status"
spottopgm exit status: 0

Band 1 is the default. The manual names the three choices as infrared, visible light and ultraviolet, but never says which number maps to which physical band. Do not label your output "infrared" or "visible" just because it looks that way; use a neutral name like spot-band1.pgm until your own source documentation confirms the mapping.

Converting a colour SPOT image makes spottopgm announce that fact on standard error, along with the input width. Neither message is part of the PGM data, which is why the example above only redirects standard output.

Checkpoint

Confirm the output exists and is not empty:

$ ls -lh -- spot-band1.pgm
$ file -- spot-band1.pgm
spot-band1.pgm: Netpbm image data, greymap

file's exact wording can vary by version. What matters is a non-zero size and a description that reads as PGM or Netpbm greymap. A non-zero return code means preserve the source and read the diagnostic before switching bands.

4. Select another band

Use exactly one of -1, -2 or -3 before the input path. This creates a separate result for band 2:

$ spottopgm -2 "$INPUT" > spot-band2.pgm
$ printf 'exit status: %s\n' "$?"
exit status: 0
$ file -- spot-band2.pgm
spot-band2.pgm: Netpbm image data, greymap

Warning

Never pass -1, -2 and -3 together. The synopsis treats them as alternatives, and the tool only ever produces one PGM image, not a three-colour PPM. Need all three bands? Run three separate conversions to three separate output paths, and keep the band number in each file name.

That still does not give you a red, green, blue image. The manual is explicit that there is no one-to-one correspondence between RGB and the SPOT infrared, visible and ultraviolet bands. Combining the files into a colour composite is a separate image-processing job that needs documented band semantics you probably do not have yet.

5. Crop to a rectangle

Supply four positional values before the input file: Firstcol Firstline Lastcol Lastline. All four go together, or none:

$ spottopgm -2 100 200 1100 1200 "$INPUT" > spot-window.pgm
$ printf 'exit status: %s\n' "$?"
exit status: 0
$ file -- spot-window.pgm
spot-window.pgm: Netpbm image data, greymap

This crops to the described rectangle; it does not resize anything. The manual never says whether the boundary values are inclusive or exclusive, so do not calculate an exact output width by hand. Check the result with file or an image viewer instead.

Most SPOT images run around 3000 lines and at least 3000 columns wide, but the format only records the width, not the length. That is why the default rectangle uses the detected width and a fallback of 3000 lines. If your source has a different known extent, pass an explicit rectangle rather than trusting that fallback.

6. Protect existing output files

Warning

Shell redirection with > truncates its destination before spottopgm even starts. Never point a first attempt at a PGM file you already care about. Write to a temporary name, check it, then replace the old file once you have decided the result is good:

$ spottopgm -2 "$INPUT" > spot-band2.pgm.new
$ test "$?" -eq 0 && test -s spot-band2.pgm.new
$ file -- spot-band2.pgm.new
spot-band2.pgm.new: Netpbm image data, greymap
$ mv -- spot-band2.pgm.new spot-band2.pgm

That final mv is a deliberate overwrite, so treat it that way. If conversion fails, skip that step entirely; remove the incomplete .new file only after confirming it is not the only copy you need, since deleting it is permanent. Writing across filesystems? Use a temp file in the destination directory and check space first.

7. Diagnose a failed conversion

Start with the diagnostic and exit status. A missing or unreadable path is a shell and permissions problem, not a reason to change image parameters:

$ ls -l -- "$INPUT"
$ test -r "$INPUT" && echo readable || echo 'not readable'
$ spottopgm "$INPUT" > spot-check.pgm
$ printf 'exit status: %s\n' "$?"
exit status: 1

An empty or truncated file gets an input error and no PGM data written, in the tested case. Do not treat a diagnostic on standard error as image metadata, and never feed a partial output into a later conversion step without checking it first.

  • Wrong size output? Use the reported width and your source documentation to pick an explicit rectangle.
  • Unexpected content? Try another band into a different output file and confirm the source's band definitions.

The program's own limitation still applies: it cannot determine the input length in one pass, and it makes no promise of working with every SPOT image out there.

Done means

  • Command confirmed. spottopgm is the installed Netpbm command you meant to run.
  • Source untouched. The file remains unchanged and readable by your normal account.
  • Band recorded. The chosen band is noted in the output name or your accompanying notes.
  • Output checked. Non-zero size, passes a file-type check.
  • Rectangle explicit where needed. You used a stated rectangle whenever the 3000-line default was unsuitable.
  • Nothing overwritten early. No existing output was replaced before a new conversion had been checked.