{
    "mode": "man",
    "parameter": "pnmpsnr",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/man/pnmpsnr/json",
    "generated": "2026-10-06T04:51:13Z",
    "synopsis": "",
    "sections": {
        "NAME": {
            "content": "pnmpsnr - compute the difference between two images (the PSNR)\n\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "",
            "subsections": [
                {
                    "name": "pnmpsnr",
                    "content": "[pnmfile1]\n\n[pnmfile2]\n\n[-rgb] [-machine] [-max=n] [-target=n] [-target1=n] [-target2=n] [-target3=n]\n\nMinimum  unique  abbreviations of options are acceptable.  You may use double hyphens instead\nof single hyphen to denote options.  You may use white space in place of the equals  sign  to\nseparate an option name from its value.\n\n\n"
                }
            ]
        },
        "DESCRIPTION": {
            "content": "This program is part of Netpbm(1).\n\npnmpsnr  reads two PBM, PGM, or PPM files, or PAM equivalents, as input and computes the mag‐\nnitude of difference between the two images as a peak signal-to-noise ratio (PSNR) This  met‐\nric is typically used in image compression papers to rate the distortion between original and\ndecoded image.\n\npnmpsnr either prints these values or compares them to thresholds you specify.\n\n\nThe PSNR of a given component is the ratio of the maximum mean square difference of component\nvalues  that  could  exist between the two images (a measure of the information content in an\nimage) to the actual mean square difference for the two subject images.  It is expressed as a\ndecibel value.\n\nThe mean square difference of a component for two images is the mean square difference of the\ncomponent value, comparing each pixel with the pixel in the same position of the other image.\nFor the purposes of this computation, components are normalized to the scale [0..1].\n\nThe maximum mean square difference is identically 1.\n\nSo the higher the PSNR, the closer the images are.  A luminance PSNR of  20  means  the  mean\nsquare difference of the luminances of the pixels is 100 times less than the maximum possible\ndifference, i.e. 0.01.\n\nNote  that the word \"peak\" is a misnomer; there is no maximum involved; the metric is a mean.\nBut \"peak signal to noise ratio\" is for some reason the common term for this measurement.\n\nIf the inputs are PBM or PGM, pnmpsnr computes the PSNR of the luminance only.  Otherwise, it\ncomputes three separate PSNRs: either the luminance, and chrominance (Cb and  Cr)  components\nof the colors or the red, green, and blue components.\n\nBy default, the program prints the PSNRs to Standard Output in human-friendly form.\n\nWith the -machine option, the program prints the PSNRs, but in machine-friendly form.\n\nWith  a -target[x] option, the program just prints 'match' or 'nomatch', depending on whether\nthe PSNRs exceed targets you specify.\n\n\npnmpsnr reports the PSNR either in human-friendly form or in machine-friendly form (see  -ma‐\nchine).\n\n\n",
            "subsections": []
        },
        "OPTIONS": {
            "content": "In  addition  to  the options common to all programs based on libnetpbm (most notably -quiet,\nsee  Common Options ), pnmpsnr recognizes the following command line options:\n\n\n",
            "subsections": [
                {
                    "name": "-rgb",
                    "content": "rather than the luminance and chrominance components.  It has no effect on a  monotone\nimage.\n\nThis option was new in Netpbm 10.71 (June 2015).\n\n"
                },
                {
                    "name": "-machine",
                    "content": "This  option  causes  pnmpsnr to report the PSNRs in machine-friendly form, so another\nprogram can easily use the information.\n\nThe output is a single line.  It contains one floating point decimal number  for  each\ncolor  component, with a single space between every two.  (This means there are either\n1 or 3 numbers).  For the YCbCr color space (no -rgb), they are in the  order  Y,  Cb,\nCr.  For the RGB color space (-rgb), they are in R, G, B order.  For a monotone image,\nthere is one number.\n\nWhere  the  component does not differ between the images, so the PSNR is infinite, the\nnumber is inf\n\nBut note that the number displayed is also modified by the effect of -max.  In partic‐\nular, with -max, you will never see inf.\n\nThis option has no effect when you also specify -target[n].\n\nThis option was new in Netpbm 10.74 (March 2016).\n\n"
                },
                {
                    "name": "-max=_ -machine",
                    "content": "It specifies the maximum number pnmpsnr will print as a PSNR.  If the PSNR is  greater\nthan  n,  pnmpsnr  just  prints n.  n is a decimal floating point number.  An infinite\nPSNR is considered greater than any number.\n\nThis is mainly useful to deal with infinite PSNRs.  It is often much  more  convenient\nto have a program process only numbers than to make it deal with infinity, and often a\nvery large number has the same effect on a program as infinity.\n\nNote that the output is logarithmic, which means you will not see really large but fi‐\nnite  numbers.  If you specify -max=1000, the only way you will see 1000 in the output\nis if the PSNR is really infinite.  Two images with as many pixels as there are  elec‐\ntrons  in  the  universe, differing in only one pixel, and only in the smallest amount\nrepresentable in the Netpbm format, have a PSNR less than 1000.\n\nThis option was new in Netpbm 10.74 (March 2016).\n\n"
                },
                {
                    "name": "-target",
                    "content": "This option causes pnmpsnr to run in comparison mode - rather than print the PSNRs, it\njust tells you whether the PSNRs exceed n (a floating point number), i.e. whether  the\ncompared  images  are  the  same  within a given margin of error.  If all the computed\nPSNRs (luminance for a PBM or PGM; luminance and chrominance or red, green,  and  blue\nfor  PPM)  exceed  n,  the  program  prints 'match' to Standard Output.  Otherwise, it\nprints 'nomatch'.\n\nIf you also specify any of -target1, -target2, or -target3, and the images are  color,\npnmpsnr ignores -target.\n\nThis  is  mainly useful for use in a program.  If you're running pnmpsnr manually, you\ncould just run pnmpsnr without -target and compare the PSNRs to your targets yourself.\n\nThis option was new in Netpbm 10.82 (March 2018).\n\n"
                },
                {
                    "name": "-target",
                    "content": "Like -target, these options cause pnmpsnr to run in comparison mode.  But they provide\nseparate targets for the individual color component PSNRs.   -target1,  target-2,  and\n-target3 are for either the Y, Cb, and Cr components, respectively, or the red, green,\nand blue components, respectively, depending upon whether you specified -rgb.\n\nIf  you  don't  specify the corresponding -targetn option for a component, pnmpsnr ig‐\nnores the PSNR of that component in deciding whether the images match.\n\nIf the image is a PBM or PGM, these options have no effect, except that it stilll  se‐\nlects  comparison  mode, so if you don't also specify -target, and the image is PBM or\nPGM, the program fails.\n\nNote that the options are defined so that you could code a pnmpsnr command in  a  pro‐\ngram  that works on both color and monotone images, specifying individual PSNR targets\nfor use on the color images and the single target for use on the monotone images.\n\nThese options were new in Netpbm 10.82 (March 2018).\n\n\n\n\n"
                }
            ]
        },
        "SEE ALSO": {
            "content": "pnm(1)\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/pnmpsnr.html\n\nnetpbm documentation                       06 January 2018                    Pnmpsnr User Manual(1)",
            "subsections": []
        }
    },
    "summary": "pnmpsnr - compute the difference between two images (the PSNR)",
    "flags": [
        {
            "flag": "",
            "long": null,
            "arg": null,
            "description": "rather than the luminance and chrominance components. It has no effect on a monotone image. This option was new in Netpbm 10.71 (June 2015)."
        },
        {
            "flag": "",
            "long": null,
            "arg": null,
            "description": "This option causes pnmpsnr to report the PSNRs in machine-friendly form, so another program can easily use the information. The output is a single line. It contains one floating point decimal number for each color component, with a single space between every two. (This means there are either 1 or 3 numbers). For the YCbCr color space (no -rgb), they are in the order Y, Cb, Cr. For the RGB color space (-rgb), they are in R, G, B order. For a monotone image, there is one number. Where the component does not differ between the images, so the PSNR is infinite, the number is inf But note that the number displayed is also modified by the effect of -max. In partic‐ ular, with -max, you will never see inf. This option has no effect when you also specify -target[n]. This option was new in Netpbm 10.74 (March 2016)."
        },
        {
            "flag": "",
            "long": null,
            "arg": null,
            "description": "It specifies the maximum number pnmpsnr will print as a PSNR. If the PSNR is greater than n, pnmpsnr just prints n. n is a decimal floating point number. An infinite PSNR is considered greater than any number. This is mainly useful to deal with infinite PSNRs. It is often much more convenient to have a program process only numbers than to make it deal with infinity, and often a very large number has the same effect on a program as infinity. Note that the output is logarithmic, which means you will not see really large but fi‐ nite numbers. If you specify -max=1000, the only way you will see 1000 in the output is if the PSNR is really infinite. Two images with as many pixels as there are elec‐ trons in the universe, differing in only one pixel, and only in the smallest amount representable in the Netpbm format, have a PSNR less than 1000. This option was new in Netpbm 10.74 (March 2016)."
        },
        {
            "flag": "",
            "long": null,
            "arg": null,
            "description": "This option causes pnmpsnr to run in comparison mode - rather than print the PSNRs, it just tells you whether the PSNRs exceed n (a floating point number), i.e. whether the compared images are the same within a given margin of error. If all the computed PSNRs (luminance for a PBM or PGM; luminance and chrominance or red, green, and blue for PPM) exceed n, the program prints 'match' to Standard Output. Otherwise, it prints 'nomatch'. If you also specify any of -target1, -target2, or -target3, and the images are color, pnmpsnr ignores -target. This is mainly useful for use in a program. If you're running pnmpsnr manually, you could just run pnmpsnr without -target and compare the PSNRs to your targets yourself. This option was new in Netpbm 10.82 (March 2018)."
        },
        {
            "flag": "",
            "long": null,
            "arg": null,
            "description": "Like -target, these options cause pnmpsnr to run in comparison mode. But they provide separate targets for the individual color component PSNRs. -target1, target-2, and -target3 are for either the Y, Cb, and Cr components, respectively, or the red, green, and blue components, respectively, depending upon whether you specified -rgb. If you don't specify the corresponding -targetn option for a component, pnmpsnr ig‐ nores the PSNR of that component in deciding whether the images match. If the image is a PBM or PGM, these options have no effect, except that it stilll se‐ lects comparison mode, so if you don't also specify -target, and the image is PBM or PGM, the program fails. Note that the options are defined so that you could code a pnmpsnr command in a pro‐ gram that works on both color and monotone images, specifying individual PSNR targets for use on the color images and the single target for use on the monotone images. These options were new in Netpbm 10.82 (March 2018)."
        }
    ],
    "examples": [],
    "see_also": [
        {
            "name": "pnm",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/pnm/1/json"
        }
    ],
    "tldr": {
        "source": "official",
        "description": "Compute the difference between two images.",
        "examples": [
            {
                "description": "Compute the difference, i.e. the peak signal-to-noise ratio (PSNR) between two images",
                "command": "pnmpsnr {{path/to/file1.pnm}} {{path/to/file2.pnm}}"
            },
            {
                "description": "Compare the color components rather than the luminance and chrominance components of the images",
                "command": "pnmpsnr {{path/to/file1.pnm}} {{path/to/file2.pnm}} -rgb"
            },
            {
                "description": "Run in comparison mode, i.e. only output `nomatch` or `match` depending on whether the computing PSNR exceeds `n` or not",
                "command": "pnmpsnr {{path/to/file1.pnm}} {{path/to/file2.pnm}} -target {{n}}"
            },
            {
                "description": "Run in comparison mode and compare the individual image components, i.e. Y, Cb, and Cr, to the corresponding thresholds",
                "command": "pnmpsnr {{path/to/file1.pnm}} {{path/to/file2.pnm}} -target1 {{threshold_Y}} -target2 {{threshold_Cb}} -target3 {{threshold_Cr}}"
            },
            {
                "description": "Run in comparison mode and compare the individual image components, i.e. red, green, and blue to the corresponding thresholds",
                "command": "pnmpsnr {{path/to/file1.pnm}} {{path/to/file2.pnm}} -rgb -target1 {{threshold_red}} -target2 {{threshold_green}} -target3 {{threshold_blue}}"
            },
            {
                "description": "Produce machine-readable output",
                "command": "pnmpsnr {{path/to/file1.pnm}} {{path/to/file2.pnm}} -machine"
            }
        ]
    }
}