pgmslice
Extract sub-images from a portable graymap image
TLDR
View documentation for the current command
SYNOPSIS
pgmslice [-N] [-M] [pgmfile]
Where:
-N: Specifies the number of horizontal slices (rows).
-M: Specifies the number of vertical slices (columns).
pgmfile: The input PGM file. If omitted, reads from standard input.
PARAMETERS
-N
Specifies the number of horizontal slices (rows) to divide the image into. This determines how many rows of subimages will be created.
-M
Specifies the number of vertical slices (columns) to divide the image into. This determines how many columns of subimages will be created.
pgmfile
The path to the input Portable Graymap (PGM) image file. If this argument is omitted, pgmslice will read its input from standard input (stdin).
DESCRIPTION
pgmslice is a versatile utility provided as part of the extensive NetPBM toolkit, specialized in the manipulation of Portable Graymap (PGM) images. Its primary function is to systematically slice a single input PGM image into an array of smaller, equally sized PGM subimages. The user defines the grid by specifying the number of horizontal slices (rows) and the number of vertical slices (columns) into which the original image should be divided.
Upon execution, pgmslice reads the PGM image, either from a specified file or from standard input, and then computes the dimensions for each resulting subimage. It outputs all generated subimages sequentially, concatenated together, to standard output. This output structure typically requires piping to other NetPBM utilities or redirection to separate files if individual access to each slice is required. This command is invaluable for tasks such as preparing image tiles for web display, segmenting medical scans, or dissecting satellite imagery for detailed analysis, providing a programmatic way to deconstruct larger graymap visuals into their constituent parts.
CAVEATS
pgmslice exclusively operates on Portable Graymap (PGM) images. It does not support other image formats directly.
The command outputs all generated slices concatenated to standard output. This means that to obtain individual image files, the output must typically be piped to another NetPBM utility like pamstack -force and then processed, or redirected carefully to separate files using shell scripting.
If the original image's dimensions are not perfectly divisible by the specified number of rows (-N) and columns (-M), the last slices in each row or column will have smaller dimensions than the preceding ones, as pgmslice maintains the starting coordinates but truncates the size.
HISTORY
pgmslice is an integral part of the NetPBM package, a long-standing and widely used collection of graphics manipulation programs. NetPBM itself evolved from Jef Poskanzer's PBMplus toolkit, first released in 1988. Over the decades, NetPBM has been continuously maintained and expanded by various contributors, becoming a robust and essential utility suite for Unix-like systems. pgmslice fits into this ecosystem as a specialized tool for PGM image segmentation, demonstrating the modular design philosophy of NetPBM, where each command performs a specific image processing task. Its development is tied to the overall evolution and maintenance of the NetPBM project, focusing on command-line efficiency and interoperability with other tools.