#------------------------------------------------------------------------ # # Copyright (c) 1997-1998 by Cornell University. # # See the file "license.txt" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # #------------------------------------------------------------------------ package require DvmBasic package require DvmByteGeom package require DvmPnm source ../lib/pnmlib.tcl if {$argc != 2} { puts "enter input pgm filename :" set inname [gets stdin] puts "enter output pgm filename :" set outname [gets stdin] } else { set inname [lindex $argv 0] set outname [lindex $argv 1] } #puts [format "homo transform %s into %s" $inname $outname] # change the target dimension here # the image will be transformed to a trapezoid with # top = w2, bottom = w2-20, height = h2 # four points are respectively (0,0), (w2, 0), (w2-50, h2), (50,h2) set w2 [expr 200] set h2 [expr 100] set hdrbuf [read_pgm $inname] set hdr [lindex $hdrbuf 0] set buf [lindex $hdrbuf 1] set w [pnm_hdr_get_width $hdr] set h [pnm_hdr_get_height $hdr] set l [byte_homo_compute_matrix $w $h $w2 0 [expr $w2-50] $h2 50 $h2] set a [lindex $l 0] set b [lindex $l 1] set d [lindex $l 2] set e [lindex $l 3] set m [lindex $l 4] set n [lindex $l 5] set newbuf [byte_new $w2 $h2] byte_set $newbuf 0 byte_homo $buf $newbuf $a $b 0 $d $e 0 $m $n 1 pnm_hdr_set_width $hdr $w2 pnm_hdr_set_height $hdr $h2 write_pgm $hdr $newbuf $outname byte_free $newbuf byte_free $buf pnm_hdr_free $hdr