File Exchange

image thumbnail

imageautocorr -- Autocorrelation of time-ordered data

version 1.0.0 (2.64 KB) by Tristan Ursell
Performs autocorrelation of time-ordered data or images, to output an autocorrelation matrix with values ranging from -1 to 1.

2 Downloads

Updated 03 Aug 2018

View License

Tristan Ursell
August 2018

autocorrmat = imageautocorr(im_stack)
autocorrmat = imageautocorr(mat_data)
autocorrmat = imageautocorr('im_stack.tif')
autocorrmat = imageautocorr('im_stack.tif','load')
autocorrmat = imageautocorr('directory_path')
autocorrmat = imageautocorr('directory_path','load')

This script calculates the image autocorrelation for a (presumed) ordered time series of images. The input data also need not be images, per se, it could also be any type of ordered, correlated data.

'autocorrmat' is an autocorrelation matrix giving the normalized correlation coefficients (-1 <= c <= 1) between any two time points of the data.

'im_stack' is assumed to be a an image stack, that is, images of size M x N with Z such images, such that size(im_stack) = M x N x Z. These would already be loaded into memory.

'mat_data' is a matrix of data M x N where each column is a time point with data of length M.

'im_stack.tif' is stacked TIFF, like 'im_stack', but not loaded into memory. In this mode, the script will 'imread' each image from the stack and perform the autocorrelation without loading in the full stack. This can be useful if the image data is very large. Using the option 'load', will load the stack into memory, and proceed as if it were a stack in memory. In this mode the input is treated as a full path and file name, and as such, you can enter a full path and file name here, e.g. using fullfile(path1,file1). NOTE: Reading images into memory one-by-one will be a much slower computation than loading ('load') into memory.

'directory_path' is a directory containing *only* image files. The script will examine all files in the current directory and read them in as images, thus if you have a folder with (e.g. TIFFs, BMPs, PNGs, JPEGs, etc) that have sequential file names like:

mypic_001.png
mypic_002.png
mypic_003.png
...

this is the option you want. The option 'load', will load those files into memory for processing. NOTE: Reading images into memory one-by-one will be a much slower computation than loading ('load') into memory.

%EX:

%first create a set of correlated data
im_stack=zeros(256,256,256);
im_stack(:,:,1)=normrnd(0,1,[256,256]);

for i=2:256
im_stack(:,:,i)=im_stack(:,:,i-1)*cos(i*pi/50)+normrnd(0,1,[256,256])*sin(i*pi/250);
end

autocorrmat = imageautocorr(im_stack);

figure;
subplot(1,2,1)
imagesc(autocorrmat)
axis equal tight
xlabel('Frame')
ylabel('Frame')
colorbar

subplot(1,2,2)
for i=1:256
imagesc(im_stack(:,:,i))
axis equal tight
xlabel('X')
ylabel('Y')
title(['Frame ' num2str(i)])
pause(0.1)
end

Comments and Ratings (0)

MATLAB Release Compatibility
Created with R2016b
Compatible with any release
Platform Compatibility
Windows macOS Linux