Monday 4 January 2010

Imaging plots


My experiments generate image data in three columns: (x, y, brightness)

Converting the raw data into a pretty image was always a slightly tedious task, as I used GNU Octave (or MATLAB) to generate the plot

function plot_3column_data(filename)
%   Grab data from file
data_from_file=load(filename);
x=data_from_file(:,1);
y=data_from_file(:,2);
z=data_from_file(:,3);

%   Find range of x and y axes and make arrays of axis data for plot
xmin=min(x);
xmax=max(x);
ymin=min(y);
ymax=max(y);
xstep=x(2)-x(1);
x_plot=[xmin:xstep:xmax];
y_plot=[ymin:xstep:ymax];

%   Reshape data column into a matrix
z_plot=reshape(z,length(x_plot),length(y_plot));

%   Finally, make a surface plot of the data, using a
%   chosen colour scheme and tweak the shape of the
%   axes
surface(x_plot,y_plot,z_plot','EdgeColor','None')
colormap bone
axis equal


Note that this fairly laborious script didn't even contain axis labelling or exporting to a PNG image. The trouble is, I think, that Octave is a very powerful matrix manipulation language and using it just as an image plotter is overkill. The script is ugly and the interpreter is pretty slow to load.

I'm sure there are much better ways to do this in Octave, but there are already some very nice ready-made data plotting tools available. I found that Gnuplot has a built-in "image" plot style, which does exactly what I want:
set terminal png transparent large size 800,600
set output 'image.png'
plot 'data.dat' with image

It's very simple, and very fast :)

No comments:

Post a Comment