forked from ahay/src
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
637 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* Non-local smoothing. */ | ||
#include <rsf.h> | ||
|
||
int main (int argc, char *argv[]) | ||
{ | ||
int n1,n2, i1,i2, is, ns; | ||
float *trace, *trace2, ax, ay, t; | ||
sf_file inp, out; | ||
|
||
/* initialize */ | ||
sf_init(argc,argv); | ||
|
||
/* set input and output files */ | ||
inp = sf_input("in"); | ||
out = sf_output("out"); | ||
|
||
/* get input dimensions */ | ||
if (!sf_histint(inp,"n1",&n1)) | ||
sf_error("No n1= in input"); | ||
n2 = sf_leftsize(inp,1); | ||
|
||
/* get command-line parameters */ | ||
if (!sf_getint("ns",&ns)) sf_error("Need ns="); | ||
/* spray radius */ | ||
|
||
if (!sf_getfloat("ax",&ax)) sf_error("Need ax="); | ||
/* exponential weight for the coordinate distance */ | ||
|
||
trace = sf_floatalloc(n1); | ||
trace2 = sf_floatalloc(n1); | ||
|
||
/* loop over traces */ | ||
for (i2=0; i2 < n2; i2++) { | ||
/* read input */ | ||
sf_floatread(trace,n1,inp); | ||
|
||
/* loop over samples */ | ||
for (i1=0; i1 < n1; i1++) { | ||
t = 0.; | ||
|
||
/* accumulate shifts */ | ||
for (is=-ns; is <= ns; is++) { | ||
if (i1+is >= 0 && i1+is < n1) { | ||
|
||
/* !!!MODIFY THE NEXT LINE!!! */ | ||
t += trace[i1+is]*expf(-ax*is*is); | ||
} | ||
} | ||
|
||
trace2[i1] = t; | ||
} | ||
|
||
/* write output */ | ||
sf_floatwrite(trace2,n1,out); | ||
} | ||
|
||
/* clean up */ | ||
sf_fileclose(inp); | ||
exit (0); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from rsf.tex import * | ||
|
||
End(use='hyperref,listings',options='reproduce', | ||
color='horizon smoothed mona smoothed2', | ||
include=r''' | ||
\newlength{\boxwidth} | ||
\setlength{\boxwidth}{\textwidth} | ||
\addtolength{\boxwidth}{-50pt} | ||
\setlength{\fboxsep}{10pt} | ||
\newcommand{\answer}[1]{\noindent\fbox{\parbox{\boxwidth}{\textbf{Answer:} #1}}} | ||
''') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from rsf.proj import * | ||
|
||
# Download data | ||
Fetch('horizon.asc','hall') | ||
|
||
# Convert format | ||
Flow('horizon','horizon.asc', | ||
''' | ||
echo in=$SOURCE data_format=ascii_float n1=3 n2=57036 | | ||
dd form=native | window n1=1 f1=-1 | | ||
put | ||
n1=196 o1=33.139 d1=0.01 label1=y unit1=km | ||
n2=291 o2=35.031 d2=0.01 label2=x unit2=km | ||
''') | ||
|
||
# Triangle smoothing | ||
Flow('smoothed','horizon','smooth rect1=20 rect2=20') | ||
|
||
# Display results | ||
for horizon in ('horizon','smoothed'): | ||
# --- CHANGE BELOW --- | ||
Plot(horizon,'grey color=j bias=65 yreverse=n wanttitle=n') | ||
edge = 'edge-'+horizon | ||
Flow(edge,horizon,'canny max=98 | dd type=float') | ||
Plot(edge,'grey allpos=y yreverse=n wanttitle=n') | ||
Result(horizon,[horizon,edge],'SideBySideIso') | ||
|
||
End() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from rsf.proj import * | ||
|
||
# Download data | ||
Fetch('horizon.asc','hall') | ||
|
||
# Convert format | ||
Flow('horizon2','horizon.asc', | ||
''' | ||
echo in=$SOURCE data_format=ascii_float n1=3 n2=57036 | | ||
dd form=native | window n1=1 f1=-1 | | ||
add add=-65 | put | ||
n1=196 o1=33.139 d1=0.01 label1=y unit1=km | ||
n2=291 o2=35.031 d2=0.01 label2=x unit2=km | ||
''',stdin=0) | ||
Result('horizon2','grey yreverse=n color=j title=Input') | ||
|
||
# Spray | ||
Flow('spray','horizon2', | ||
''' | ||
spray axis=3 n=21 o=-0.1 d=0.01 | | ||
spray axis=4 n=21 o=-0.1 d=0.01 | ||
''') | ||
|
||
# Shift | ||
Flow('shift1','spray','window n1=1 | math output=x2') | ||
Flow('shift2','spray','window n2=1 | math output=x3') | ||
|
||
Flow('local','spray shift1 shift2', | ||
''' | ||
datstretch datum=${SOURCES[1]} | transp | | ||
datstretch datum=${SOURCES[2]} | transp | ||
''') | ||
Plot('local','window j3=4 j4=4 | grey color=j',view=1) | ||
|
||
# --- CHANGE BELOW --- | ||
# try "exp(-0.1*(input-loc)^2-200*(x3^2+x4^2))" | ||
Flow('simil','spray local', | ||
''' | ||
math loc=${SOURCES[1]} output=1 | ||
''') | ||
|
||
Flow('norm','simil', | ||
'stack axis=4 | stack axis=3') | ||
|
||
Flow('smoothed2','local simil norm', | ||
''' | ||
add mode=p ${SOURCES[1]} | | ||
stack axis=4 | stack axis=3 | | ||
add mode=d ${SOURCES[2]} | ||
''') | ||
Result('smoothed2','grey yreverse=n color=j title=Output') | ||
|
||
End() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from rsf.proj import * | ||
|
||
# Generate synthetic data | ||
Flow('step',None, | ||
''' | ||
spike nsp=3 n1=101 k1=26,51,76 mag=-1,2,-1 d1=1 label1= unit1= | | ||
causint | | ||
noise seed=62009 var=0.001 | ||
''') | ||
Result('step','dots') | ||
|
||
# Conventional smoothing | ||
Flow('smooth','step','smooth rect1=10') | ||
Result('smooth','dots') | ||
|
||
# Spray by repeating the input | ||
Flow('spray','step','spray axis=2 d=1 o=-10 n=21') | ||
Result('spray','dots') | ||
|
||
# Shift each trace | ||
Flow('shift','spray','window n1=1 | math output=x1') | ||
Flow('local','spray shift', | ||
'datstretch datum=${SOURCES[1]}') | ||
Result('local','dots') | ||
|
||
# Triangle weight | ||
# --- CHANGE BELOW --- | ||
Flow('triangle','local','math output="1-abs(x2)/10" ') | ||
Flow('tnorm','triangle','stack') | ||
Result('triangle','dots gaineach=n title="Triangle Weight" ') | ||
|
||
# Triangle smoothing by weighting and stacking | ||
Flow('smooth2','local triangle tnorm', | ||
''' | ||
add mode=p ${SOURCES[1]} | | ||
stack | | ||
add mode=d ${SOURCES[2]} | ||
''') | ||
Result('smooth2','dots title="Triangle Smoothing 2" title=') | ||
|
||
# Nonlocal weight | ||
Flow('similarity','spray local triangle', | ||
'''math loc=${SOURCES[1]} tri=${SOURCES[2]} | ||
output="tri*exp(-10*(input-loc)^2)"''') | ||
Result('similarity','dots gaineach=n title="Similarity Weight" ') | ||
|
||
# Multiply two weights together | ||
Flow('nlnorm','similarity','stack') | ||
Flow('nlsmooth','local similarity nlnorm', | ||
''' | ||
add mode=p ${SOURCES[1]} | | ||
stack | | ||
add mode=d ${SOURCES[2]} | ||
''') | ||
Result('nlsmooth','dots') | ||
|
||
End() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from rsf.proj import * | ||
|
||
# Download data | ||
Fetch('mona.img','imgs') | ||
|
||
# Convert to standard format | ||
Flow('mona','mona.img', | ||
''' | ||
echo n1=512 n2=513 in=$SOURCE data_format=native_uchar | | ||
dd type=float | ||
''',stdin=0) | ||
|
||
Result('mona', | ||
''' | ||
grey transp=n allpos=y title="Mona Lisa" | ||
color=b screenratio=1 wantaxis=n | ||
''') | ||
|
||
End() |
Oops, something went wrong.