source pkgsNeeded.tcl

ui_init "t_proc.tcl"
SetFileTypes

PH "Image processing commands"

set sw [poImgUtil NewSwatch]

poImgUtil SetCompressionRGB $OFF $OFF $OFF

set img [poImage NewImageFromFile "testIn/keksi$fInfo(suf)"]
$img GetImageInfo w h a g

set imgsave [poImage NewImage $w $h $a $g]
$imgsave CopyImage $img

set msg "Original image"
ui_addimg $img $msg

set fname "testOut/procFlipHori$fInfo(suf)"
set msg   "$fname: Flipping horizontally"
P $msg
$img FlipHorizontal
$img WriteSimple $fname $fInfo(fmt) $fInfo(vsn)
ui_addimg $img $msg

set fname "testOut/procFlipVert$fInfo(suf)"
set msg  "$fname: Flipping vertically"
P $msg
$img CopyImage $imgsave
$img FlipVertical
$img WriteSimple $fname $fInfo(fmt) $fInfo(vsn)
ui_addimg $img $msg

set fname "testOut/procFlipDiag$fInfo(suf)"
set msg  "$fname: Flipping diagonal"
P $msg
$img CopyImage $imgsave
poImgUtil SetDrawColorRGB 0 1 0
$img DrawRect 0 $h $w $w
$img FlipDiagonal
$img WriteSimple $fname $fInfo(fmt) $fInfo(vsn)
ui_addimg $img $msg

set fname "testOut/procErode1$fInfo(suf)"
set msg   "$fname: Eroding by 1"
P $msg
$img CopyImage $imgsave
$img Erosion 1
$img WriteSimple $fname $fInfo(fmt) $fInfo(vsn)
ui_addimg $img $msg

set fname "testOut/procErode4$fInfo(suf)"
set msg   "$fname: Eroding by 4"
P $msg
$img CopyImage $imgsave
$img Erosion 4
$img WriteSimple $fname $fInfo(fmt) $fInfo(vsn)
ui_addimg $img $msg

set fname "testOut/procRemap$fInfo(suf)"
set msg   "$fname: Remapping color values for RED channel"
P $msg
$img CopyImage $imgsave
set remap [list 1.0 0.8 0.0]
$img RemapValues $RED $remap
$img WriteSimple $fname $fInfo(fmt) $fInfo(vsn)
ui_addimg $img $msg

set fname "testOut/procMedianIn$fInfo(suf)"
set msg   "$fname: setting yellow point at 100,100"
P $msg
$img CopyImage $imgsave
poImgUtil SetDrawColorRGB 1 1 0
$img DrawPixel 100 100
$img GetPixel 100 100 tmpcol
P "Pixel at 100, 100 set to yellow"
poImgUtil PrintChans $tmpcol Drawcolor
$img WriteSimple $fname $fInfo(fmt) $fInfo(vsn)
ui_addimg $img $msg

set fname "testOut/proMedianOut$fInfo(suf)"
set msg   "$fname: Median filtering"
P $msg
$img Median 
$img GetPixel 100 100 tmpcol
P "Pixel at 100, 100 after median filter"
poImgUtil PrintChans $tmpcol Drawcolor
$img WriteSimple $fname $fInfo(fmt) $fInfo(vsn)
ui_addimg $img $msg

set t 0.04
set fname "testOut/procThreshold$fInfo(suf)"
set msg "$fname: Thresholding with $t"
P $msg
$img CopyImage $imgsave
set imgthres [poImage NewImage $w $h $a $g]
$imgthres Blank
$imgthres Threshold $img $t
$imgthres WriteSimple $fname $fInfo(fmt) $fInfo(vsn)
ui_addimg $imgthres $msg

set t 0.4
set fname "testOut/procCutoff1$fInfo(suf)"
set msg "$fname: Cutoff with $t"
P $msg
set imgCutOff [poImage NewImage $w $h $a $g]
$imgCutOff CopyImage $imgsave
$imgCutOff CutOff $t
$imgCutOff WriteSimple $fname $fInfo(fmt) $fInfo(vsn)
ui_addimg $imgCutOff $msg

set t1 0.4
set t2 0.6
set fname "testOut/procCutoff2$fInfo(suf)"
set msg "$fname: Cutoff between $t1 and $t2"
P $msg
set imgCutOff2 [poImage NewImage $w $h $a $g]
$imgCutOff2 CopyImage $imgsave
$imgCutOff2 CutOff $t1 $t2
$imgCutOff2 WriteSimple $fname $fInfo(fmt) $fInfo(vsn)
ui_addimg $imgCutOff2 $msg

set fname "testOut/procBlur3$fInfo(suf)"
set msg   "$fname: Blur filtering by 3"
P $msg
$img CopyImage $imgsave
$img Blur 3
$img WriteSimple $fname $fInfo(fmt) $fInfo(vsn)
ui_addimg $img $msg

set fname "testOut/procBlur5$fInfo(suf)"
set msg   "$fname: Blur filtering by 5"
P $msg
$img CopyImage $imgsave
$img Blur 5
$img WriteSimple $fname $fInfo(fmt) $fInfo(vsn)
ui_addimg $img $msg

