MATLAB code & Java Archive

Java implementation of the wavelet-based surrogates generation

This is the java implementation of the method for generating surrogates of gridded data with the same spatial dependence and probability distribution as the input image. Surrogates are generated by matching the dual-tree complex wavelet spectra (and hence the autocorrelation functions) of white noise images with the spectra of the original images. The generated images can then be used to build the probability distribution function of any statistic of association under the null hypothesis. Original publication of the method and Jar archive are available here.

Method and scripts should be cited as:

Deblauwe V., Kennel P. & Couteron P. 2012. Testing association between spatially autocorrelated variables: a new approach using surrogate lattice data. PloS One 7(11): e48766.

There are several ways to use these java libraries. If you are familiar with java you could include it into your own scripts. If you are not, I will rather advice you to call those scripts from another programming language like C, R, Matlab, etc.

Here is an example with matlab:

A is the image (matrix) for which you want to create 999 surrogates. You should have in mind that this image should be square and better results will be achieved with a size that is a power of two (2,4,8,16,32,..). This limitation is easily circumvented by resizing the  image.

A=imread(‘C:\filename.tif’,’tiff’); % we load an image
A=double(A);   % in case the image was in uint8
A=imresize(A,[64,64]); % resize to a square and power of two

We will save the created surrogates in a 3-D matrix named A2.

% number of stages for the wavelet decomposition (we always choose the maximum number)

[nrow,ncol]=size(A);   % the number of rows and columns of A
J=floor(log2(min([nrow,ncol])));
% number of iteration for surrogate synthesis (>=1)
steps=100;
% add the path to the java library
javaaddpath(‘C:\EnergySynthPlugin.jar’) ;
% make an instance to the java class ‘EnergySynth’
algo = EnergySynth(A, J, steps, 8, 2,true);
% 8 and 2 are the recomended wavelet to use in this application (see the paper in PloS). The last argument is set as ‘true’ to indicate that we do want to proceed the histogram matching (otherwise you can set ‘false’).
% synthetise 999 surrogates of A
A2 = algo.synthetizeSamples(999);
A2=permute(A2,[2 3 1]); % rearange the surrogates so that the third dimension  corresponds to the repeated synthesis

Concerning the size of your data, I would advice you to change the resolution to 32 x 32, through a nearest neighbour or bilinear resampling for instance, to get a size compatible with this script (the limitation comes from the wavelet decomposition).

Please feel free to ask if you need more help.

Advertisements