Variables | |
tuple | par = sf.Par() |
tuple | input = sf.Input() |
tuple | output1 = sf.Output(par.string("dx_outputfilename")) |
tuple | output2 = sf.Output(par.string("dy_outputfilename")) |
tuple | n1 = input.int("n1") |
tuple | n2 = input.int("n2") |
tuple | ni = input.size(2) |
tuple | inputimage = np.zeros((n1,n2),'f') |
tuple | input_padded = Sadiabatic(inputimage) |
tuple | I = array(range(1,n1+1)) |
tuple | J = array(range(1,n2+1)) |
tuple | Imx = (3*input_padded[I+1][:,J-1]+10*input_padded[I+1][:,J]+3*input_padded[I+1][:,J+1]-3*input_padded[I-1][:,J-1]-10*input_padded[I-1][:,J]-3*input_padded[I-1][:,J+1]) |
tuple | Imy = (3*input_padded[I-1][:,J+1]+10*input_padded[I][:,J+1]+3*input_padded[I+1][:,J+1]-3*input_padded[I-1][:,J-1]-10*input_padded[I][:,J-1]-3*input_padded[I+1][:,J-1]) |
import rsf as sf import numpy as np
from Sadiabatic import *
Get the RSF parameters for this function
par = sf.Par()
Get the name of the file for which we want to calculate the gradients from the RSF input. As well, output1 is the name of the RSF file to which we write the gradient values in the x direction, and output2 is the RSF filename for writing the gradient values in the y direction.
input = sf.Input() output1 = sf.Input(par.string("dx_outputfilename")) output2 = sf.Input(par.string("dy_outputfilename"))
n1 is the width of the image and n2 is the height of the image
n1 = input.int("n1") n2 = input.int("n2")
Make sure the input is 2-D. Otherwise, the gradients cannot be calculated with this code.
ni = input.size(2) assert ni == 1,"sfsmoothgradient needs 2D input"
Read in the input image
inputimage = np.zeros((n1,n2),'f')
input.read(inputimage)
Pad the input image with repetition so that gradients can be calculated on the boundaries.
input_padded = Sadiabatic(inputimage)
Used for indexing of image for computation of gradient
I = array(range(1,n1+1)) J = array(range(1,n2+1))
Calculate gradient in x direction
Imx = (3*input_padded[I+1][:,J-1]+10*input_padded[I+1][:,J]+3*input_padded[I+1][:,J+1]-3*input_padded[I-1][:,J-1]-10*input_padded[I-1][:,J]-3*input_padded[I-1][:,J+1])/32
Calculate gradient in y direction
Imy = (3*input_padded[I-1][:,J+1]+10*input_padded[I][:,J+1]+3*input_padded[I+1][:,J+1]-3*input_padded[I-1][:,J-1]-10*input_padded[I][:,J-1]-3*input_padded[I+1][:,J-1])/32
Write directional gradients (in x and y directions) to appropriate output files
output1.put("n1",n1) output1.put("n2",n2) output1.write(Imx) output2.put("n1",n1) output2.put("n2",n2) output2.write(Imy)
Definition at line 129 of file Msmoothgradient.py.
tuple Imx = (3*input_padded[I+1][:,J-1]+10*input_padded[I+1][:,J]+3*input_padded[I+1][:,J+1]-3*input_padded[I-1][:,J-1]-10*input_padded[I-1][:,J]-3*input_padded[I-1][:,J+1]) |
Definition at line 133 of file Msmoothgradient.py.
tuple Imy = (3*input_padded[I-1][:,J+1]+10*input_padded[I][:,J+1]+3*input_padded[I+1][:,J+1]-3*input_padded[I-1][:,J-1]-10*input_padded[I][:,J-1]-3*input_padded[I+1][:,J-1]) |
Definition at line 136 of file Msmoothgradient.py.
tuple input = sf.Input() |
Definition at line 112 of file Msmoothgradient.py.
tuple input_padded = Sadiabatic(inputimage) |
Definition at line 126 of file Msmoothgradient.py.
tuple inputimage = np.zeros((n1,n2),'f') |
Definition at line 124 of file Msmoothgradient.py.
Definition at line 130 of file Msmoothgradient.py.
tuple n1 = input.int("n1") |
Definition at line 119 of file Msmoothgradient.py.
tuple n2 = input.int("n2") |
Definition at line 120 of file Msmoothgradient.py.
tuple ni = input.size(2) |
Definition at line 121 of file Msmoothgradient.py.
tuple output1 = sf.Output(par.string("dx_outputfilename")) |
Definition at line 116 of file Msmoothgradient.py.
tuple output2 = sf.Output(par.string("dy_outputfilename")) |
Definition at line 117 of file Msmoothgradient.py.
tuple par = sf.Par() |
Definition at line 110 of file Msmoothgradient.py.