Calculation of cross variogram

4 views (last 30 days)
Chethan S
Chethan S on 1 May 2011
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.

Accepted Answer

the cyclist
the cyclist on 1 May 2011
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 Comments
Chethan S
Chethan S on 1 May 2011
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 on 1 May 2011
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.

Sign in to comment.

More Answers (0)

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!