Create a mask of the background in a PAM image. See also: pbmmask. More information: https://netpbm.sourceforge.net/doc/pambackground.html.
pbmmask
pambackground path/to/image.pam > path/to/output.pam