Help/info for PGM file viewer

PGM File Viewer reads a PGM file (binary P5 or ASCII P2) and interprets its content as raw photographic image file. PGM files can be easily produced from raw files by dcraw.

Creating a PGM file

The following invocation of dcraw will produce a binary PGM file with unaltered pixel values from a raw file:

dcraw -D -4 -t0 rawfilename

For most camera types, dcraw does some cropping, eg., to remove unexposed borders. Alternatives to dcraw may exist for your camera to create a PGM file containing the full, uncropped sensor image. For example, for Canon raw files, see Johann Briffa's scripts for running the Stanford PVRG JPEG software.

Description of the windows, and navigation

The 'RGB rendering' window shows a RGB rendering of the raw image. The other two image windows show pixel-level views of the portion of the RGB image enclosed by the (usually tiny) yellow box. You can move the yellow box using a mouse, or by using the keyboard (arrow keys, page up/down, and home/end). The coordinates of the top-left and bottom-right pixels in the pixel-level windows are given in their title bars.

Pixel values are displayed in hexidecimal. For 16-bit values, the four hexidecimal digits are displayed split into a stack of two 8-bit hex values, eg., 0x1234 is displayed as 12 over 34.

Layout

The program will automatically lay out the windows when it starts. All the windows can be dragged and resized. To preserve a layout, press 'save', which will store the information in your browser's local storage. If the browser finds a previously-saved layout, it will show a 'Load' button; pressing that Load button will load the previously-save layout.

Construction of the RGB window image

A PGM file contains a two-dimensional array of values, displayed by PGM File Viewer as hexadecimal values. PGM File Viewer interprets the array as if it is a raw image produced by a camera. Information about the camera's colour filter pattern is not stored in the PGM file, so to create an RGB image a colour filter array of RG/GB or GR/BG is assumed (if it is not one of these, the colour shading of the resulting RGB image will be incorrect; however, the values displayed in each pixel will be accurate).

The RGB image is created from the raw sensor pixel array using a rudimentary demosaicing algorithm (as used by LoCA Focus Analyser), as follows: For each 2 x 2 square of RG/GB pixels, a 2 x 2 square of RGB pixels is created by assigning the single red and blue pixel values to all four RGB pixels; the upper two RGB green values are sourced from the upper green sensor, and the lower green RGB values come from the lower green sensor. Finally, the RGB pixel is gamma-corrected, which makes darker values lighter. No colour space conversion is done. If there is an odd number of pixels in a row or column, the RGB rendering will be off on the last row/column (but the sensor values will be displayed correctly).

Photographic raw file processors would normally use more sophisticated demosaicing algorithms (eg., using interpolation algorithms to build RGB values at every pixel location), colour conversion (to change from raw RGB to the target space, eg., sRGB), white balancing, and gamma correction.

File information

The 'Control & information' window shows information about an image after it loads.

'Active bits' refers to the number of bits in use across all sensor values in the file. Generally it will match the maximum number of bits used by the sensor, but may be less if the image is dark. The observed bit pattern is reported in hexadecimal format.

Histogram

PGM File Viewer doesn't display an image histogram; a histogram can be generated by loading the PGM file into the Focus Analyser web page.

Comments or suggestions