Calculation of cross variogram

조회 수: 4 (최근 30일)
Chethan S
Chethan S 2011년 5월 1일
I need to generate cross variograms of images using moving windows. To explain the process in a simple way, let me consider two matrices:
j = 1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
k = 17 18 19 20
21 22 23 24
25 26 27 28
29 30 31 32
For generation of cross variograms, the calculation goes on like this:
(1 - 2)(17 - 18) + (2 - 3)(18 - 19)+(3 - 4)(19-20)...
for such pairs of elements. I am not able to think about what kind of loop or built-in function can be used for such work.
I also had to generate variograms from images for this work. For generation of variograms I had to consider only one band of data. For that case I used nlfilter for moving window and created a function to select and calculate values.

채택된 답변

the cyclist
the cyclist 2011년 5월 1일
It wasn't 100% clear to me if each row was supposed to be treated independently, because you don't indicate how terms from any other rows are used. This does the same operation on each row, ultimately giving you a column vector of the same size as the first dimension of your matrices.
diff_j = -diff(j,1,2); % First parenthetical term of the pair
diff_k = -diff(k,1,2); % Second parenthetical term of the pair
prod_jk = diff_j.*diff_k; % All the parenthetical products
sum_prod_jk = sum(prod_jk,2) % Sum of the parenthetical products
This could all be combined into a one-liner, but I kept it split apart to make it easier to see what was going on.
  댓글 수: 2
Chethan S
Chethan S 2011년 5월 1일
Each row was to be treated individually. In fact the solution you provided works fine. This is the equation I am using: http://i.imgur.com/r18kt.png. It means each element of j is to be considered as a central value and the above calculation needs to be carried out. As I work on large satellite images I will need a fast way. Will I be able to use *nlfilter* like methods in this case?
the cyclist
the cyclist 2011년 5월 1일
I don't have any experience with the Image Processing Toolbox, but from reading the documentation, it seems likely you will be able to use nlfilter().
If this answer solved your issue, please "accept" it, so that others looking for a similar solution know that it was helpful.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by