Overlay values from an array on an image




I have a macro where I import an image, compute some values that are stored in arrays, and then I would like to plot the data from these arrays as overlays on top of my image. Here is some of the code in case this helps to clarify:

W = getWidth; H = getHeight; U = round(0.3*H); V = U + 1;
Upper = newArray(W); 
for (j=0; j<W; j++) { 
   makeLine(j, 0, j, U); 
   profile = getProfile(); 
   maxLoc = Array.findMaxima(profile, 1);
   if (maxLoc.length > 0)
	Upper[j] = maxLoc[0] * -1;
       Upper[j] = 0; }

x = newArray(W);
for (p=0; p<x.length; p++) { x[p] = p; }

Fit.doFit("2nd Degree Polynomial", x, Upper);
curveU = newArray(W);
for(a=0; a<W; a++)
	curveU[a] = Fit.f(a);

Now I would like to overlay the curveU values on my image as a line. Does anyone know if this is possible?

Any tips would be greatly appreciated.


Good day Hans,

here is an example macro that shows how to achieve what you wish:

// create test image
newImage("Test", "8-bit ramp", 256, 256, 1);
setBackgroundColor(0, 0, 0);
run("Clear", "slice");
run("Select All");
// profile to overlay
y = getProfile();
for ( i = 0; i < y.length; i++ ) {
	y[i] = -0.5 * y[i] + 192;
x = Array.getSequence( 256 );
makeSelection( "polyline", x, y );
run("Fit Spline");
run("Overlay Options...", "stroke=green width=3");
run("Add Selection...");
run("Select None");
run("Set... ", "zoom=300 x=128 y=128");

It creates a test image and draws its vertical projection profile onto it.




Thanks a lot Herbie, this is excellent! Worked exactly as I’d hoped on my images.

All the best,