INCLUDE "H6:LOADPPM5.ACT" DEFINE HISTSIZE="256" PROC PutBigPixel(INT x,y BYTE col) IF x>=0 AND x<=79 AND y>=0 AND y<=47 THEN y==LSH 2 col==RSH 4 IF col<0 THEN col=0 ELSEIF col>15 THEN col=15 FI Color=col Plot(x,y) DrawTo(x,y+3) FI RETURN PROC DrawImage(GrayImage POINTER image INT x,y) INT i,j BYTE c FOR j=0 TO image.gh-1 DO FOR i=0 TO image.gw-1 DO c=GetGrayPixel(image,i,j) PutBigPixel(x+i,y+j,c) OD OD RETURN PROC CalcHistogram(GrayImage POINTER image INT ARRAY hist) INT i,j BYTE c Zero(hist,HISTSIZE*2) FOR j=0 TO image.gh-1 DO FOR i=0 TO image.gw-1 DO c=GetGrayPixel(image,i,j) hist(c)==+1 OD OD RETURN BYTE FUNC CalcThresholdValue(INT width,height INT ARRAY hist) INT i,sum,total,curr total=width*height sum=0 FOR i=0 TO HISTSIZE-1 DO curr=hist(i) IF sum>=(total-curr)/2 THEN RETURN (i) FI sum==+curr OD RETURN (HISTSIZE-1) PROC Binarize(GrayImage POINTER src,dst BYTE threshold) INT i,j BYTE c FOR j=0 TO src.gh-1 DO FOR i=0 TO src.gw-1 DO c=GetGrayPixel(src,i,j) IF c