Saving PIV analysis doesn't work in macro

fiji
piv
imagej
batch-processing
macro

#1

Hello,

Even though there is a good PIV macro out there, it doesn’t work in my computers (can’t figure out why it doesn’t work, but it doesn’t work :frowning: ), so I had to write one, and I am stuck.

It looks like imageJ can’t recognize the PIV result (which is in .txt) so it can’t rename the file after it is saved. Here is my macro that I wrote so far.

dir1=getDirectory("choose your directory");
dir2=getDirectory("choose your directory");
list=getFileList(dir1);
setBatchMode(true);
for	(i=0;i<list.length;i++)

{
		showProgress(i+1,list.length);
		open(dir1+list[i]);
		open(dir1+list[i+1]);
		run("Images to Stack", "name=[i] title=[] use");
		
run("iterative PIV(Advanced)...", "  piv1=128 sw1=256 vs1=64 piv2=64 sw2=128 vs2=32 piv3=48 sw3=96 vs3=16 correlation=0.60 debug_x=-1 debug_y=-1 path=[] what=[Accept this PIV and output] noise=0.20 threshold=5 c1=3 c2=1 save=C:/Users/Admin/Desktop/piv/PIV_1.txt");
open ("C:/Users/Admin/Desktop/piv/PIV_1.txt");
getInfo("PIV_1.txt");
	saveAs(dir2+list[i]+".txt");
	run("Close");

close();
close();
}

It is kind of semi-automatic because I have to rename PIV_1.txt file right after it is saved, and it takes so much time. Please help!!

Thank you so much in advance,
Gurumi


#2

Hello @gurumi,

I’m not sure to understand what you’re trying to do or how this is supposed to work. Can’t you just save the PIV_1.txt file with the name you want in the first place instead of renaming afterwards ? It seems that you are trying to load the newly written “PIV_1.txt” file into ImageJ, copy its content and save a copy elsewhere ?

You can copy a file easier using File.copy(path1, path2), see https://imagej.nih.gov/ij/developer/macro/functions.html

Note, also that getInfo does not work as you expect it to do. It does not take the title of a window as a parameter. If you want to extract the content of the current text-window, you need to call getInfo("window.contents"). But there should be no need to copy the file content in this way.

Best regards,
Volker


#3

Hi volker,

Thanks for your answer!
I want to save result files as “list.txt” in dir2, but unfortunately, I don’t know how to do it except save a file and rename it afterward…:frowning: I am really a beginner…
If you know how I can improve my code so that I can save all files as “list.txt” in dir2, (without saving each result file as PIV_1.txt and rename it ;)) that would be awesome!

Thank you again for your help. I will look through File.copy and see how to apply it!

-Gurumi


#4

Hello,

I think you could tell the plugin where to save the result directly. Try something like:

run("iterative PIV(Advanced)...", "  piv1=128 sw1=256 vs1=64 piv2=64 sw2=128 vs2=32 piv3=48 sw3=96 vs3=16 correlation=0.60 debug_x=-1 debug_y=-1 path=[] what=[Accept this PIV and output] noise=0.20 threshold=5 c1=3 c2=1 save="+dir2+list[i]+".txt");

Best regards,
Volker


#5

Wow, it works!! Thank you so much, Volker!!

-Gurumi