Calculation of cross variogram
4 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
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 个评论
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 个)
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!