Home / Alt manpages / pgmtexture(1)

  • pgmtexture(1)
  • User command
  • linux

Measure Image Texture with pgmtexture

pgmtexture turns a greyscale PGM image into a table of texture numbers, so you stop eyeballing two images and start comparing them properly. Allow about fifteen minutes to get a repeatable command and a way to compare runs made at different pixel distances.

The installed Netpbm package here is version 2:11.05.02-1.1build1. Its pgmtexture command calculates features from spatial dependence matrices at 0, 45, 90 and 135 degrees.

  • You need: a readable PGM file, a shell and Netpbm.
  • It will not touch: the source image, root access, or system configuration. It only reads the image and writes results to standard output.

1. Confirm the installed command

Check the executable and package version before you trust output in a script or report:

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

Package versions differ between distributions. Keep the version beside saved measurements if the results ever need reproducing. The program reads one PGM image from the optional file argument, or from standard input when no file is supplied.

Checkpoint

Make sure the input really is the file you intend to analyse.

$ file /path/to/image.pgm
$ test -r /path/to/image.pgm && echo 'readable'

Do not confuse PGM with PPM. PGM is the greyscale Netpbm format this command expects. If you have another image format, convert it with a separate tool first and verify that conversion on its own.

2. Run the default measurement

Run pgmtexture with the input path as its final argument:

$ pgmtexture /path/to/image.pgm
pgmtexture: (Image has 4 gray levels.)
pgmtexture: Computing spatial dependence matrix...
pgmtexture:  ...done.
pgmtexture: Computing textural features ...
pgmtexture:  ...done.

Angle                           0         45         90        135        Avg
Angular Second Moment   ...
Contrast                ...
Correlation             ...
Variance                ...
Inverse Diff Moment      ...

The exact values and the number of grey levels depend on the image. The table has one column per direction plus an average column, and the default distance is 1 pixel. Progress messages and the table both go to standard output, so redirect it when you need a record:

$ pgmtexture /path/to/image.pgm > texture-distance-1.txt
$ test -s texture-distance-1.txt && echo 'measurement saved'

Warning

Redirection with > replaces an existing destination before the command even runs. If the old report matters, pick a new name or copy the old file first. For a safer replacement, write to a temporary name, check it, then move it into place deliberately:

$ pgmtexture /path/to/image.pgm > texture-distance-1.txt.new
$ test -s texture-distance-1.txt.new
$ mv texture-distance-1.txt.new texture-distance-1.txt

Recovery

If the measurement fails, remove only the incomplete .new file with rm -- texture-distance-1.txt.new. That deletion is irreversible, so check the name before running it. The original report stays in place until the final mv.

3. Choose a different pixel distance

Use -d followed by a distance when texture at a wider separation matters:

$ pgmtexture -d 2 /path/to/image.pgm > texture-distance-2.txt
$ test -s texture-distance-2.txt && echo 'distance-2 measurement saved'
  • Distance does not resize anything. It changes the separation used when building the spatial dependence matrices, not the pixel count.
  • Keep the distance in the filename and your notes. A distance-1 result is not directly interchangeable with a distance-2 result.
  • Use a positive integer that fits the image. A large distance leaves fewer useful pixel pairs, especially in a small image, and can make the result less representative. The manual documents distance 1 as the default; it makes no promise that a larger distance will produce a stable or useful measurement.

4. Read the feature table without overclaiming

The command prints a set of Haralick-style features: Angular Second Moment, Contrast, Correlation, Variance, Inverse Difference Moment, Sum Average, Sum Variance, Sum Entropy, Entropy, Difference Variance, Difference Entropy, Information Measures of Correlation, and Maximal Correlation Coefficient.

  • Compare like with like. Use the same image preparation, distance and command version when comparing samples.
  • Read the directional columns. They show that texture can vary with orientation, so the Avg column is a useful summary but should not replace the four directional values when orientation matters.
  • Treat the numbers as measurements, not labels. They are not "smooth" or "rough" on their own; interpret them in the context of your image set and preprocessing, and do not compare values from different grey-level scaling or different crops as if only texture had changed.

5. Handle the known convergence limitation

Maximal Correlation Coefficient needs a second-largest eigenvalue of a matrix named Q. The manual warns that this method does not always converge, so a run can print a warning or fail to give a trustworthy value even when the other rows look fine.

Capture both the output and the exit status when the result feeds automation:

$ pgmtexture -d 2 /path/to/image.pgm > texture-distance-2.txt
$ status=$?
$ printf 'pgmtexture exit status: %s\n' "$status"
pgmtexture exit status: 0

A zero status only tells you the process completed; it does not remove the documented convergence limitation. Review the terminal diagnostics and the Maximal Correlation Coefficient row before you publish a result. If convergence is reported as a problem, keep the other values only if your analysis explicitly allows a partial feature set, and record the warning alongside the measurement.

Do not hide diagnostics by redirecting only standard output while troubleshooting. For one combined capture, use &> in Bash, label the file clearly, then work out which lines are diagnostics and which are table data.

6. Diagnose ordinary input failures

If the command cannot open the image, check the path and permissions before reaching for elevated privileges:

$ ls -l /path/to/image.pgm
$ test -r /path/to/image.pgm && echo 'input is readable'
  • Not a valid PGM? Convert or repair it with the appropriate image tool rather than changing the pgmtexture command at random, and keep the original input unchanged while you test the conversion.
  • Reading from a pipeline? Isolate the producer first so you can tell whether the failure is in the image stream or in pgmtexture itself.
  • No need for sudo. Nothing here needs root unless your chosen input or output directory is deliberately restricted. Running as root will not improve the texture calculation, and it can leave root-owned report files that are awkward to replace later.

Done means

  • Confirmed the version. You checked the installed Netpbm version and the path to pgmtexture.
  • Measured the image. You ran a readable PGM through the documented default distance of 1.
  • Protected any redirected report. You stored it without blindly destroying a previous result.
  • Recorded non-default distances. You kept them beside their output and compared like with like.
  • Treated the convergence warning as real. You checked diagnostics and did not trust Maximal Correlation Coefficient blindly.
  • Stayed unprivileged. You used ordinary user permissions and left the source image and system configuration unchanged.