Last active
January 3, 2021 11:12
-
-
Save mutterer/27025b8910307f1dd3728d0239e8be49 to your computer and use it in GitHub Desktop.
This ImageJ macro creates an animation by interpolating ROI coordinates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This macro creates an animation by interpolating ROI coordinates | |
// and drawing each step and fading and blurring the image. | |
// The active ROI is hidden if batch mode is true. | |
run("Fresh Start"); | |
newImage("2021", "8-bit black", 256, 256, 1); | |
run("Fire"); | |
setBatchMode(true); // hide ROIs on active image, requires 1.53h21 | |
setForegroundColor(255,255,255); | |
makeLine(78,90,97,61,134,63,149,91,76,174,66,157,139,180,170,160); | |
run("Fit Spline"); | |
run("Interpolate", "interval=1 smooth"); | |
Roi.getCoordinates(x2,y2); | |
l = x2.length; | |
makeLine(238,53,201,71,192,138,221,182,257,136,254,72,212,52); | |
run("Fit Spline"); | |
run("Interpolate", "interval=1 smooth"); | |
Roi.getBounds(x, y, width, height); | |
Roi.move(x-100, y); | |
Roi.getCoordinates(x0,y0); | |
makeLine(396,129,442,56,432,57,433,181,427,190,391,190,471,190); | |
run("Fit Spline"); | |
run("Interpolate", "interval=1 smooth"); | |
Roi.getBounds(x, y, width, height); | |
Roi.move(x-310, y-10); | |
Roi.getCoordinates(x1,y1); | |
x0=Array.resample(x0,l); | |
y0=Array.resample(y0,l); | |
x1=Array.resample(x1,l); | |
y1=Array.resample(y1,l); | |
xn = newArray(l); | |
yn = newArray(l); | |
steps =50; | |
while (true) { | |
// interpolate from '2' to '0' | |
for(s=0;s<steps;s++) { | |
for(i=0;i<l;i++) { | |
xn[i]=x2[i]+s*(x0[i]-x2[i])/steps; | |
yn[i]=y2[i]+s*(y0[i]-y2[i])/steps; | |
} | |
step(); | |
} | |
// interpolate from '0' to '2' | |
for(s=0;s<steps;s++) { | |
for(i=0;i<l;i++) { | |
xn[i]=xn[i]+s*(x2[i]-xn[i])/steps; | |
yn[i]=yn[i]+s*(y2[i]-yn[i])/steps; | |
} | |
step(); | |
} | |
// interpolate from '2' to '1' | |
for(s=0;s<steps;s++) { | |
for(i=0;i<l;i++) { | |
xn[i]=xn[i]+s*(x1[i]-xn[i])/steps; | |
yn[i]=yn[i]+s*(y1[i]-yn[i])/steps; | |
} | |
step(); | |
} | |
// interpolate from '1' to original '2' | |
for(s=0;s<steps;s++) { | |
for(i=0;i<l;i++) { | |
xn[i]=xn[i]+s*(x2[i]-xn[i])/steps; | |
yn[i]=yn[i]+s*(y2[i]-yn[i])/steps; | |
} | |
step(); | |
} | |
} | |
function step() { | |
makeSelection("polyline", xn, yn); | |
run("Line Width...", "line="+20*(s<2)+3); | |
run("Draw"); | |
run("Select None"); | |
run("Subtract...", "value=5"); | |
run("Gaussian Blur...","radius=1"); | |
wait(10); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment