#!/usr/bin/pike /* * jpgscanclean.pike * * Utility to clean the background of scanned pages (req. RGB page) * * Author: Dario Rodriguez dario@softhome.net * The program is licensed under the terms of the MIT/X license. */ int bgthreshold=64; // from 0 to 255 int amplitude=15; // from 1 to 255 int main(int argc, array(string) argv) { Image.Image in,out,inhsv,indistance; string infile,outfile; if(argc!=3 || argv[argc-1]=="--help") { write("Syntax: "+argv[0]+" infile.jpg outfile.png\n"); return(1); } write(argv[1]+" -> "+argv[2]+"\n"); write("* Generating intermediate representations..."); infile=argv[1]; outfile=argv[2]; in=Image.load(infile); inhsv=in->copy()->rgb_to_hsv(); indistance=in->copy()->distancesq(255,255,255); out=Image.Image(in.xsize(),in.ysize()); // Guess the most used bg color write("done.\n* Guessing most used bg hue..."); array(int) hues=allocate(256); int x,y; int h,n,selh,seln,j; int c; for(y=0;yseln) { seln=n; selh=h; } } write(""+selh); // Clean image write(".\n* Cleaning image..."); int d; for(y=0;y