MODULE PZBoundary EXPORTS Main; (* Extracts a fragment contour from a ".pgm" image, writes it as a PZLR3Chain.T. *) (* Last edited on 1999-08-22 01:41:20 by hcgl *) IMPORT ParseParams, Process, FileWr, Wr, Fmt; IMPORT OSError, Thread, Stdio, TextWr; IMPORT PZImage, PZLR3Chain; FROM PZImage IMPORT Side; FROM Stdio IMPORT stderr; FROM PZTypes IMPORT NAT; <* FATAL Wr.Failure, Thread.Alerted, OSError.E *> TYPE Options = RECORD inFile: TEXT; (* Input image name, without ".pgm" *) black: NAT; (* Maximum black level *) grey: NAT; (* grey level *) side: Side; (* Which contour to write *) outFile: TEXT (* Output float chain name, without ".flc" *) END; PROCEDURE Main() = VAR aFC : REF PZLR3Chain.T; aImage : REF PZImage.T; BEGIN WITH o = GetOptions(), cc = PZBoundaryComments(o) DO Wr.PutText(stderr,"reading input file..."); aImage := PZImage.ReadPGM(o.inFile); Wr.PutText(stderr, Fmt.Int(NUMBER(aImage^)) & "x" & Fmt.Int(NUMBER(aImage[0])) & "\n"); aFC := PZImage.ExtractBoundary(aImage^, o.black, o.grey, o.side); PZLR3Chain.Write(FileWr.Open(o.outFile & ".flc"), cc, aFC^, 0.01d0) END END Main; PROCEDURE GetOptions(): Options = VAR o: Options; BEGIN WITH pp = NEW(ParseParams.T).init(stderr) DO TRY pp.getKeyword("-inFile"); o.inFile := pp.getNext(); pp.getKeyword("-black"); o.black := pp.getNextInt(0, 254); pp.getKeyword("-grey"); o.grey := pp.getNextInt(0, 255); pp.getKeyword("-outFile"); o.outFile := pp.getNext(); IF pp.keywordPresent("-inside") THEN o.side := Side.Inner ELSIF pp.keywordPresent("-outside") THEN o.side := Side.Outer ELSE o.side := Side.Interpolated END; pp.finish(); EXCEPT | ParseParams.Error => Wr.PutText(stderr, "Usage: PZBoundary \\\n"); Wr.PutText(stderr, " -inFile \\\n"); Wr.PutText(stderr, " -black \\\n"); Wr.PutText(stderr, " -grey \\\n"); Wr.PutText(stderr, " -outFile \\\n"); Wr.PutText(stderr, " [ -inside | -outside ] \n"); Process.Exit(1); END; END; RETURN o END GetOptions; PROCEDURE PZBoundaryComments(READONLY o: Options):TEXT= BEGIN WITH wr = NEW(TextWr.T).init() DO Wr.PutText( wr, "PZBoundary inFile: " & o.inFile & "\n"); Wr.PutText( wr, " black: " & Fmt.Int(o.black) & " grey: " & Fmt.Int(o.grey) & "\n"); RETURN(TextWr.ToText(wr)) END (* DO *); END PZBoundaryComments; BEGIN Main() END PZBoundary. (* Copyright © 2001 Universidade Estadual de Campinas (UNICAMP). Authors: Helena C. G. Leitão and Jorge Stolfi. This file can be freely distributed, used, and modified, provided that this copyright and authorship notice is preserved, and that any modified versions are clearly marked as such. This software has NO WARRANTY of correctness or applicability for any purpose. Neither the authors nor their employers chall be held responsible for any losses or damages that may result from its use. *)