Cara menggunakan image cross correlation python
Utpal Kumar 6 minute read GEOPHYSICS February 16, 2021 Show
Table of Contents
IntroductionCross-correlation is an established and reliable tool to compute the degree to which the two seismic time-series are dependent on each other. Several studies have relied on the cross-correlation method to obtain the inference on the seismic data. For details on cross-correlation methods, we refer the reader to previous works [see references]. It is essential to understand and identify the complex and unknown relationships between two time-series for obtaining meaningful inference from our data. In this post, we will take the geophysical data for understanding purposes. For general readers, I recommend to ignore the field specific examples and stay along, as the concept of correlation is mathematical and can be applied on data related to any field. Similar postsPhoto by Burak K from PexelsIn seismology, several applications are based on finding the time shift of one time-series relative to other such as ambient noise cross-correlation (to find the empirical Green’s functions between two recording stations), inversion for the source (e.g., gCAP) and structure studies (e.g., full-waveform inversion), template matching etc. In this post, we will see how we can compute cross-correlation between seismic time-series and extract the time-shift information of the relation between the two seismic signals in the time and frequency domain. Time domain cross-correlation functionThe correlation between two-stochastic processes A and B (expressed in terms of time-series as \(A(t)\) and \(B(t)\)) can be expresses as (see ref. 1): \begin{equation} \label{eq:square} \begin{split} \rho (\tau) = \frac{\sum_i A(t_i-\tau) B(t_i)}{[\sum_i A(t_i)^2\sum_iB(t_i)^2]^{1/2}} \end{split} \end{equation} The above equation is the sample cross-correlation function between two time-series with a finite time shift \(\tau\). It is important to note that the correlation \(\rho\) by its face value alone does not dictate whether or not the correlation in question is significant, unless the degrees of freedom (DOF) of the processes, which signifies the information content (or entropy), is also specified (see Chao and Chung, 2019 for details). Compute Cross-correlationLet us now look into how we can compute the time domain cross correlation between two time series. For this task, I arbitrarily took two seismic velocity time-series: Arbitrarily selected data
The above code reads the txt file containing the vertical component located in the directory ( Please note that there are several different ways to read the data and preference of that way depends on the user and the data format. To plot the time-series, I used Data VisualizationCompute the cross-correlation in time-domain
In this example, Alternatively, one can directly create Pandas Series object by using pd.Series(). I have used the
Here, as you can notice that the I obtained the correlation between the above pair of time-series to be Time-domain cross-correlation of arbitraily taken real time-seriesFrequency-domain approach of cross-correlation for obtaining time shifts
This gives: Where, the function
Here, the shift of Generate synthetic pair of time seriesAlthough the results obtained seems plausible, as we used the arbitrary pair of real time series, we do not know if we have obtained the correct results. So, we apply the above methods on synthetic pair of time-series with known time-shifts. Let us use the Time-domain cross-correlation of low-pass filtered unit impulse functionReferences
Download CodesAll the above codes can be downloaded from my Github repo. Disclaimer of liabilityThe information provided by the Earth Inversion is made available for educational purposes only. Whilst we endeavor to keep the information up-to-date and correct. Earth Inversion makes no representations or warranties of any kind, express or implied about the completeness, accuracy, reliability, suitability or availability with respect to the website or the information, products, services or related graphics content on the website for any purpose. UNDER NO CIRCUMSTANCE SHALL WE HAVE ANY LIABILITY TO YOU FOR ANY LOSS OR DAMAGE OF ANY KIND INCURRED AS A RESULT OF THE USE OF THE SITE OR RELIANCE ON ANY INFORMATION PROVIDED ON THE SITE. ANY RELIANCE YOU PLACED ON SUCH MATERIAL IS THEREFORE STRICTLY AT YOUR OWN RISK. How does Python calculate auto correlation?Method 3: Using plot_acf() A plot of the autocorrelation of a time series by lag is called the AutoCorrelation Function (ACF). Such a plot is also called a correlogram. A correlogram plots the correlation of all possible timesteps. The lagged variables with the highest correlation can be considered for modeling. How do you manually calculate autocorrelation in Python?Use numpy. correlate() to calculate autocorrelation Call numpy. correlate(arr, arr, mode="full") to calculate the autocorrelation of the array arr with itself. Further Reading: There are three modes that affect which correlations are evaluated by limiting data pairs. You can read more about modes at numpy. What is auto correlation and crossCross correlation happens when two different sequences are correlated. Autocorrelation is the correlation between two of the same sequences. In other words, you correlate a signal with itself. How do you calculate auto correlation?The number of autocorrelations calculated is equal to the effective length of the time series divided by 2, where the effective length of a time series is the number of data points in the series without the pre-data gaps. The number of autocorrelations calculated ranges between a minimum of 2 and a maximum of 400. What is crossCross-correlation is an essential signal processing method to analyze the similarity between two signals with different lags. Not only can you get an idea of how well the two signals match, but you also get the point of time or an index where they are the most similar. This article will discuss multiple ways to process cross-correlation in Python.
How do you use phase crossIn this example, we use phase cross-correlation to identify the relative shift between two similar-sized images. The phase_cross_correlation function uses cross-correlation in Fourier space, optionally employing an upsampled matrix-multiplication DFT to achieve arbitrary subpixel precision 1.
How does SciPy crossThen, the signal is automatically padded at the start and finish by the SciPy cross-correlation. As a result, compared to our pure Python code and the NumPy module, it provides a more extensive signal response for cross-correlation. Therefore, we deleted these padding components to make the outcome equivalent in our test case.
Is there a working Python implementation of normalized crossIf you are trying to do something similar to cv2.matchTemplate (), a working python implementation of the Normalized Cross-Correlation (NCC) method can be found in this repository:
|