Home / Alt manpages / pamsharpness(1)

  • pamsharpness(1)
  • User command
  • linux

Measure PNM image sharpness with pamsharpness

You will finish with a repeatable sharpness measurement for a PNM or PAM image, plus a safe way to compare several images without modifying them. pamsharpness is part of Netpbm. The installed package on this machine is Netpbm 2:11.05.02-1.1build1. Allow about ten minutes if the image is already in a Netpbm format.

You need a shell, a readable PNM or PAM file, and the netpbm package. These examples only read images and print a result. They do not need sudo, change image files, or alter a service.

1. Check the installed command

Confirm that the executable is available before debugging an image path:

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

The manual page defines one positional argument, imagefile. It also permits the argument to be omitted, in which case the program can read a Netpbm image from standard input. There are no options specific to the sharpness calculation. The command accepts common libnetpbm options, but adding an option is not necessary for the basic measurement.

Checkpoint: if command -v prints nothing, stop and install Netpbm through your normal package-management process. Do not use sudo merely because the image itself is stored in your home directory.

2. Measure one image

Pass a readable PNM or PAM file by its path:

$ pamsharpness /path/to/input.ppm
Sharpness = 0.111111

Your number will depend on the image. The output is a message on standard output, not a rewritten image or a report file. Capture the exit status immediately if a script needs to distinguish success from failure:

$ pamsharpness /path/to/input.ppm
Sharpness = 0.111111
$ printf '%s\n' "$?"
0

A successful status means the program read the image and completed its calculation. It does not mean that the image is aesthetically sharp, correctly exposed, or suitable for a particular print size.

3. Understand what the number measures

pamsharpness calculates the average difference in intensity between each pixel and its eight surrounding pixels, considering the red, green and blue components. It excludes the outside edge of the image because edge pixels do not have eight neighbours.

In practical terms, a larger value means more abrupt local colour or intensity changes under this measurement. That can indicate detail or a strong boundary, but it can also come from noise, compression artefacts, text, or a high-contrast background. Treat the result as a measurement of local change, not as a universal camera-quality score.

Compare like with like: use the same dimensions, crop, format and processing where possible. A resized image, a sharpened export, or a different subject can change the number. The manpage does not define a fixed scale of acceptable sharpness, so do not invent a pass threshold from one sample.

4. Use standard input in a pipeline

Omit the filename when another command produces a PNM stream:

$ cat /path/to/input.ppm | pamsharpness
Sharpness = 0.111111

The same form works with an existing Netpbm converter in place of cat. Keep the producer separate while testing so that an error is not mistaken for a low sharpness result. For a file comparison, print the filename alongside the command output:

for image in /path/to/reference.ppm /path/to/candidate.ppm; do
    printf '%s: ' "$image"
    pamsharpness "$image" || exit $?
done

This is a read-only loop. It stops on the first failed measurement instead of silently reporting an incomplete comparison.

5. Diagnose input and output mistakes

If the command cannot open a file, check the exact path and read permission without changing anything:

$ ls -l /path/to/input.ppm
$ test -r /path/to/input.ppm && printf '%s\n' 'readable'
$ pamsharpness /path/to/input.ppm
Sharpness = 0.111111

For a missing file, the installed command prints an error such as Unable to open file ... and returns status 1. Correct the path or permissions, then rerun the check. Do not redirect the diagnostic away while investigating.

The program assumes that its input is a PNM or a PNM-equivalent PAM image. If you give it another format, the result is not necessarily meaningful. Check the file with an appropriate inspection tool before measuring, and convert it to a supported Netpbm format in a separate output file if needed. Preserve the original until the converted image has been checked.

Done means

  • pamsharpness is available from the installed Netpbm package.
  • The input is a readable PNM or PNM-equivalent PAM image.
  • The command printed a numeric Sharpness = ... result and returned status 0.
  • Comparisons use images whose size, crop and processing are understood.
  • No original image was overwritten and no elevated privilege was used.