Variograms on Images
    17 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
    Chethan S
 am 2 Apr. 2011
  
    
    
    
    
    Kommentiert: Mohd Galib
 am 6 Dez. 2020
            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 Kommentare
Akzeptierte Antwort
  David Young
      
 am 2 Apr. 2011
        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 Kommentare
  Mohd Galib
 am 26 Nov. 2020
				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
 am 6 Dez. 2020
				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
Weitere Antworten (0)
Siehe auch
Kategorien
				Mehr zu Deep Learning Toolbox finden Sie in Help Center und File Exchange
			
	Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


