Adjust Image Saturation Safely with pamaltsat
You will use pamaltsat to make a Netpbm image more vivid, less saturated, or greyscale, then verify that the result is a valid image without overwriting the source. Allow about fifteen minutes if Netpbm is already installed. The examples use Netpbm 11.5.2 from package version 2:11.05.02-1.1build1 on this machine.
The route
Jump straight to the step you need, or tick off Done means at the end.
This is an ordinary user-level workflow. You need a readable Netpbm image, such as PPM, and a directory where you can create a new output file. Nothing here needs sudo. Keep the original until you have inspected the result.
1. Check the installed command
Confirm that the command in your shell is the one you intend to run:
$ command -v pamaltsat
/usr/bin/pamaltsat
$ pamaltsat --version
pamaltsat: Using libnetpbm from Netpbm Version: Netpbm 11.5.2
pamaltsat: Built from source dated 2024-03-31 09:09:47
The exact build details vary by distribution. The relevant point is that this guide follows the installed Netpbm 11.5.2 behaviour. The command writes an image to standard output, so redirecting that output is part of every useful invocation.
Checkpoint
If command -v finds nothing, install the Netpbm package through your normal package-management process before continuing. Do not download a replacement binary into a system directory just to get this command.
2. Make a new image with the default spectrum method
The default method is called spectrum. It preserves each pixel's total intensity and leaves neutral grey pixels alone. A strength greater than 1 increases saturation; a value between 0 and 1 reduces it.
Use a new destination name. Shell redirection with > truncates an existing destination before pamaltsat has finished, so do not point it at your only copy:
$ pamaltsat -strength 1.6 /path/to/input.ppm > /path/to/input-saturated.ppm
$ file /path/to/input-saturated.ppm
/path/to/input-saturated.ppm: Netpbm image data, size 1920 x 1080, rawbits, pixmap
The dimensions and wording from file depend on your input and the installed file utility. A successful conversion should produce a non-empty Netpbm image with the same dimensions as the source. If the source is not a PPM, the output format is still a Netpbm format written to standard output, and the command's header is the authoritative check.
Do not confuse strength with a percentage. 1.6 means multiply the saturation by a factor of 1.6, not increase it by 1.6 percent. 1 leaves the image unchanged, subject to normal format conversion details.
3. Reduce saturation or create greyscale output
Use a fractional strength for a quieter result:
$ pamaltsat -strength 0.35 /path/to/input.ppm > /path/to/input-muted.ppm
$ file /path/to/input-muted.ppm
/path/to/input-muted.ppm: Netpbm image data, size 1920 x 1080, rawbits, pixmap
To remove saturation, pass zero:
$ pamaltsat -strength 0 /path/to/input.ppm > /path/to/input-grey.ppm
$ head -c 2 /path/to/input-grey.ppm
P6
Strength is mandatory and must be a real non-negative factor. Negative values are not a supported way to invert hue or produce a special effect. A missing value is an error, and the installed command exits with status 1 after reporting that -strength must be specified.
Checkpoint
Check the output header before opening it in a viewer. For a raw PPM result, file should report an image and head -c 2 should print P6. Do not use a text editor to inspect the whole file because the pixel data is binary.
4. Try the logarithmic method when its model fits
The alternative log method treats saturation using intensity ratios and raises component intensities to the requested power before restoring the original total intensity. It can reduce saturation by any requested factor. At high strengths, some pixels may reach the maximum saturation that is possible while preserving their original intensity, so a large number is not a guarantee of a proportionally stronger visible result.
Select it explicitly:
$ pamaltsat -method log -strength 2.1 /path/to/input.ppm > /path/to/input-log-saturated.ppm
$ file /path/to/input-log-saturated.ppm
/path/to/input-log-saturated.ppm: Netpbm image data, size 1920 x 1080, rawbits, pixmap
The two documented method names are spectrum and log. If you omit -method, spectrum is selected. Start with a moderate strength and inspect the output rather than assuming that a larger value is better. Images containing components at their maximum or minimum can behave differently from mid-range pixels.
5. Handle intensity-linear input correctly
Netpbm images are commonly stored with samples representing brightness after gamma adjustment, but some workflows use samples proportional to light intensity. Add -linear only when your input is the intensity-linear variation of the format:
$ pamaltsat -linear -method spectrum -strength 1.4 /path/to/linear-input.ppm > /path/to/linear-output.ppm
$ file /path/to/linear-output.ppm
/path/to/linear-output.ppm: Netpbm image data, size 1920 x 1080, rawbits, pixmap
This flag tells pamaltsat how to interpret the samples. It does not convert an ordinary gamma-adjusted image into a linear one. Applying it merely because the option exists can make the result look wrong. If you do not know how the input was encoded, identify that at the stage which created the image before choosing this flag.
6. Protect the source and recover from a bad result
pamaltsat reads the input and writes a new image; it does not edit the source file in place. The risky operation is the shell redirection. Use a temporary destination in the same directory, verify it, then move it into place only if replacement is intentional:
$ pamaltsat -strength 1.6 /path/to/input.ppm > /path/to/.input.ppm.new
$ file /path/to/.input.ppm.new
/path/to/.input.ppm.new: Netpbm image data, size 1920 x 1080, rawbits, pixmap
$ mv -- /path/to/.input.ppm.new /path/to/processed.ppm
The final mv changes directory state and can replace an existing file if the destination is already present. Pause before it, especially in a script. If conversion fails, remove the incomplete temporary file and keep the original. If you have already replaced a destination, recovery requires restoring your own backup or regenerating it from the unchanged source; pamaltsat has no undo command.
Do not use elevated privileges to solve a normal output error. Check the input path and permissions instead:
$ test -r /path/to/input.ppm && echo 'input is readable'
$ test -w /path/to && echo 'directory is writable'
If those checks fail, work in a directory you own or ask the administrator to provide access. Running the image transformation as root does not repair a malformed image and increases the consequences of a mistaken output path.
7. Avoid the common traps
- Wrong expectation from strength: values above one increase saturation, values below one decrease it, and zero produces Rec. 709 greyscale output. Unity is the neutral setting.
- Unexpected neutral pixels: the program preserves neutral grey pixels. Adjust colour balance first with a suitable tool such as
pamlevelsif the source is already neutral where you expected a change. - Clipping at high strength: the program limits results that would fall outside the valid sample range. Reduce the strength if highlights or strongly saturated regions do not retain the detail you expected.
- Wrong method assumption:
spectrumis the default. Use-method logwhen you specifically want the logarithmic model; do not infer the method from the output file name. - Binary output in the terminal: standard output is an image, not a status report. Always redirect it to a file unless another image program is deliberately reading the pipe.
Done means
pamaltsatis installed and its Netpbm version is known.-strengthis present, non-negative, and chosen for the intended change.- The method is explicit when
logis wanted; otherwise the defaultspectrummethod is understood. -linearis used only when the input samples are intensity-linear.- The new file has been checked as a non-empty Netpbm image before any replacement.
- The original input remains available, and any failed temporary conversion can be discarded without losing it.