#!/usr/bin/tclsh # usage: webgen.new img-dir [x y w h] # scott wehrwein # modified by Daniel to produce no more than 6 columns set codepath "/home/schar/public_html/colormatching" ######################### # HTML generation procs # ######################### proc Head {title} { return " $title

$title

" } proc StartOverviewTable { imagelist } { set result "" # show a thumbnail of each image foreach img $imagelist { set img [string range $img 0 end-4] append result " " } # a label for each image append result foreach img $imagelist { set img [string range $img 0 end-4] append result } return $result } proc StartOverviewRow { i imagelist } { # if {[expr $i == [expr [llength $imagelist] - 1]]} { return } set img [lindex $imagelist $i] set img [string range $img 0 end-4] set result " " #add empty td's for the lower half of the overview table for {set n 0} {$n <= $i} {incr n 1} { # append result } return $result } proc OverviewEntry { pre } { return " " } proc EndOverviewTable { } { return "
$img
$img
$img${pre}rgb_thumb
" } proc StartDetailsTable { } { return "" } proc DetailsEntry {im1 im2} { global dir return "" } proc EndDetailsTable { } { return "
$im1 vs
$im2
\[top\]
${im1} ${im2} rgb histogram
r histogram g histogram b histogram
" } proc Foot {} { return "
This page was generated [clock format [clock seconds]].
" } proc HtmlCompare { im1 im2 } { global noresid set html [open align/${im1}_${im2}.html w 0666] if (!$noresid) { set mdownup " function mdown() { document.getElementById('flashimg').src = '${im1}_${im2}_corrected_crop.png'; document.getElementById('label').innerHTML = '${im1} corrected'; } function mup() { over ? mover() : mout(); }" set bodyattributes " onmousedown = 'mdown()' onmouseup = 'mup()'" set instructions ", hold the left mouse button to switch to im1-corrected" set resid "
Residual:
residual
" } else { set mdownup "" set bodyattributes "" set instructions "" set resid "" } puts $html " ${im1} vs ${im2}

${im1} vs ${im2}

Mouse over to switch from im1 to im2$instructions
theimage
${im1}
$resid " close $html } ################ # main program # ################ # check for correct number of args if {$argc != 2} { if {$argc != 6} { puts "Usage: webgen img-dir twist \[x y w h\]" exit 1 } } # go to the provided directory cd [lindex $argv 0] set dir "hist/" set twist [lindex $argv 1] # get a list of the files in the directory set files [lsort [glob -nocomplain *.png]] # handle when a crop region is specified if {$argc == 6} { set x [lindex $argv 2] set y [lindex $argv 3] set w [lindex $argv 4] set h [lindex $argv 5] set dir crop_${x}_${y}_${w}_${h} # make a subdirectory for the cropped region's files exec mkdir -p $dir foreach file $files { # crop each image exec convert -crop ${w}x${h}+${x}+${y} +repage $file $dir/$file } # make a blink page # blink is gone. # exec /home/swehrwei/public_html/summer2008/blink $dir # call this script on the subdirectory exec $codepath/webgen $dir exit 0 } # find out whether the histogram generator will be computing corrected and residual set dim [exec identify -format "%w %h" [lindex $files 0]] set noresid 0 if {[lindex $dim 0] > 1200 && [lindex $dim 1] > 900} { set noresid 1 } # begin writing the two html tables into string variables set overview [StartOverviewTable $files] set details [StartDetailsTable] # make a directory for all the images we're about to generate # and one for all the html files exec mkdir -p $dir exec mkdir -p align # begin looping through all unique pairs of images for {set i 0} {$i < [llength $files]} {incr i 1} { # strip off the .png set fn1 [string range [lindex $files $i] 0 end-4] # create thumbnail of each image exec convert -thumbnail 128x128> [lindex $files $i] hist/${fn1}_thumb.jpg # create the images for the page that lets you check the alignment via mouseover exec convert -crop 800x600+0+0 +repage ${fn1}.png align/${fn1}_align.jpg # end the previous row, begin a new one, and output a label for the row append overview [StartOverviewRow $i $files] #for {set j [expr $i + 1]} {$j < [llength $files]} {incr j 1} set jend [llength $files] if {$jend > 6} { set jend 6 } for {set j 0} {$j < $jend} {incr j 1} { set fn2 [string range [lindex $files $j] 0 end-4] set pre [concat ${fn1}_${fn2}_] append overview [OverviewEntry $pre] # call the C++ histogram program on the current pair of images if {$twist} { if {$noresid} { if { [catch {exec $codepath/histogram ${fn1}.png ${fn2}.png \-fast 10 \-twist 1} msg] } { #puts $msg } } else { if { [catch {exec $codepath/histogram ${fn1}.png ${fn2}.png \-twist 1} msg] } { #puts $msg } } exec rm -f twisted.png } else { # no twist if {$noresid} { if { [catch {exec $codepath/histogram ${fn1}.png ${fn2}.png \-fast 10} msg] } { #puts $msg } } else { if { [catch {exec $codepath/histogram ${fn1}.png ${fn2}.png} msg] } { #puts $msg } } } # move and rename the images it produced #exec cjpeg r.pgm > ${dir}${pre}r.jpg #exec cjpeg g.pgm > ${dir}${pre}g.jpg #exec cjpeg b.pgm > ${dir}${pre}b.jpg exec convert r.pgm ${dir}${pre}r.jpg exec convert g.pgm ${dir}${pre}g.jpg exec convert b.pgm ${dir}${pre}b.jpg exec convert rgb.ppm ${dir}${pre}rgb.png exec rm -f r.pgm g.pgm b.pgm rgb.ppm if {!$noresid} { if {[catch { exec convert im1-corrected.ppm ${dir}${pre}corrected.png } msg] } { set noresid 1 } else { exec convert residual.ppm ${dir}${pre}residual.png exec rm -f residual.ppm im1-corrected.ppm } } # make a half-sized thumbnail of the rgb histogram exec convert -thumbnail 128x128 ${dir}${pre}rgb.png ${dir}thumb_${pre}rgb.jpg if {!$noresid} { # make an 800x600 version of the corrected and residual images for the align page exec convert -crop 800x600+0+0 +repage ${dir}${pre}corrected.png align/${pre}corrected_crop.png exec convert -crop 800x600+0+0 +repage ${dir}${pre}residual.png align/${pre}residual_crop.png } append details [DetailsEntry $fn1 $fn2] # generate the html alignment check page HtmlCompare $fn1 $fn2 } } append overview [EndOverviewTable] append details [EndDetailsTable] set pg [Head [pwd]]$overview$details[Foot] set outfile [open index.html w 0666] puts $outfile $pg close $outfile