I am new to coding and have issues writing code for imageJ. Here is what I want to do: In imageJ, I export a video, apply a grey filter on it, invert the color, trace a line on my object of interest, and finally, Plot Profil to have in y the greyscale and x the size of my object. By clicking LIVE, I can have the plot through the entire video. The problem that I have is that I want to export my data in CSV to be able to open it on excel for each frame. But when I export my data, it only does it for one frame and not the entire movie. I tried to look around to write a code that could do that but couldn't find the answer.
If someone has an idea, I am listening! Thanks for your help
I tryied that
dir = getDirectory("Image")
title = getTitle();
for(i=1;i<nSlices;i++){
run("Duplicate...","duplicate range=i.i");
saveAs("Csv",dir + title + "_" + i);
run("Close");
}
But that duplicate my frames on my image, not my plot, and of course I have an error because I cannot save it in csv because there are images.
Here is a demo ImageJ-macro that should do what you want (first update your ImageJ to the latest version 1.54b):
//imagej-macro "saveStackProfiles" (Herbie G., 12. Jan. 2023)
requires( "1.54b" );
close("*");
run("MRI Stack"); // load a demo stack
nme=getTitle();
ttl=split(nme,".")
hH=0.5*getHeight();
makeLine( 0, hH, getWidth, hH );
nme="Profiles_of_"+ttl[0];
Table.create(nme);
n=nSlices;
for(i=1;i<=n;i++) {
setSlice(i);
p=getProfile();
Table.setColumn("Slice"+i, p);
}
//close(getTitle());
path=getDir("Where to save the profile data?");
Table.save(path+nme+".csv");
exit();
//imagej-macro "saveStackProfiles" (Herbie G., 12. Jan. 2023)
Paste the above macro code to an empty macro window (Plugins >> New >> Macro) and run it. (You need an open internet connection to load the demo stack.)
The table is saved with the slice-profiles as columns.
It should be rather easy to modify this demo macro to make it suit to your needs.
Now here is a version that adds a first column with the distances:
//imagej-macro "saveStackProfiles" (Herbie G., 13. Jan. 2023)
requires( "1.54b" );
close("*");
run("MRI Stack"); // load a demo stack
run("Set Scale...", "distance=65 known=50 unit=mm");
nme=getTitle();
ttl=split(nme,".")
makeLine( 0, 0.5*getHeight, getWidth, getHeight );
nme="Profiles _of_"+ttl[0];
getPixelSize(unit, d, na);
p=getProfile();
n=p.length;
for(i=0;i<n;i++)
p[i]=i*d;
Table.create(nme);
Table.setColumn("Distance/"+unit, p);
n=nSlices;
for(i=1;i<=n;i++) {
setSlice(i);
p=getProfile();
Table.setColumn("Slice"+i, p);
}
//close(getTitle());
path=getDir("Where to save the profile data?");
Table.save(path+nme+".csv");
exit();
//imagej-macro "saveStackProfiles" (Herbie G., 13. Jan. 2023)