LinuxCommandLibrary

pamslice

Extract rectangular sub-images from Netpbm images

TLDR

Print the values of the pixels in the n'th row in a table

$ pamslice [[-r|-row]] [n] [path/to/image.pam]
copy

Print the values of the pixels in the n'th column in a table
$ pamslice [[-c|-column]] [n] [path/to/image.pam]
copy

Consider the m'th plane of the input image only
$ pamslice [[-r|-row]] [n] -plane [m] [path/to/image.pam]
copy

Produce output in a format suitable for input to an xmgr for visualisation
$ pamslice [[-r|-row]] [n] [[-x|-xmgr]] [path/to/image.pam]
copy

SYNOPSIS


pamslice [-rows=toprow:bottomrow] [-cols=leftcol:rightcol]
        [-rowoffset=offset] [-coloffset=offset]
        [-fillval=value] [-fillcolor=color]
        [-fillcolor-source=source] [-fillcolor-source-tupletype=tupletype]
        [-noautobackfill] [-background=color] [-noverbose]
        [--] [pamfile]

PARAMETERS

-rows=toprow:bottomrow
    Specifies the range of rows to extract from the input image. Rows are 0-indexed. If not specified, all rows are included.

-cols=leftcol:rightcol
    Specifies the range of columns to extract from the input image. Columns are 0-indexed. If not specified, all columns are included.

-rowoffset=offset
    Sets the rowoffset value in the output PAM header to offset. Defaults to the toprow value of the slice.

-coloffset=offset
    Sets the coloffset value in the output PAM header to offset. Defaults to the leftcol value of the slice.

-fillval=value
    Specifies a single channel value (0 to maxval) to fill areas of the output image that extend beyond the input image boundaries. Overrides -fillcolor.

-fillcolor=color
    Specifies a color (e.g., red, rgb(255,0,0)) to fill areas of the output image that extend beyond the input image boundaries. This is typically for multi-channel images.

-fillcolor-source=source
    Defines the color space for the color specified by -fillcolor. Examples include srgb or linear-rgb. Default is srgb.

-fillcolor-source-tupletype=tupletype
    Specifies the tuple type of the color specified by -fillcolor, if it differs from the input image's tuple type.

-noautobackfill
    Prevents pamslice from automatically filling expanded areas with black when no explicit fill color/value is given. Without this, black is the default background fill.

-background=color
    An obsolete synonym for -fillcolor. It is recommended to use -fillcolor instead.

-noverbose
    Suppresses any informational messages or warnings that pamslice might otherwise print to standard error.

pamfile
    The path to the input PAM image file. If omitted, pamslice reads the image data from standard input.

--
    Signals the end of options, allowing subsequent arguments that might start with a hyphen to be interpreted as filenames.

DESCRIPTION

pamslice is a utility from the Netpbm toolkit, designed to extract a specific rectangular portion (slice) from a Portable Arbitrary Map (PAM) image. It can read PAM images from standard input or a specified file and write the resulting slice to standard output. Beyond simple cropping, pamslice offers the unique ability to "expand" the slice beyond the original image boundaries. When the requested slice extends outside the source image, the tool can fill the expanded areas with a user-defined background color or value, allowing for the creation of larger canvases with specific background fills. This makes pamslice useful for tasks like preparing images for tiling, extracting sub-regions, or creating images with borders. It processes images channel by channel, respecting the original image's depth and tuple type.

CAVEATS

  • pamslice primarily works with PAM images. While Netpbm tools often handle implicit conversions from other formats, direct PAM input is preferred for consistency.
  • Row and column coordinates are 0-indexed.
  • When expanding the slice beyond the original image, ensure a fillval or fillcolor is specified, or be aware of the default black fill (if -noautobackfill is not used).
  • The maxval of the output image will match the maxval of the input image. Any specified fill values or colors should be within this range.

HISTORY

pamslice is a component of the Netpbm project, a long-standing and widely used toolkit for graphics manipulation. Netpbm originated from pbmplus in the late 1980s and has evolved considerably since then. pamslice itself was introduced as part of the expansion of Netpbm to include the Portable Arbitrary Map (PAM) format, which offers more flexibility than the older PBM, PGM, and PPM formats by supporting arbitrary tuple types and depths. Its development reflects the project's continuous effort to provide robust and versatile command-line tools for image processing, focusing on simplicity and interoperability within the Unix philosophy.

SEE ALSO

pamcut(1), pamscale(1), pamtopnm(1), pnm(5), pam(5)

Copied to clipboard