Variograms on Images
조회 수: 5 (최근 30일)
이전 댓글 표시
I am working on applying geostatistics on Landsat imagery. My focus is on applications of variograms. I will be using n x n windows for generation of variogram plots and texture layers. From various online forums I learnt that the process would be faster if functions like blkproc, nlfilter, colfilt etc. are used instead of normal for loop based moving windows.
I see from the MATLAB help that I can integrate other custom functions to above said functions. But as I have to calculate directional variograms - in EW, NS, NE-SW and NW-SE directions I will have to consider only few pixels(cells of matrix) in front of the central pixel and not all surrounding pixels as in the case of filters. Can anyone suggest how I can go about/are there functions(or toolboxes) available to do such operations?
댓글 수: 0
채택된 답변
David Young
2011년 4월 2일
If I've understood correctly what you need, I'd use a function something like the following (which doesn't use blkproc or any of that family, but which does use MATLAB's vectorisation capability effectively).
function v = directionalVariogram(img, xoffset, yoffset)
%directionalVariogram computes empirical direction variogram
% v = directionalVariogram(img, xoffset, yoffset) takes a 2D image array
% and offsets in the x and y directions. It returns the mean of the
% squared differences between pairs of pixels in the image such that the
% spatial offsets between the pixels are as specified.
if xoffset < 0 % difference is symmetric so can force xoffset positive
xoffset = -xoffset;
yoffset = -yoffset;
end
% make offset and trimmed copies of image
if yoffset > 0
imga = img(1+yoffset:end, 1+xoffset:end);
imgb = img(1:end-yoffset, 1:end-xoffset);
else
imga = img(1:end+yoffset, 1+xoffset:end);
imgb = img(1-yoffset:end, 1:end-xoffset);
end
d = imga - imgb;
v = mean(d(:).^2);
end
To get the estimate for a distance of sqrt(2) pixels in the NE-SW direction, you call it like this, for example
v = directionalVariogram(img, 1, -1)
It will work with offsets in any direction and larger offsets (up to the size of the image) but the offsets have to be integers.
If you can't see how the function works, and you want to understand it, try putting in some calls to imshow to display imga and imgb, and call it with large offsets. You should also check it on some synthetic test data, for which you know what the answer should be, to make sure it does exactly what you expect.
댓글 수: 2
Mohd Galib
2020년 11월 26일
while running this programme in matlab with an image it is showing an error...perhaps because we have not defined 'xoffset'& 'yoffset' before loops....could you please help me, as I am new to Matlab...
Mohd Galib
2020년 12월 6일
i tried it as....
img = imread('assignment 3.jpg');
img1 = rgb2gray(img) ;
[row,column]=size(img1);
%variogram of image column wise
for lag = 1:500
for x=1:2000 %since the system was very long to process
% ,thats why not took upto end
img2=img1(1:end,x)-img1(1:end, x+lag);
v1 = mean(img2(:).^2);
end
figure(1)
plot(lag,v1,'*')
hold on
legend("variogram")
title("variogram of image column wise")
xlabel ("pixel distance")
ylabel("variogram value")
end
%variogram of image row wise
for lag = 1:500
for x=1:2000 %since the system was very long to process
%,thats why not took upto end
img3=img1(x,1:end)-img1(x+lag,1:end);
v2 = mean(img3(:).^2);
end
figure(2)
plot(lag,v2,'*')
hold on
legend("variogram")
title("variogram of image row wise")
xlabel ("pixel distance")
ylabel("variogram value")
end
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!