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개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!