Home / Alt manpages / spottopgm(1)

  • spottopgm(1)
  • User command
  • linux

Convert a SPOT Satellite Image to PGM with spottopgm

You will finish with a greyscale PGM file made from a SPOT satellite image, using a selected band and, if needed, a rectangular part of the source. The examples use Netpbm 11.5.2 from Debian package version 2:11.05.02-1.1build1, as installed on the machine used for this guide.

Allow about fifteen minutes, excluding time spent locating or copying a large source image. You need a readable SPOT image, a shell, and enough free space for the PGM output. The conversion normally needs no elevated privileges. Do not use sudo unless the input or destination is genuinely inaccessible to your normal account.

1. Confirm the installed command

Check the executable and package before you start. These are ordinary, read-only commands:

$ 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 invoked with an unsupported invocation or an unusable input. On this installation it reports Netpbm 11.5.2. There is no documented option in the local manual for printing a clean version-only response, so do not build scripts around the diagnostic text.

Checkpoint

If command -v prints nothing, stop and install Netpbm through your normal package-management process. Do not copy a different spottopgm into a working directory and assume its syntax matches this guide.

2. Inspect the source without changing it

Record the source path and check that it is readable. Replace the placeholder with the actual file name:

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

The program accepts one input file after its options. It writes the converted PGM image to standard output, so a shell redirection is needed if you want a file. Keep the original source untouched. A failed conversion can still leave a partial destination if you redirect directly to a named file.

There is no reliable generic file-type check for every SPOT variant. The manual warns that the program has only been tested with a limited number of images. Treat a successful exit status as evidence that the conversion completed, not as proof that the source is a valid image from your collection.

3. Convert the default band and whole image

Run the simplest form first. It selects band 1 and uses 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 identifies the three choices as infrared, visible light, and ultraviolet, but does not establish which number maps to which physical band. Do not label the result as infrared or visible merely because it looks that way. Use a neutral name such as spot-band1.pgm until the source documentation tells you the mapping.

While converting a colour SPOT image, spottopgm announces that fact on standard error. It also prints the input width on standard error. These messages do not form part of the PGM data, which is why the example redirects only standard output.

Checkpoint

Verify that the output exists and is not empty:

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

The wording from file can vary. The useful checks are a non-zero size and a description that identifies a PGM or Netpbm greymap. If the command returned non-zero, preserve the source and investigate the diagnostic before trying a different band.

4. Select another band

Use exactly one of -1, -2, or -3 before the input path. For example, 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

Do not pass -1, -2, and -3 together. The synopsis describes them as alternatives, and the tool produces one PGM image rather than a three-colour PPM. If you need all three bands, run three conversions to three different output paths and keep the band number in each name.

That workflow does not establish a red, green, and blue image. The manual explicitly says 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 task that requires documented band semantics.

5. Crop to a rectangle

Supply four positional values before the input file when you need a subset: Firstcol Firstline Lastcol Lastline. All four values belong together:

$ 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 example asks for the rectangle described by the four coordinates; it does not resize the image. The manual does not document whether the boundary values are inclusive or exclusive, so do not calculate an exact output width from them without checking the result. Use file or an image viewer to confirm the dimensions produced by your installed build.

Most SPOT images are around 3000 lines long and at least 3000 columns wide, but the format records the width rather than the length. The default rectangle therefore uses the detected width and 3000 lines. That 3000-line value is a fallback, not a measurement of your file. If your source has a different known extent, pass an explicit rectangle instead of accepting a potentially unsuitable default.

6. Protect existing output files

Shell redirection with > truncates its destination before spottopgm starts. Do not point a first attempt at a useful PGM file. Write to a new temporary name, check it, then replace the old file only when 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

The final mv replaces an existing destination with the checked file, so treat it as a deliberate overwrite. If conversion fails, do not run that command. Remove the incomplete .new file only after checking that it is not the only copy you need; deleting it is irreversible. If the destination is on a different filesystem, use a temporary file in the destination directory and check available space first.

7. Diagnose a failed conversion

Start with the diagnostic printed by the command and its exit status. A missing or unreadable path is a shell and permissions problem, not a reason to change the 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

If a file is empty or truncated, the installed command reports an input error and writes no PGM data in the tested case. A non-zero status is the boundary that matters for a script. Do not treat a diagnostic on standard error as image metadata, and do not feed a partial output into a later conversion step without checking it.

If the default output appears the wrong size, use the reported width and your source documentation to choose an explicit rectangle. If the image content is unexpected, try another band in a different output file and confirm the source's band definitions. The program's own limitation remains relevant: it cannot determine the input length in one pass and does not guarantee compatibility with every SPOT image.

Done means

  • spottopgm is the installed Netpbm command you intended to use.
  • The source file remains unchanged and is readable by your normal account.
  • The selected band is recorded in the output name or accompanying notes.
  • The PGM output has a non-zero size and passes a file-type check.
  • An explicit rectangle was used when the 3000-line default was unsuitable.
  • No existing output was overwritten until a new conversion had been checked.