#------------------------------------------------------------------------
#
# 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 DvmPnm
package require DvmVision

source ../lib/pnmlib.tcl

if {$argc < 2} {
    puts "Enter input PPM file name :"
    set inname [gets stdin]
    puts "Enter output PBM file name :"
    set outname [gets stdin]
} else {
    set inname [lindex $argv 0]
    set outname [lindex $argv 1]
}

set hdrbyte [read_pgm $inname]
set hdr [lindex $hdrbyte 0]
set byte [lindex $hdrbyte 1]
set w [pnm_hdr_get_width $hdr]
set h [pnm_hdr_get_height $hdr]

set edge [byte_new $w $h]
set bit1 [bit_new $w $h]
set smth [byte_new $w $h]

byte_smooth $byte $smth 2

byte_edge_detect_canny $smth $edge 5 10
bit_make_from_threshold_8 $edge $bit1 128 0
write_pbm_8 $hdr $bit1 $outname

byte_free $byte
byte_free $smth
byte_free $edge
bit_free $bit1