Recombinant DNA technology (Immunological screening)
channel_mzhazbay.pdf
1. Extraction of channel structure from a depth slice
of 3-D seismic volume using bilateral filter and
edge detection algorithm∗
Maksat Zhazbayev†
‡
1 Abstract
The bilateral filter is a nonlinear filter that smoothes a signal by spacial
filtering and attempts to preserve edges. This is accomplished by taking into
account both the spatial proximity and similarity in intensity. The two Gaussian
functions are used such as one that takes the physical distance between two
pixels as an input, and other one that takes the absolute difference in intensity
as its input. The bilateral filter has proven to be an effective image denoising
technique that can be used in various ways according to channel edge extraction
from a depth slice of 3-D seismic volume. The selection of the filter parameters
is an important issue during the application of bilateral filter. In this paper,
a synopsis on bilateral filtering operations and its applications are discussed in
particular for image denoising.
2 Introduction
In the Figure 1, a depth slice from 3-D seismic volume is illustrated on the
left. It has a feature like a channel structure that needs to be extracted using
Canny’s (1986) edge detection algorithm. In the right plot of Figure 1, edge
detector picks areas of high gradient that seem to be aligned along an edge.
The result is not too clear because it is affected by some random fluctuations
in seismic amplitudes. In this paper, I attempt to achieve a better result in
channel extraction by smoothing while keeping the edges of the structure.
To introduce bilateral filtering, I begin by defining Gaussian convolution.
Conventional smoothing as Gaussian filter removes amplitude fluctuations but
at the cost of broadening the channel that makes it unreliable. After, I proceed
to use the bilateral filter that is also a weighted-average filter. The filtered
∗Completed for the Certificate in Scientific Computation
†Maksat Zhazbayev - B.S. in Geophysics in Jackson School of Geosciences
‡Special Thanks to my advisor Sergey Fomel in Jackson School of Geosciences and Bureau
of Economic Geology in University of Texas at Austin
1
2. (a) (b)
Figure 1: (a) Depth slice from 3-D seismic and (b) output of edge detection
output is computed at each pixel as the average of neighboring pixels that is
weighted by the Gaussian of spatial and intensity distance. The bilateral filter
performs in the range of the image what traditional filters do in its domain since
the idea of bilateral filter is to smooth the image while preserving the edges.
Depending on the image intensity, range filtering is defined in order to average
image values with weights that decay with dissimilarity. Afterwards, the range
and domain kernels are combined where if one of the weights is close to zero, a
limited smoothing occurs.
3 Materials and Methods
First of all, I used Gaussian blurring that is the simplest way for smoothing to
remove random amplitude fluctuations from a depth slice of 3-D seismic volume.
The main component is the convolution by a kernel, and each output pixel value
is weighted sum of its neighbors in input image. Gaussian Convolutions is given
by:
GC[I]p =
X
q∈S
Gσ(||p - q||)Iq, (1)
where Gσ(x) indicates 2D Gaussian Kernel that is defined as:
Gσ(x) =
1
√
2πσ2
exp(
−x2
2σ2
) (2)
The weight for pixel q is defined by Gaussian Gσ(||p - q||), where parameter σ
defines the size of the neighborhood. This influence is based on spatial distance
between pixels and not their values.
Furthermore, I define the bilateral filter to smooth the image while preserving
its edges. The name of bilateral filter indicates that the kernel of the filter is a
combination of the two filter kernels such as one is a function of input image’s
spatial domain, and the other is a function of its range. The most common
2
3. way of doing this is by using Gaussian functions that give values according to a
normal distribution and has probability density function:
g(x) =
1
√
2πσ2
exp(
−x2
2σ2
) (3)
This weighted value is then multiplied by the initial value of the input pixel
and summed over a neighborhood. Then, it is normalized by dividing by the
sum of the weighted values. For a neighborhood around Iin(i, j) denoted by Ω,
this gives:
Iout(i, j) =
P
p∈Ω gσs
(|p − (i, j)|)gσr
(|Ip − Iin(i, j)|)Ip
P
p∈Ω gσs
(|p − (i, j)|)gσr
(|Ip − Iin(i, j)|)
(4)
In the equation (4), σr and σs are the range and spatial parameters respec-
tively. Changing these parameters affect the distribution of values, potentially
giving more or less weight to pixels further away. As the two values of Gaus-
sian function are multiplied, the smoothing occurs when the pixels are close or
similar to each other. Consequently, when one of the values is close to zero,
the whole term becomes insignificant. This essentially means that pixels that
are similar but far away, or close but very different, have a little effect on the
output.
The bilateral filter was implemented both for 1-D and 2-D in Python and C
respectively. A Gaussian function g(x) equivalent to in equation (3) is returned
by the function gaussian(int x, int sigma). The distance difference or domain
distance will be the same regardless of what pixel it is being applied to, and is
returned by the function distance(int x, int y, int i, int j). Also, the intensity
difference or range distance Gaussian filter is defined in the body of the function
apply bilateral filter(float source, float filtered image, int x, int y, int r1, int r2,
int sig i, int sig s, int n1, int n2), where result will vary as it depends on the
intensity of the pixel it is being applied to and the intensities of the neighboring
pixels. This function apply bilateral filter() basically applies the element wise
multiplication of these two different masks at every pixel p that is eventually
weighted by the sum of its own components.
4 Results
The Gaussian convolution is independent of the image content. Therefore, a
pixel has an influence on another one depending only on their distance in the
image. For example, a bright pixel would have an influence over a dark pixel
even though these pixels have a different values.
Just like Gaussian convolution, the bilateral filter is described as weighted
average of pixels in the neighborhood. The difference is bilateral filter accounts
for the difference in intensity values with the neighbors to preserve the edges.
The amount of filtering is specified by the parameters σs and σr. For example,
the Figure-3 illustrates gaussian smoothing and bilateral filtering for a synthetic
3
4. example in Figure 2, of a blocky signal containing some random noise. In Figure
3 (a) the random noise gets smoothed at the cost of blurring the edges. The
Figure 3 (b) simply explains how effective bilateral filter would be when applied
to a depth slice from a 3-D seismic volume that has a channel structure that
needs to be extracted.
Figure 2: 1-D synthetic blocky signal contaminated with random noise
As shown in Figure-5, when gaussian smoothing is applied to a depth slice of
3-D seismic volume, random fluctuations are removed by gaussian smoothing.
However, it also broadens the channel and makes the channel edge detection
unreliable. Whereas, bilateral filtering provides a better solution by keeping the
shape of the channel structure and smoothes around it as shown in Figure-6.
Gaussian linear filtering blurs out the image because pixels across discon-
tinuities are averaged together and the edges get lost with high σ since the
averaging is performed over a bigger area.
(a) (b)
Figure 3: (a) Gaussian smoothing and (b) Bilateral filtering
4
5. (a) (b)
Figure 4: (a) Original depth slice from 3-D seismic volume and (b) output of
edge detection
(a) (b)
Figure 5: (a) Gaussian smoothing of the depth slice and (b) output of edge
detection
(a) (b)
Figure 6: (a) Bilateral filtering of the depth slice and (b) output of edge detection
5
6. (a)
(b)
Figure 7: (a) Original Image 512x512 and (b) Bilateral filtering with σs=16 and
σr=10 over 10 iterations
In addition, the bilateral filter can be iterated meaning the filter can be ap-
plied a multiple times to previous result. Applying the filter over a big number
of iterations produces a cartoonish image as in Figure 7.
5 Discussion
The gaussian filter is simpler and provides an introduction of local averaging
concept. It removes the random noise by smoothing but at the expense of
having the edges blurred. Whereas, the bilateral filter is a simple and effective
way to smooth an image while preserving discontinuities, and separate image
structures as I illustrated in the example with the channel. Manipulating with
parameters of bilateral filter provides a lot more diverse set of applications as
6
7. in Figure 8. Overall, the bilateral filter is an expensive algorithm in particular
if a large neighborhood size is defined, and on top of it needs a calculation of
the two weights, and a normalization step as well.
7
9. 6 Acknowledgements
I would like to thank Sergey Fomel for his advices and help that I received
throughout this project. Without his help, my final result wouldn’t be nearly
what it is.
9
10. References
[1] Canny, J., 1986, A computational approach to edge detection: IEEE Trans.
Pattern Analysis and Machine Intelligence, 8, 679-714.
[2] Gilboa, G., and S. Osher, 2008, Nonlocal operators with applications to
image processing: Multiscale Model & Simulation, 7, 1005-1028.
[3] Fomel, S., and G. Hennenfent, 2007, Reproducible computational experi-
ments using SCons: 32nd International Conference on Acoustics, Speech,
and Signal Processing (ICASSP), IEEE, 1257-1260.
[4] Tomasi, C., and R. Manduchi, 1998, Bilateral filtering for gray and color
images: Proceedings of IEEE International Conference on Computer Vision,
IEEE, 836-846.
10
11. 7 Appendix A
1 d b i l a t e r a l . py
#!/ usr / bin /env python
import m8r as s f
import numpy as np
import math
input = s f . Input ()
output = s f . Output ()
par = s f . Par ()
n1 = input . int (” n1 ”)
#n2 = input . int (” n2 ”)
#sigmaD = 5
#sigmaR = 5
sigmaD = par . f l o a t (” sigmaD ”)
sigmaR = par . f l o a t (” sigmaR ”)
i t e r a t i o n s = par . int (” i t e r a t i o n s ”)
I = np . zeros (n1 , ’ f ’ )
input . read ( I )
sz = 40
I = np . pad ( I , ( sz , sz ) , ’ constant ’ , constant values =0)
w = np . zeros ( I . shape , ’ f ’ )
num = np . zeros ( I . shape , ’ f ’ )
Id = np . zeros ( I . shape , ’ f ’ )
f or i t e r a t i o n in range ( i t e r a t i o n s ) :
f or i in range ( sz , len ( I )−sz ) :
sumW = 0
sumNum = 0
f or k in range ( i−sz , i+sz ) :
W = np . exp ( −(i−k) ∗∗2 / (2∗ sigmaD∗∗2) − ( I [ i
]− I [ k ] ) ∗∗2 / (2∗ sigmaR ∗∗2) )
sumW += W
sumNum += I [ k ] ∗ W
I [ i ] = sumNum / sumW
output . write ( I [ sz : len ( I )−sz ] )
11
12. 8 Appendix B
2 d b i l a t e r a l . c
#include <stdio . h>
#include <math . h>
#include <r s f . h>
f l o a t distance ( int x , int y , int i , int j ) ;
f l o a t gaussian ( int x , f l o a t sigma ) ;
void a p p l y b i l a t e r a l f i l t e r ( f l o a t ∗∗ source , f l o a t ∗∗
filtered image , int x , int y , int r1 , int r2 , f l o a t
sigma i , f l o a t sigma s , int n1 , int n2 ) ;
void a p p l y b i l a t e r a l f i l t e r o w n ( f l o a t ∗∗ source , f l o a t ∗∗
filtered image , int r1 , int r2 , f l o a t sigma i , f l o a t
sigma s , int n1 , int n2 , int i t e r a t i o n s ) ;
int main ( int argc , char ∗ argv [ ] )
{
int n1 , n2 , n12 , r1 , r2 , i t e r a t i o n s ;
f l o a t ∗∗ dinp=NULL, ∗∗dout=NULL;
f l o a t a1 , a2 ;
s f f i l e inp , out ;
s f i n i t ( argc , argv ) ;
inp = s f i n p u t (” in ”) ;
out = sf output (” out ”) ;
i f (SF FLOAT != s f g e t t y p e ( inp ) ) s f e r r o r (”Need f l o a t
input ”) ;
i f ( ! s f h i s t i n t ( inp ,” n1”,&n1 ) ) s f e r r o r (”No n1= in
input ”) ;
i f ( ! s f h i s t i n t ( inp ,” n2”,&n2 ) ) s f e r r o r (”No n2= in
input ”) ;
n12 = n1∗n2 ;
i f ( ! s f g e t i n t (” r1 ”,& r1 ) ) r1 =1; /∗ v e r t i c a l smoothing
radius ∗/
i f ( ! s f g e t i n t (” r2 ”,& r2 ) ) r2 =1; /∗ horizontal
12
13. smoothing radius ∗/
i f ( ! s f g e t i n t (” i t e r a t i o n s ”,& i t e r a t i o n s ) ) i t e r a t i o n s
=1; /∗ i t e r a t i o n s ∗/
i f ( ! s f g e t f l o a t (” a1”,&a1 ) ) a1=0.0 f ; /∗ sigma i
s p a t i a l ∗/
i f ( ! s f g e t f l o a t (” a2”,&a2 ) ) a2=a1 ; /∗ sigma s range
∗/
dinp = s f f l o a t a l l o c 2 (n1 , n2 ) ;
dout = s f f l o a t a l l o c 2 (n1 , n2 ) ;
s f f l o a t r e a d ( dinp [ 0 ] , n12 , inp ) ;
a p p l y b i l a t e r a l f i l t e r o w n ( dinp , dout , r1 , r2 , a1 , a2
, n1 , n2 , i t e r a t i o n s ) ;
// s f f l o a t w r i t e ( dout [ 0 ] , n12 , out ) ;
s f f l o a t w r i t e ( dinp [ 0 ] , n12 , out ) ;
}
f l o a t distance ( int x , int y , int i , int j ) {
f l o a t r e s u l t = (x−i ) ∗(x−i ) + (y−j ) ∗(y−j ) ;
return r e s u l t ;
}
f l o a t gaussian ( int x , f l o a t sigma ) {
f l o a t pi = 3 . 1 4 ;
f l o a t r e s u l t = ( 1 . / pow(2 ∗ pi ∗ ( sigma ∗ sigma )
, 0 .5 ) ) ∗ expf (−(x∗x) / (2∗ sigma∗sigma ) ) ;
return r e s u l t ;
}
void a p p l y b i l a t e r a l f i l t e r ( f l o a t ∗∗ source , f l o a t ∗∗
filtered image , int x , int y , int r1 , int r2 , f l o a t
sigma i , f l o a t sigma s , int n1 , int n2 ) {
f l o a t i f i l t e r e d = 0;
f l o a t Wp = 0;
int k1 , k2 ;
f l o a t gi , gs ;
f l o a t w;
int neighbour x , neighbour y ;
f l o a t neighbour , p i x e l ;
f or ( k1=−r1 ; k1<r1 ; k1++){
13
14. neighbour x = x+k1 ;
i f ( neighbour x < 0 | | neighbour x >= n1 )
continue ;
f or ( k2=−r2 ; k2<r2 ; k2++){
neighbour y = y+k2 ;
i f ( neighbour y < 0 | | neighbour y >= n2 )
continue ;
// neighbour = ∗( source+neighbour x ∗n2+
neighbour y ) ;
// p i x e l = ∗( source+x∗n2+y) ;
neighbour = source [ neighbour x ] [ neighbour y ] ;
p i x e l = source [ x ] [ y ] ;
gi = gaussian ( distance ( neighbour x ,
neighbour y , x , y) , sigma i ) ;
gs = gaussian ( neighbour − pixel , sigma s ) ;
w = gi ∗ gs ;
Wp += w;
i f i l t e r e d += neighbour ∗ w;
// p r i n t f (”% f n and %f n” , gi , gs ) ;
}
}
i f i l t e r e d = i f i l t e r e d / Wp;
// f i l t e r e d i m a g e [ x ] [ y ] = i f i l t e r e d ;
source [ x ] [ y ] = i f i l t e r e d ;
//∗( f i l t e r e d i m a g e+x∗n2+y) = i f i l t e r e d ;
// p r i n t f (”% f n” , i f i l t e r e d ) ;
// p r i n t f (”% f n” , ∗( source+x∗n2+y) ) ;
}
void a p p l y b i l a t e r a l f i l t e r o w n ( f l o a t ∗∗ source , f l o a t ∗∗
filtered image , int r1 , int r2 , f l o a t sigma i , f l o a t
sigma s , int n1 , int n2 , int i t e r a t i o n s ) {
int x , y , i t e r ;
f or ( i t e r =0; i t e r < i t e r a t i o n s ; i t e r++){
f or (x=0; x<n1 ; x++){
f or (y=0; y<n2 ; y++){
a p p l y b i l a t e r a l f i l t e r ( source ,
filtered image , x , y , r1 , r2 , sigma i ,
sigma s , n1 , n2 ) ;
// p r i n t f (”% f n” ,∗( f i l t e r e d i m a g e+x∗n2+y) )
;
}
}
}
}
14
15. 9 Appendix C
SConstruct
from r s f . proj import∗
prog = Program ( ’2 d b i l a t e r a l . c ’ )
b i l a t e r a l = s t r ( prog [ 0 ] )
#### 1−D NOISY SIGNAL BILATERAL FILTER
####
Flow ( ’1 dsignal ’ , None , ’ spike nsp=3 n1=101 k1=26 ,51 ,76 mag
=−1,2,−1 d1=1 | causint | noise var =0.001 ’)
Result ( ’1 dsignal ’ , ’ dots t i t l e =”1−D blocky s i g n a l w/
random noise ” ’)
Flow ( ’1 d b i l a t e r a l ’ , ’ 1 dsignal 1 d b i l a t e r a l . py ’ , ’ . / ${
SOURCES[ 1 ] } sigmaD=10 sigmaR=0.3 i t e r a t i o n s =1 ’)
Result ( ’1 d b i l a t e r a l ’ , ’ dots t i t l e =”B i l a t e r a l f i l t e r ” ’)
Flow ( ’1 d gaussian ’ , ’ 1 dsignal ’ , ’ gaussmooth rect =10 ’)
Result ( ’1 d gaussian ’ , ’ dots wanttitle=n ’)
#### HORIZON
−Channel ####
Fetch ( ’ horizon . asc ’ , ’ hall ’ )
Flow ( ’ horizon ’ , ’ horizon . asc ’ ,
’ ’ ’
echo in=$SOURCE data format=a s c i i f l o a t 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=196 o2=35.031 d2=0.01 label2=x unit2=km
’ ’ ’)
Result ( ’ horizon ’ , ’ grey color=j bias=0 yreverse=n t i t l e=
Original ’ )
Flow ( ’ edgehorizon ’ , ’ horizon ’ , ’ canny max=98 | dd type=
float ’ )
Result ( ’ edgehorizon ’ , ’ grey color=j yreverse=n label1=”y (
km) ” label2=”x (km) ” bias=0 wanttitle=n ’ )
#### Applying Gaussian smoothing ####
Flow ( ’ horizong ’ , ’ horizon ’ , ’ smooth rect1=20 rect2 =20 ’)
15
16. Result ( ’ horizong ’ , ’ grey color=j yreverse=n label1=”y (km)
” label2=”x (km) ” bias=0 wanttitle=n ’ )
Flow ( ’ edgehorizong ’ , ’ horizong ’ , ’ canny max=98 | dd type=
float ’ )
Result ( ’ edgehorizong ’ , ’ grey color=j yreverse=n label1=”y
(km) ” label2=”x (km) ” bias=0 wanttitle=n ’ )
#### Applying 2−D B i l a t e r a l F i l t e r ####
Flow ( ’ horizonb ’ , [ ’ horizon ’ , b i l a t e r a l ] , ’./ ${SOURCES[ 1 ] }
r1=25 r2=25 a1=4 a2=7 i t e r a t i o n s =1 ’)
Result ( ’ horizonb ’ , ’ grey color=j yreverse=n wanttitle=n ’ )
Flow ( ’ edgehorizonb ’ , ’ horizonb ’ , ’ canny max=98 | dd type=
float ’ )
Result ( ’ edgehorizonb ’ , ’ grey color=j yreverse=n wanttitle=
n ’)
#### MONA 2D BILAT ####
Flow ( ’mona ’ , ’ mona . img ’ , ’ echo in=$SOURCE n1=512 n2=512 d1
=1 d2=1 o1=0 o2=0 data format=native uchar | dd type=
float ’ )
Result ( ’mona ’ , ’ grey wanttitle=n color=b transp=n ’ )
Flow ( ’monab ’ , [ ’ mona ’ , b i l a t e r a l ] , ’./ ${SOURCES[ 1 ] } r1=10
r2=10 a1=16 a2=10 i t e r a t i o n s =10 ’)
Result ( ’monab ’ , ’ grey wanttitle=n color=b transp=n ’ )
Flow ( ’ monabdiff ’ , ’ monab mona ’ , ’ d i f f e r e n c e subtracter=${
SOURCES[ 1 ] } ’ )
Result ( ’ monabdiff ’ , ’ grey transp=n color=b t i t l e=Mona ’ )
f or i in range (4 ,16 ,4) :
f or j in range (1 ,10 ,3) :
monabb = ’mona−’ + s t r ( i ) + ’−’ + s t r ( j )
Flow (monabb , [ ’ mona ’ , b i l a t e r a l ] , ’./ ${
SOURCES[ 1 ] } r1=10 r2=10 a1=%d a2=%d
i t e r a t i o n s =10’ % ( i , j ) )
Result (monabb , ’ grey transp=n color=b
t i t l e=%s ’%(monabb) )
End()
16
17. 10 Reflection
Above methods are implemented with Madagascar in languages C and Python.
Madagascar is an open-source software package for multidimensional data anal-
ysis and reproducible computational experiments in geoscience.
During this project I learned a development kit for C, and Python in Mada-
gascar environment. Also, I picked up a new skills such as writing scientific
publications based on L
A
TEX, and reproducing numerical experiments based on
SCons.
17