 # Overlay values from an array on an image

Hi,

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:

``````open("test2.png");
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 * -1;
else
Upper[j] = 0; }

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

Fit.doFit("2nd Degree Polynomial", x, Upper);
Fit.plot();
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);
makePolygon(0,0,255,0,0,255);
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("Select None");
run("Set... ", "zoom=300 x=128 y=128");
``````

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

Regards

Herbie

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

All the best,
Hans