INTERFACE PZImage; (* Tools for image processing *) IMPORT PZLR3Chain; TYPE GrayLevel = BITS 8 FOR [0..255]; T = ARRAY OF ARRAY OF GrayLevel; PROCEDURE ReadPGM(fName: TEXT): REF T; (* Reads a PGM file "fName" and returns the image *) PROCEDURE WritePGM(fName :TEXT; READONLY M: T); (* Writes the image "M" as file "fName", in PGM format. *) TYPE Side = {Inner, Interpolated, Outer}; PROCEDURE ExtractBoundary( READONLY M: T; black: CARDINAL; grey: CARDINAL; side: Side := Side.Interpolated; ): REF PZLR3Chain.T; (* Given a PGM image "M" of a single 4-connected puzzle piece, returns the piece's outline as a 2D closed curve. Assumes that "M[y,x] <= black" if and only if pixel "(x,y)" is outside the piece. The result traces the level curve "M[x,y] = grey" with subpixel accurancy, except that it will not deviate more than two pixels from the "M[x,y] = black" curve. Also assumes that the piece does not touch the boundary of "M". The "side" parameter specifies which contour to return. The "Inner" and "outer" contours have integer vertices. *) END PZImage.