TUgridNoise TCL UTILITIES USER MANUAL TUgridNoise
SYNOPSIS
Grid noise removal algorithms.
PACKAGE
TCLUTILS
NAME
TUgridNoise
USAGE
TUgridNoise  Algorithm Grid gInfo {V1} {V2} {V3}
INPUT DEFINITIONS
Algorithm - The algorithm to apply to the grid.
CUT - If the value of a grid cell is less than or equal to V1 then set it to V2.
UNIFORM - Subtract V1 from each grid cell. If the result is less than V2 then set it to V3.
DESPECKLE - Despeckle the grid. Data values above V2 are considered significant. Look at the 8 cells surrounding each cell in the grid. If less than or equal to V1 are significant then set the cell value to V3.
Grid - The input 2D data grid generated by a call to TUdataGrid.
gInfo - The grid information array for the input data grid.
V1 - Optional input the meaning of which depends on the Algorithm selected. Default value is 1.
V2 - Optional input the meaning of which depends on the Algorithm selected. Default value is 0.
V3 - Optional input the meaning of which depends on the Algorithm selected. Default value is 0.
RETURN DEFINITION
NONE
DESCRIPTION
TUgridNoise attempts to remove noise from a grid using one of its built in algorithms. The CUT algorithm sets any cells in the grid whose value is below the cutoff set in V1 to the value V2 which is generally 0. The UNIFORM algorithm is similar except that is uniformly subtracts the value V1 from all cells. An cells which this reduces below a value V2V3 which is again generally 0. DESPECKLE attempts to remove small isolated clusters of cells from the grid. With the exception of edge cells each cell in a grid is surrouned by 8 neighboring cells.
1 2 3
4 X 5
6 7 8
The despeckle algorithm determines the number of neighboring cells which have an associated value greater than V2. If that number is less than or equal to V1 then the cell value is set to V3. Note that the new cell value is not used in checks in which it is a neighboring cell.
It should be noted that in all of the algorithms it is possible to completely blank out a grid. Setting the cut or background subtraction level in either the CUT or UNIFORM algorithms to a value above the largest cell value in a grid will erase the entire grid as will setting either V1 to 8 or V2 to a value larger an the largest cell value when using the DESPECKLE algorithm.
ERRORS
None Generated
C BACKING
No
EXAMPLE(S)
EXAMPLE 1:Sequential application of the three noise reduction algorithms to a noisy gaussian.
# NOISE reduction example

# SET up the grid information array.  

set gInfo(0) -6.0
set gInfo(1) 6.0
set gInfo(2) -6.0
set gInfo(3) 6.0
set gInfo(4) 100
set gInfo(5) 100
set gInfo(6) POINT
set gInfo(7) POINT
set gInfo(8) COLUMN
set gInfo(9) IGNORE
set gInfo(10) NEW:ADD:END
set gInfo(11) -1
set gInfo(12) -5
set gInfo(13) -1.0e30
set gInfo(14)  1.0e30
set gInfo(15)  NO
set gInfo(16)  NO

# SET up a data set of a single Gaussian centered at (0, -0).

set nP 0
set nG [expr $gInfo(4) * $gInfo(5)]
for { set I 0 } { $I < $nG } { incr I } {
   TUgridInfo 20 gInfo rV $I
   set X($nP) $rV(2)
   set Y($nP) $rV(3)
   set R [expr $X($nP) * $X($nP) + $Y($nP) * $Y($nP)]
   set V($nP) [expr 4.0 * exp(-$R)]
   incr nP
}

# GRID the data set

TUdataGrid $nP 1 X X 1 Y Y V gV Norm gInfo

# SET up the plot basics.  There are a total of 5 plots defined here.

set GphInfo(xScrL) 500
set GphInfo(yScrL) 760
GraphicsOn TK ETones SWAP

GenWindow 1 0.0 0.0 0.0 1.0 1.0 0.0  0. 0. 0. 1. 1. 0. XY
set WinInfo(2,corFmt) 1
RelWindow 2 1 177.0 515.0 0. 377. 715. 0. -6. -6. 0. 6. 6. 0.
DefinePlot 2 2 $gInfo(4) $gInfo(5)
set WinInfo(4,corFmt) 1
RelWindow 4 1 75.0 290.0 0. 275. 490. 0. -6. -6. 0. 6. 6. 0.
DefinePlot 4 4 $gInfo(4) $gInfo(5)
set WinInfo(5,corFmt) 1
RelWindow 5 1 280.0 290.0 0. 480. 490. 0. -6. -6. 0. 6. 6. 0.
DefinePlot 5 5 $gInfo(4) $gInfo(5)
set WinInfo(6,corFmt) 1
RelWindow 6 1 75.0 65.0 0. 275. 265. 0. -6. -6. 0. 6. 6. 0.
DefinePlot 6 6 $gInfo(4) $gInfo(5)
set WinInfo(7,corFmt) 1
RelWindow 7 1 280.0 65.0 0. 480. 265. 0. -6. -6. 0. 6. 6. 0.
DefinePlot 7 7 $gInfo(4) $gInfo(5)

# SET up the color map to run from 0.0 to 4.0

PLTcolorMap 0.0 4.0 LINEAR 0 cA

# PLOT the gaussian

Plot3D 2 Xb Yb Dummy Dummy gV AUTO Dummy cA

# ADD some white noise to the grid and plot the gaussian with noise

for { set I 0 } { $I < $nG } { incr I } {
   set gV($I) [expr $gV($I) + [TUdataRnd1 TmP 1 P 0.5]]
}

Plot3D 4 Xb Yb Dummy Dummy gV AUTO Dummy cA

# REDUCE noise using a CUT of .2 and then plot the results

TUgridNoise CUT gV gInfo 0.2
Plot3D 5 Xb Yb Dummy Dummy gV AUTO Dummy cA

# REDUCE noise using a UNIFORM background subtraction of .3 on the already
#   noise reduced grid and then plot the results

TUgridNoise UNIFORM gV gInfo .3 
Plot3D 6 Xb Yb Dummy Dummy gV AUTO Dummy cA

# DESPECKLE the already noise reduced grid.  Any cell with two or less
#   neighbors is removed.

TUgridNoise DESPECKLE gV gInfo 2 .1
Plot3D 7 Xb Yb Dummy Dummy gV AUTO Dummy cA

# THROW up the axis.  Only annotate lower left-hand  plot

PlotOutlines 2 [list "" 1.0 "" 1.0] [list NONE NONE BOTH BOTH]
PlotOutlines 4 [list "" 1.0 "" 1.0] [list NONE NONE BOTH BOTH]
PlotOutlines 5 [list "" 1.0 "" 1.0] [list NONE NONE BOTH BOTH]
PlotOutlines 6 [list "X" 1.0 "Y" 1.0] [list BOT BOT BOTH BOTH]
PlotOutlines 7 [list "" 1.0 "" 1.0] [list NONE NONE BOTH BOTH]

# LABEL the plots 

TextProp 12 HOLD HOLD
WinClip 2 0
TexT 2 0.0 6.50 0.0 center "ORIGINAL" $GphInfo(White)
WinClip 4 0
TexT 4 0.0 6.50 0.0 center "NOISY" $GphInfo(White)
WinClip 5 0
TexT 5 0.0 6.50 0.0 center "CUT AT .2" $GphInfo(White)
WinClip 6 0
TexT 6 0.0 6.50 0.0 center "THEN UNIFORM AT .3" $GphInfo(White)
WinClip 7 0
TexT 7 0.0 6.50 0.0 center "LAST DESPECKLE" $GphInfo(White)

update
      
Sept 25, 2006