00001 """/*! \page Orientation Estimation 00002 @section Background 00003 The goal of this tutorial is to show how SLIMpy can be used in the 00004 process of estimating the image gradient orientations 00005 (direction of edges in an image) using the linear structure 00006 tensor so that the estimates are robust to added noise. 00007 00008 The structure tensor @b T of an image @b I is defined to be the outer product 00009 of the image gradient vector with itself: 00010 \f[ 00011 \textbf{T} = \left(\begin{array}{c}I_x \\I_y\end{array}\right) \left(\begin{array}{cc}I_x & I_y\end{array}\right)=\left(\begin{array}{cc}I_x^2 & I_xI_y\\I_xI_y&I_y^2\end{array}\right) 00012 \f] 00013 00014 Then this structure tensor is blurred with an averaging filter @b A to form 00015 the linear structure tensor @b L: 00016 \f[ 00017 \textbf{L} = A \ast T 00018 \f] 00019 00020 Finally, the robust-to-noise gradient direction can be computed by finding the eigenvector corresponding to 00021 the larger eigenvalue of the 2x2 matrix @b L. 00022 00023 This tutorial will do the above computation of the gradient direction using three SLIMpy linear operators - one that adds 00024 noise to the original image, another which takes averages across the image in local windows, and the third which finds a preliminary 00025 estimate to the gradient direction using a special 3x3 filter. 00026 */""" 00027 00028 ################################################################################# 00029 # Gradient Orientation Estimation with Linear Structure Tensor 00030 # 00031 # Author: Reza Shahidi 00032 # Seismic Laboratory for Imaging and Modeling 00033 # Department of Earth & Ocean Sciences 00034 # The University of British Columbia 00035 # 00036 # Date: July 2008 00037 ################################################################################# 00038 00039 from slimproj import * 00040 from OrientationEstimation import * 00041 from new_smoothgradient_slimpy import * 00042 from new_smoothgradient_rsf_integration import * 00043 from new_noise_slimpy import * 00044 from new_noise_rsf_integration import * 00045 00046 from rsfproj import * 00047 import os, sys 00048 00049 python = WhereIs('python') 00050 00051 env = Environment() 00052 user = os.path.basename(os.getcwd()) 00053 00054 py_progs = 'smoothgradient' 00055 00056 # Python main programs 00057 py_mains = Split(py_progs) 00058 for prog in py_mains: 00059 # no compilation but rename 00060 env.InstallAs('sf'+prog,'M'+prog+'.py') 00061 00062 @slim_builder_simple 00063 def new_noise_bldr( vectors ): 00064 """ 00065 use our new noise operator 00066 """ 00067 z = vectors[0] 00068 00069 N = noiseX( z.space, sigma=0.08 ) 00070 N.space = z.space 00071 00072 noisyimage = N*z 00073 00074 return noisyimage 00075 00076 @slim_builder_simple 00077 def new_smoothgradient_bldr( vectors ): 00078 """ 00079 use our new smooth gradient operator 00080 """ 00081 z = vectors[0] 00082 00083 dx_outfile = vectors[1] 00084 dy_outfile = vectors[2] 00085 00086 D = smoothgradientX( z.space, dx_outputfilename=dx_outfile, dy_outputfilename=dy_outfile) 00087 D.space = z.space,z.space 00088 00089 Grad = D*z 00090 00091 return Grad 00092 00093 @slim_builder_simple 00094 def OrientationEstimation_bldr( vectors ): 00095 """ 00096 use our new Orientation Estimation operator 00097 """ 00098 00099 theta = OrientationEstimation( "marmousi_theta.rsf", ["marmousi_noisy.rsf", "marmousi_gradx.rsf", "marmousi_grady.rsf"], "" ) 00100 00101 gradfilename='marmousi_grad' 00102 noisydata='marmousi_noisy' 00103 gradxfilename='marmousi_gradx' 00104 gradyfilename='marmousi_grady' 00105 00106 new_noise_bldr('marmousi_noisy', 'marmousi_model') 00107 Flow('marmousi_grad','marmousi_noisy', 00108 python+' Msmoothgradient.py'+ 00109 """ dx_outputfilename=\'marmousi_gradx.rsf\' dy_outputfilename=\'marmousi_grady.rsf\' 00110 """) 00111 00112 OrientationEstimation_bldr( "marmousi_theta.rsf",["marmousi_model.rsf", "marmousi_gradx.rsf", "marmousi_grady.rsf"])