{
    "mode": "man",
    "parameter": "pgmhist",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/man/pgmhist/json",
    "generated": "2026-10-07T09:08:57Z",
    "synopsis": "",
    "sections": {
        "NAME": {
            "content": "pgmhist - print a histogram of the values in a PGM image\n\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "",
            "subsections": [
                {
                    "name": "pgmhist",
                    "content": "[-median, -quartile, -decile]\n\n[-forensic]\n\n[-machine]\n\n[pgmfile]\n\n"
                }
            ]
        },
        "DESCRIPTION": {
            "content": "This program is part of Netpbm(1).\n\npgmhist  reads  a  PGM image as input and prints a histogram of the gray values or other gray\nvalue distribution metrics.\n\nIf you specify none of -median, -quartile, or -decile, pgmhist prints  a  complete  histogram\nshowing how many pixels of each possible gray value exist in the image.  Along with each gray\nvalue,  it  tells you how many pixels are at lest as black as it and how many are at least as\nwhite.\n",
            "subsections": [
                {
                    "name": "-median -quartile -decile",
                    "content": "tiles.  Each quantile is a gray value that actually appears in the image (as opposed to frac‐\ntional  values  that  are  sometimes used for quantiles).  The 3rd quartile is the least gray\nvalue for which at least 75% of the pixels are as dark or darker than it.  The  4th  quartile\nis the brightest gray value that appears in the image.\n\n\n"
                }
            ]
        },
        "OPTIONS": {
            "content": "In  addition  to  the options common to all programs based on libnetpbm (most notably -quiet,\nsee  Common Options ), pgmhist recognizes the following command line options:\n\nYou may specify at most one of -median, -quartile, and -decile.  If none of these  is  speci‐\nfied pgmhist prints a histogram of gray values.\n\n\n",
            "subsections": [
                {
                    "name": "-median",
                    "content": "This option causes pgmhist to print the median gray value.\n\nThis option was new in Netpbm 10.61 (December 2012).\n\n"
                },
                {
                    "name": "-quartile",
                    "content": "This option causes pgmhist to print the four quartile gray values.\n\nThis option was new in Netpbm 10.61 (December 2012).\n\n"
                },
                {
                    "name": "-decile",
                    "content": "This option causes pgmhist to print the ten decile gray values.\n\nThis option was new in Netpbm 10.61 (December 2012).\n\n"
                },
                {
                    "name": "-forensic",
                    "content": "With this option, pgmhist works on images that contain invalid gray values.  Normally,\nlike  most  Netpbm  programs, pgmhist fails if it encounters a gray value greater than\nthe maxval that the image declares.  The presence of such a value means the  image  is\ninvalid,  so  the pixels have no meaning.  But with -forensic, pgmhist produces a his‐\ntogram of the actual gray values without regard to maxval.  It issues messages  summa‐\nrizing the invalid pixels if there are any.\n\nOne  use  for  this is to diagnose the problem that caused the invalid Netpbm image to\nexist.\n\nThere is a small exception to the ability of pgmhist to process  invalid  pixels  even\nwith  -forensic:  it  can never process a gray value greater than 65535.  Note that in\nthe rarely used Plain PGM format, it is possible for a number greater than that to ap‐\npear where a gray value belongs.\n\nThis option was new in Netpbm 10.66 (March 2014).  But Netpbm older  than  10.66  does\nnot properly reject invalid sample values, so the effect is very similar to -forensic.\n\n"
                },
                {
                    "name": "-machine",
                    "content": "This  option  causes  pgmhist to print the information in a way easily digestible by a\nmachine as opposed to a human.\n\nFor the quantiles, there is one line per quantile, in quantile order, and it  consists\nof the gray value of the quantile in decimal with no leading zeroes.\n\nFor  the  full  histogram  output,  it  consists  of  one line per possible gray value\n(whether that value appears in the image or not), in order of the  gray  values.   The\nline  consists  of  two tokens separated by a space.  The first is the gray value; the\nsecond is the number of pixels in the image that have that gray value.  Both are deci‐\nmal numbers without leading zeroes.\n\nThis option was new in Netpbm 10.61 (December 2012).\n\n\n\n\n"
                }
            ]
        },
        "SEE ALSO": {
            "content": "pnmnorm(1), ppmhist(1), pgm(1)\n\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Copyright (C) 1989 by Jef Poskanzer.\n",
            "subsections": []
        },
        "DOCUMENT SOURCE": {
            "content": "This manual page was generated by the Netpbm tool 'makeman' from  HTML  source.   The  master\ndocumentation is at\n\nhttp://netpbm.sourceforge.net/doc/pgmhist.html\n\nnetpbm documentation                      18 December 2021                    Pgmhist User Manual(1)",
            "subsections": []
        }
    },
    "summary": "pgmhist - print a histogram of the values in a PGM image",
    "flags": [
        {
            "flag": "",
            "long": null,
            "arg": null,
            "description": "This option causes pgmhist to print the median gray value. This option was new in Netpbm 10.61 (December 2012)."
        },
        {
            "flag": "",
            "long": null,
            "arg": null,
            "description": "This option causes pgmhist to print the four quartile gray values. This option was new in Netpbm 10.61 (December 2012)."
        },
        {
            "flag": "",
            "long": null,
            "arg": null,
            "description": "This option causes pgmhist to print the ten decile gray values. This option was new in Netpbm 10.61 (December 2012)."
        },
        {
            "flag": "",
            "long": null,
            "arg": null,
            "description": "With this option, pgmhist works on images that contain invalid gray values. Normally, like most Netpbm programs, pgmhist fails if it encounters a gray value greater than the maxval that the image declares. The presence of such a value means the image is invalid, so the pixels have no meaning. But with -forensic, pgmhist produces a his‐ togram of the actual gray values without regard to maxval. It issues messages summa‐ rizing the invalid pixels if there are any. One use for this is to diagnose the problem that caused the invalid Netpbm image to exist. There is a small exception to the ability of pgmhist to process invalid pixels even with -forensic: it can never process a gray value greater than 65535. Note that in the rarely used Plain PGM format, it is possible for a number greater than that to ap‐ pear where a gray value belongs. This option was new in Netpbm 10.66 (March 2014). But Netpbm older than 10.66 does not properly reject invalid sample values, so the effect is very similar to -forensic."
        },
        {
            "flag": "",
            "long": null,
            "arg": null,
            "description": "This option causes pgmhist to print the information in a way easily digestible by a machine as opposed to a human. For the quantiles, there is one line per quantile, in quantile order, and it consists of the gray value of the quantile in decimal with no leading zeroes. For the full histogram output, it consists of one line per possible gray value (whether that value appears in the image or not), in order of the gray values. The line consists of two tokens separated by a space. The first is the gray value; the second is the number of pixels in the image that have that gray value. Both are deci‐ mal numbers without leading zeroes. This option was new in Netpbm 10.61 (December 2012)."
        }
    ],
    "examples": [],
    "see_also": [
        {
            "name": "pnmnorm",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/pnmnorm/1/json"
        },
        {
            "name": "ppmhist",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/ppmhist/1/json"
        },
        {
            "name": "pgm",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/pgm/1/json"
        }
    ],
    "tldr": {
        "source": "official",
        "description": "Print a histogram of the values present in a PGM image.",
        "examples": [
            {
                "description": "Display the histogram for human reading",
                "command": "pgmhist {{path/to/image.pgm}}"
            },
            {
                "description": "Display the median grey value",
                "command": "pgmhist {{-me|-median}} {{path/to/image.pgm}}"
            },
            {
                "description": "Display the four quartile grey values",
                "command": "pgmhist {{-qua|-quartile}} {{path/to/image.pgm}}"
            },
            {
                "description": "Report the existence of invalid grey values",
                "command": "pgmhist {{-f|-forensic}} {{path/to/image.pgm}}"
            },
            {
                "description": "Display machine-readable output",
                "command": "pgmhist {{-ma|-machine}} {{path/to/image.pgm}}"
            }
        ]
    }
}