\ .\" This man page was generated by the Netpbm tool 'makeman' from HTML source. .\" Do not hand-hack it! If you have bug fixes or improvements, please find .\" the corresponding HTML page on the Netpbm website, generate a patch .\" against that, and send it to the Netpbm maintainer. .TH "Pnmhisteq User Manual" 0 "22 March 2015" "netpbm documentation" .SH NAME pnmhisteq - histogram equalize a PNM image .UN synopsis .SH SYNOPSIS \fBpnmhisteq\fP [\fB-gray\fP] [\fB-noblack\fP] [\fB-nowhite\fP] [\fB-rmap\fP \fIpgmfile\fP] [\fB-wmap\fP \fIpgmfile\fP] [\fB-verbose\fP] [\fIpnmfile\fP] .UN description .SH DESCRIPTION .PP This program is part of .BR "Netpbm" (1)\c \&. .PP \fBpnmhisteq\fP increases the contrast of a PGM or PPM image through the technique of "histogram equalization."[1] .PP \fBpnmhisteq\fP computes a histogram of the luminosity of the pixels in the image. It then calculates a mapping between each luminosity and a new luminosity such that it spreads out intensity levels around histogram peaks and compresses them at troughs. I.e. it moves pixels around in the histogram so as to make it flat. It applies that mapping to the input image to produce the output image. The effect of this is that the image has equal numbers of pixels at each possible intensity level, which means it uses the available levels of intensity more efficiently and thereby has more visible detail. .PP Mathematically, the luminosity mapping is this: Assume the pixels are sorted by luminosity into \fIB\fP buckets numbered from 0 (lowest luminosity) to \fIB\fP-1. \fIN[i]\fP is the number of pixels in bucket \fIi\fP. \fIT\fP is the total number of pixels (sum of \fIN[i]\fP over all \fIi\fP). \fIW\fP is the luminosity of white. .PP \fBpnmhisteq\fP replaces an input pixel whose luminosity falls into bucket \fIj\fP with one whose luminosity is: .nf j --- \e > (N[i] / T) * W / --- i=0 .fi .PP Considering a grayscale image for simplicity, this means that pixels in the most luminous bucket become white. Pixels in the 10th per centile of luminosity become 10% of white. .PP \fBpnmhisteq\fP maps a single luminosity in the input to a single luminosity in the output. That means if pixels A and B both have luminosity \&.2 in the input, and pixel A has luminosity .4 in the output, pixel B also has luminosity .4 in the output. And since the luminosities in the input are not continuous, the luminosities in the output aren't either and \fBpnmhisteq\fP doesn't meet the ideal of having exactly the same number of pixels of each luminosity in the output. .PP If you're processing a related set of images, for example frames of an animation, it's generally best to apply the same luminosity mapping to every frame, since otherwise you'll get distracting frame-to-frame changes in the brightness of objects. \fBpnmhisteq\fP's \fB-wmap\fP option allows you to save, as a PGM image, the luminosity map it computes from an image. The \fB-rmap\fP option causes \fBpnmisteq\fP to use such an image as its luminosity map. .PP So you can run \fBpnmhisteq\fP with \fB-wmap\fP on a composite you created with \fBpnmcat\fP of the images you intend to process. Then, you can run \fBpnmisteq\fP with \fB-rmap\fP on each of the individual images, using the luminosity map you generated from the composite. .PP Use \fBpnmhistmap\fP to see the result. Run a color image through \fBppmtopgm\fP first so that you see a histogram of the luminosity instead of histograms of the three color components. It should generally show a flat histogram. But because of the quantization effects described above, you might see high bars interleaved with low bars, with the local average being flat. To see local averages, use the \fB-width\fP option of \fBpnmhistmap\fP. .UN options .SH OPTIONS .PP You can abbreviate any option to its shortest unique prefix. .TP \fB-gray\fP When processing a color image, only gray pixels (those with identical red, green, and blue values) are included in the histogram and modified in the output image. This is a special purpose option intended for images where the actual data are gray scale, with color annotations you don't want modified. Weather satellite images that show continent outlines in color are best processed using this option. The option has no effect when the input is a graymap. .TP \fB-noblack\fP Do not include black pixels in the equalization. The black pixels in the output are exactly the black pixels in the input and the number of black pixels does not affect the color of any other pixels. .sp Sometimes, black isn't as much a color as a background or annotation for the real colors, so you want to treat it specially this way. Think of a picture of stars, which is nearly all black, but with lots of stars of different brightness. You want to change the brightnesses of the stars to maximize contrast between them, but if you considered the blackness to be significant, all the stars would end up close to full white. .sp This option was new in Netpbm 10.70 (March 2015). .TP \fB-nowhite\fP .sp Same as \fB-noblack\fP, but for the white pixels. .sp This option was new in Netpbm 10.70 (March 2015). .TP \fB-rmap\fP \fImapfile\fP Process the image using the luminosity map specified by the PGM file \fImapfile\fP. The PGM image, usually created by an earlier run of \fBpnmhisteq\fP with the \fB-wmap\fP option, contains a single row with number of columns equal to the maxval (greatest intensity value) of the image plus one. Each pixel in the image is transformed by looking up its luminosity in the corresponding column in the map file (column number = luminosity) and changing it to the value given by that column. .TP \fB-wmap\fP \fImapfile\fP Creates a PGM file \fImapfile\fP, containing the luminosity map computed from the histogram of the input image. This map file can be read on subsequent runs of \fBpnmhisteq\fP with the \fB-rmap\fP option, allowing a group of images to be processed with an identical map. .TP \fB-verbose\fP Prints the histogram and luminosity map on Standard Error. .UN limitations .SH LIMITATIONS .PP Histogram equalization is effective for increasing the visible detail in scientific imagery and in some continuous-tone pictures. It is often too drastic, however, for scanned halftone images, where it does an excellent job of making halftone artifacts apparent. You might want to experiment with \fBpnmnorm\fP and \fBpnmgamma\fP for more subtle contrast enhancement. .PP The luminosity map file supplied by the \fB-rmap\fP option must have the same maxval as the input image. This is always the case when the map file was created by the \fB-wmap\fP option of \fBpnmhisteq\fP. If this restriction causes a problem, simply adjust the maxval of the map with \fBpamdepth\fP to agree with the input image. .PP If the input is a PBM file (on which histogram equalization is an identity operation), the only effect of passing the file through \fBpnmhisteq\fP will be the passage of time. .UN seealso .SH SEE ALSO .BR "pnmnorm" (1)\c \&, .BR "pnmcat" (1)\c \&, .BR "pamdepth" (1)\c \&, .BR "pnmgamma" (1)\c \&, .BR "pnm" (5)\c \&, .TP [1] Russ, John C. The Image Processing Handbook. Boca Raton: CRC Press, 1992. Pages 105-110. .SH DOCUMENT SOURCE This manual page was generated by the Netpbm tool 'makeman' from HTML source. The master documentation is at .IP .B http://netpbm.sourceforge.net/doc/pnmhisteq.html .PP