57 posts
|
Dear list,
Here's a radial graph scatterplot macro that takes a csv list as input
(angle,length), then draws a scatterplot. It colours the points based on
how many neighbouring points lie within a given radius (in this example,
it's 20 pixels). Unfortunately, it goes really slowly, despite setting
batch mode - batch mode appears not to work in this script.
Any hints on how to make it go faster would be much appreciated.
Example data (c. 3000 points) here:
ftp://wht-ogd-29.mds.qmw.ac.uk/pub/imagej/angles.csv
Cheers
Mike
---------------
//Takes a CSV list of angles and values and draws a
//radial scattergraph
requires("1.37v");
//make it go faster
setBatchMode(true);
//Open the array file which must be a csv list in (angle, value \n) format
string = File.openAsString("");
//Split the CSV file into an array of lines
lines = split(string, "\n");
//initialise some variables
theta = newArray(lengthOf(lines));
r = newArray(lengthOf(lines));
rmax = 0;
//Find the maximum radius (to determine the outer boundary)
for (n=0; n<lengthOf(lines); n++){
thetar= split(lines[n], "\,");
theta[n] = parseFloat(thetar[0]);
r[n] = parseFloat(thetar[1]);
if (r[n] > rmax){
rmax = r[n];
}
}
radius = 500;
margin = 5;
image = 2*(radius+margin);
//Draw the new image
newImage("Untitled", "8-bit Black", 2*(radius+margin),2*(radius+margin), 1);
run("Orange Hot");
setColor(200);
//Draw the unit circle
drawOval(margin,margin,2*radius,2*radius);
//Draw axes
drawLine(0,radius+margin, 2*(radius+margin), radius+margin);
drawLine(radius+margin,0, radius+margin, 2*(radius+margin));
//draw each point
for (n=0; n<lengthOf(lines); n++){
setBatchMode(true);
radtheta = theta[n]*2*PI / 360;
unitr = r[n]/rmax;
x = radius + margin + unitr*cos(radtheta)*radius;
y = radius + margin - unitr*sin(radtheta)*radius;
//find out how many neighbours are within, say 20 pixels of our point
neighbours = 0;
for (p=0; p<lengthOf(lines); p++){
setBatchMode(true);
radtheta = theta[n]*2*PI / 360;
punitr = r[p]/rmax;
x1 = radius + margin + punitr*cos(radtheta)*radius;
y1 = radius + margin - punitr*sin(radtheta)*radius;
prox = sqrt((x-x1)*(x-x1)+(y-y1)*(y-y1));
if(prox<20){
neighbours=neighbours+1;
}
}
//find the colour of the pixel we will draw
setColor(255);
//this bit needs to automatically spread the LUT to the observed densities.
//right now it doesn't.
neighbours = neighbours / 3;
if (neighbours<255){
setColor(neighbours);
print(neighbours);
}
fillRect(x,y,4,4);
}
//show us the plot
setBatchMode("exit and display");
-----------------
--
Michael Doube BPhil BVSc MRCVS
PhD Student
Dental Institute
Queen Mary, University of London
New Rd
London E1 1BB
United Kingdom
Phone +44 (0)20 7377 7000 ext 2681
|