Convert a Single-Image Stereogram to a Red/Cyan Anaglyph
You will turn a Netpbm single-image stereogram into a red/cyan anaglyph that can be viewed with red/cyan 3-D glasses. The examples use pamsistoaglyph from Netpbm 11.5.2, installed here as Debian package version 2:11.05.02-1.1build1. Allow about ten minutes if the input image is already in a Netpbm format.
The route
Jump straight to the step you need, or tick off Done means at the end.
You need a readable stereogram in a Netpbm format such as PGM, PPM or PAM, the netpbm tools, and red/cyan glasses. This guide only reads the input and writes a new output file. It does not need elevated privileges. Do not overwrite the original image while experimenting with separation values.
1. Confirm the tool and inspect the input
Check that the command is installed, then ask pamfile what it is reading. Replace stereogram.pam with the path to your own file:
$ command -v pamsistoaglyph
/usr/bin/pamsistoaglyph
$ dpkg-query -W -f='${Package} ${Version}\n' netpbm
netpbm 2:11.05.02-1.1build1
$ pamfile stereogram.pam
The last command should identify a Netpbm image and show its dimensions. Exact wording depends on the format and the installed pamfile. If it reports an unsupported or corrupt input, fix that first. The converter cannot recover an image that the Netpbm reader cannot parse.
Checkpoint: record the width and height. The automatic minimum separation is 10 per cent of the image width, and the output is narrower than the input because the two eye views must overlap.
2. Create the anaglyph with automatic separation
Let the program estimate the distance between repeated views and write the result to a new file:
$ pamsistoaglyph stereogram.pam > stereogram-anaglyph.pam
pamsistoaglyph: Separation between left/right views = 42 pixels
The diagnostic is normally printed to standard error, so it remains visible while the image data is redirected to stereogram-anaglyph.pam. The number will depend on the pattern. The program searches for repeated horizontal patterns and chooses a likely eye separation; it is not a conversion of a normal photograph into stereo.
Verify the new file before opening it:
$ pamfile stereogram-anaglyph.pam
stereogram-anaglyph.pam: PAM, 598 by 400 by 3 maxval 63
Tuple type: RGB
Your dimensions and maximum value will differ. On this installed build, a small smoke-test input produced RGB PAM output with a maximum value of 63. Treat the file type and successful exit status as the useful checks, not those particular numbers.
3. View the result and correct reversed depth
Open stereogram-anaglyph.pam in an image viewer that supports PAM, or convert it with another installed Netpbm tool if your viewer does not. Put on red/cyan glasses and check whether the subject appears to have the intended depth.
pamsistoaglyph assumes that the input is a wall-eyed stereogram. If the scene appears to recede where it should project towards you, repeat the conversion with --invert:
$ pamsistoaglyph --invert stereogram.pam > stereogram-anaglyph-inverted.pam
pamsistoaglyph: Separation between left/right views = 42 pixels
$ pamfile stereogram-anaglyph-inverted.pam
Compare the two output files through the glasses. This is a reversible file-generation choice: delete neither file until you have selected the version that looks correct. If you do need to remove a test output, check its exact name first and remove only that generated file, never the source stereogram.
4. Supply a separation when automatic detection is wrong
Automatic detection can be confused by a low-quality or unusually coloured pattern. If the repeated background spacing is known, provide it in pixels with --sep:
$ pamsistoaglyph --sep=42 stereogram.pam > stereogram-sep42.pam
pamsistoaglyph: Separation between left/right views = 42 pixels
The value is the distance between the left and right views, not the width of the image and not a percentage. Use a value that is plausible for the actual repeating pattern. The option accepts either an equals sign or whitespace, so --sep 42 is equivalent. The long option names are safest in scripts, although the installed manual allows unique abbreviations.
If you only know a lower bound, use --minsep instead:
$ pamsistoaglyph --minsep=42 stereogram.pam > stereogram-minsep42.pam
This does not force a 42-pixel separation. It tells the detector to accept only a larger separation. With no option, the minimum is 10 per cent of the input width, rounded according to the program's image calculations.
5. Reduce colour noise during detection
For a JPEG-derived or subtly varied pattern, limit the grey levels used while looking for repeated pixels:
$ pamsistoaglyph --gray=16 stereogram.pam > stereogram-gray16.pam
pamsistoaglyph: Separation between left/right views = 42 pixels
--gray affects the search for separation. It does not mean that the final output is a greyscale image; the output remains an RGB anaglyph. The documented default is 63 grey levels. Start with the default, then try a lower value when small colour variations are causing a visibly implausible separation. Combining options is allowed:
$ pamsistoaglyph --gray=16 --minsep=42 --invert stereogram.pam > stereogram-adjusted.pam
If the command exits non-zero or prints an error saying that it cannot find a separation, inspect the source dimensions and pattern first. Lowering the threshold repeatedly is not a substitute for a valid stereogram. Try a known --sep only when you can justify its pixel value.
Done means
pamsistoaglyphis installed and its Netpbm package version is known.- The source passed
pamfilebefore conversion. - A new PAM RGB file was created and verified without overwriting the source.
- You checked the apparent depth through red/cyan glasses.
--invert,--sep,--minsepand--grayare used only for the specific failure they address.