set fname "testOut/procDepthblur$fInfo(suf)"
set msg   "$fname: Depthblur filtering by 8"
P $msg
poImgUtil SetFormatChan $DEPTH $FLOAT
poImgUtil SetCompressionChan $DEPTH $OFF
set imgdepth [poImage NewImage $w $h $a $g]
$imgdepth CopyImage $imgsave
poImgUtil SetDrawMaskRGB $OFF $OFF $OFF
poImgUtil SetDrawMaskChan $DEPTH $ON
for { set y 0 } { $y < $h } { incr y } {
    poImgUtil SetDrawColorChan $DEPTH [expr double ($y) / double ($h)]
    $imgdepth DrawLine 0 $y $w $y
}
$imgdepth GetDepthRange dmin dmax
P "Depth range in image is from [PF $dmin] to [PF $dmax]"
poImgUtil SetDrawMaskRGB $ON $ON $ON
poImgUtil SetDrawMaskChan $DEPTH $OFF
$imgdepth DepthBlur 8 8
$imgdepth WriteImage $fname $fInfo(fmt) $fInfo(vsn)
ui_addimg $imgdepth $msg

set fname "testOut/procDepth$fInfo(suf)"
set msg   "$fname: Depth channel of previous image"
P $msg
ui_addimg $imgdepth $msg [list $DEPTH $DEPTH $DEPTH]

set fname "testOut/procShearVert$fInfo(suf)"
set msg   "$fname: Shearing vertically"
P $msg
set imgshear [poImage NewImage [expr ($w + 100)] [expr ($h + 100)] $a $g]
$imgshear GetImageInfo ws hs
poImgUtil SetDrawColorRGB 1 0 0
$imgshear DrawRect 0 0 $ws $hs
$imgshear CopyRect $imgsave 0 0 $w $h 50 50
poImgUtil SetDrawColorRGB 0 1 0
$imgshear ShearVertical 0.1 1
$imgshear WriteSimple $fname $fInfo(fmt) $fInfo(vsn)
ui_addimg $imgshear $msg
poImgUtil DeleteImg $imgshear

set fname "testOut/procShearHori$fInfo(suf)"
set msg   "$fname: Shearing horizontally"
P $msg
set imgshear [poImage NewImage [expr ($w + 100)] [expr ($h + 100)] $a $g]
$imgshear GetImageInfo ws hs
poImgUtil SetDrawColorRGB 1 0 0
$imgshear DrawRect 0 0 $ws $hs
$imgshear CopyRect $imgsave 0 0 $w $h 50 50
poImgUtil SetDrawColorRGB 0 1 0
$imgshear ShearHorizontal 0.1 1
$imgshear WriteSimple $fname $fInfo(fmt) $fInfo(vsn)
ui_addimg $imgshear $msg

set fname "testOut/procGamma$fInfo(suf)"
set msg   "$fname: Changing gamma to 2 for all channels"
P $msg
$img CopyImage $imgsave
$img ChangeGamma $RED   2.0
$img ChangeGamma $GREEN 2.0
$img ChangeGamma $BLUE  2.0
$img WriteSimple $fname $fInfo(fmt) $fInfo(vsn)
ui_addimg $img $msg

set fname "testOut/procScale$fInfo(suf)"
set msg "$fname: Change scale and offset of channel values"
P $msg
$img CopyImage $imgsave
$img ChangeGamma $RED 1.0 0.5
$img ChangeGamma $BLUE 1.0 1.0 0.3
$img WriteSimple $fname $fInfo(fmt) $fInfo(vsn)
ui_addimg $img $msg

set fname "testOut/procHvdiff$fInfo(suf)"
set msg   "$fname: Compute horizontal and vertical differences between pixels"
P $msg
set imghvdiff [poImage NewImage $w $h $a $g]
$imghvdiff Blank
poImgUtil SetDrawColorRGB 0 0 0.5
$imghvdiff DrawRect 0 0 $w $h
$img CopyImage $imgsave
$imghvdiff Derivates $img $RED $RED $GREEN false
$imghvdiff WriteSimple $fname $fInfo(fmt) $fInfo(vsn)
ui_addimg $imghvdiff $msg

set fname "testOut/procGray1$fInfo(suf)"
set msg "$fname: Generate grayscale image out of RED channel"
P $msg
$img CopyImage $imgsave
$img CopyChannel $img  $RED $GREEN
$img CopyChannel $img  $RED $BLUE
$img WriteSimple $fname $fInfo(fmt) $fInfo(vsn)
ui_addimg $img $msg

set fname "testOut/procGray2$fInfo(suf)"
set msg "$fname: Generate grayscale image out of sensitivity response"
P $msg
set imgadd [poImage NewImage $w $h $a $g]
$imgadd CopyImage $imgsave
$imgadd ChangeGamma $RED   1.0 0.30 0.0
$imgadd ChangeGamma $GREEN 1.0 0.59 0.0
$imgadd ChangeGamma $BLUE  1.0 0.11 0.0
$img Blank
poImgUtil SetDrawModeRGB $ADD $OFF $OFF
poImgUtil SetDrawMaskRGB $ON $OFF $OFF
$img CopyRect $imgadd 0 0 $w $h 0 0

$imgadd CopyChannel $imgadd $GREEN $RED
$img CopyRect $imgadd 0 0 $w $h 0 0

$imgadd CopyChannel $imgadd $BLUE $RED
$img CopyRect $imgadd 0 0 $w $h 0 0

$img CopyChannel $img $RED $GREEN
$img CopyChannel $img $RED $BLUE

$img WriteSimple $fname $fInfo(fmt) $fInfo(vsn)
ui_addimg $img $msg

PSec "Required time" [$sw lookup]

poImgUtil DeleteSwatch $sw
poImgUtil DeleteImg $img
poImgUtil DeleteImg $imgadd
poImgUtil DeleteImg $imgsave
poImgUtil DeleteImg $imghvdiff
poImgUtil DeleteImg $imgshear
poImgUtil DeleteImg $imgdepth
poImgUtil DeleteImg $imgthres
poImgUtil DeleteImg $imgCutOff
poImgUtil DeleteImg $imgCutOff2

PS
P "End of test"

ui_show

if { [lindex $argv 0] eq "auto" } {
    ui_exit
    exit 0
}
