Home / Alt manpages / pamsharpmap(1)

  • pamsharpmap(1)
  • User command
  • linux

Measure Image Sharpness with pamsharpmap

You will create a Netpbm image that makes local sharpness visible, check its dimensions and format, and keep the original image unchanged. The examples use pamsharpmap from Netpbm package version 2:11.05.02-1.1build1 on this machine.

Allow about fifteen minutes. You need a readable PNM or PAM image, the pamsharpmap command, and a Netpbm viewer or inspection tool such as pamfile. The workflow is unprivileged: do not use sudo unless the input or output directory is deliberately restricted.

1. Check the installed command

Confirm that the command resolves to the Netpbm program you expect and record the package version. These are read-only checks:

$ command -v pamsharpmap
/usr/bin/pamsharpmap
$ dpkg-query -W -f='${Package} ${Version}\n' netpbm
netpbm 2:11.05.02-1.1build1
$ pamsharpmap --help
pamsharpmap: Use 'man pamsharpmap' for help.

There are no pamsharpmap-specific switches. Its synopsis is pamsharpmap [imagefile], so a file name is optional. The command also accepts the common options provided by the Netpbm library, but this guide does not need any of them.

Checkpoint: if command -v prints nothing, stop here and install or enable Netpbm through your normal package-management process. Do not copy a binary from an unrelated host just to make the example run.

2. Choose a new output path

pamsharpmap writes the result to standard output. Shell redirection with > truncates an existing destination before the program starts, so use a new name while testing. This example assumes your source is called photo.ppm:

$ test -r photo.ppm && echo 'input is readable'
input is readable
$ pamfile photo.ppm
photo.ppm: PPM raw, 1920 by 1080  maxval 255

The exact pamfile wording varies with the input. The useful checks are that the file is readable and that it is a PNM image, or a PAM image whose tuple type is compatible with PNM. pamsharpmap assumes that format family; for another image format, convert it first with an appropriate Netpbm tool.

Warning: do not redirect straight to the only copy of a useful image. If you have already chosen an output name that exists, make a backup or select a temporary name and rename it only after inspection. The input itself is read, not modified.

3. Generate the sharpness map

Run the command with the input file and capture standard output in a new PPM file:

$ pamsharpmap photo.ppm > photo-sharpness.ppm
$ printf 'exit status: %s\n' "$?"
exit status: 0
$ pamfile photo-sharpness.ppm
photo-sharpness.ppm: PPM raw, 1920 by 1080  maxval 255

A zero exit status means the command completed and the inspection confirms the output is a PPM with the expected dimensions. The output keeps the input dimensions, depth and tuple type, but its maxval is always 255. That last detail matters when you compare it with an input that used a different maxval.

Checkpoint: verify that photo.ppm still exists and that photo-sharpness.ppm is non-empty:

$ test -s photo.ppm && test -s photo-sharpness.ppm && echo 'both images are present'
both images are present

4. Read what the map means

Sharpness here is not a camera-lens score. At each pixel, pamsharpmap calculates the average intensity difference between that pixel and the eight surrounding pixels. A sudden local change produces a brighter component in the result; a flat area produces a darker one.

The calculation is performed separately for the red, green and blue components. An edge that is strong in red and green but weak in blue therefore appears yellow in the map. This is useful when you want to see which channels contain local detail, not merely where luminance changes.

Do not expect the outside row and column to behave like interior pixels. At the image edges, the program assumes a black border where neighbouring pixels are missing. That assumed border can make the outer edge appear sharper than a similar flat area inside the image.

Use an image viewer or convert the PPM for visual inspection. If pnmtopng is installed, make a separate preview:

$ pnmtopng photo-sharpness.ppm > photo-sharpness.png
$ file photo-sharpness.png
photo-sharpness.png: PNG image data, 1920 x 1080, 8-bit/color RGB, non-interlaced

The PNG conversion is optional and belongs to pnmtopng, not pamsharpmap. If the map looks uniformly dark, that can be a real result: the input may contain broad, gradual changes rather than strong local edges.

5. Use standard input when a pipeline needs it

Because the image argument is optional, you can supply a PNM image on standard input. This is useful when another Netpbm command produces the image:

$ pamtopnm source.pam | pamsharpmap > source-sharpness.ppm
$ pamfile source-sharpness.ppm
source-sharpness.ppm: PPM raw, 1920 by 1080  maxval 255

Keep the stages separate while troubleshooting. First save and inspect the converted input if the pipeline fails, then run pamsharpmap on that saved file. A producer that emits a non-PNM stream can make the failure look like a sharpness calculation problem.

6. Diagnose failures without changing the source

If pamsharpmap cannot open the input, check the path and permissions:

$ ls -l photo.ppm
$ test -r photo.ppm && echo readable
readable

If it rejects the file or produces an unhelpful result, inspect the header with pamfile or file. The manual only promises meaningful results for PNM or a PNM-equivalent PAM image. A JPEG, PNG or unrelated PAM tuple type needs conversion or a different tool.

If the output has the wrong apparent size, check the output with pamfile rather than trusting the file name. pamsharpmap does not resize an image. It preserves the input dimensions, so an unexpected size normally comes from the input or from an earlier pipeline stage.

To recover from an interrupted or failed run, leave the original alone and remove only the incomplete new output after checking its path carefully. If you used a temporary name, simply discard that temporary file through your normal cleanup process and rerun the command. No service restart or elevated privilege is required.

Done means

  • You confirmed the installed pamsharpmap and Netpbm version.
  • The source is a readable PNM or compatible PAM image.
  • The result was written to a new file and has the expected dimensions.
  • You know the map measures local component changes and uses a black border at the edges.
  • The result has maxval 255, and any PNG conversion was performed separately.
  • The original image remains available for comparison or recovery.