Running fiji/imagej macro from terminal - imagej

I have made a macro in fiji/imagej that i would like to activate via the terminal in a shell script. As it now stands, the macro does not need any inputs, I just want to make fiji run the macro when activated from the terminal, and save its output in the output folder. The script for the macro looks like this:
input = "/Users/matsboh/Documents/PhD/Experiment/Image analyses/Raw/";
output = "/Users/matsboh/Documents/PhD/Experiment/Image analyses/Results/";
setBatchMode(true);
list = getFileList(input);
for (i = 1; i == list.length; i++){
var im = i;
name = "raw_" + im + ".jpg";
dir_name = input + name;
open(dir_name);
run("Subtract Background...", "rolling=50 light");
run("8-bit");
run("Make Binary");
name = "results_" + im + ".csv";
dir_name = output + name;
run("Analyze Particles...", "size=100-20000 show=Nothing display clear");
saveAs("Measurements", dir_name);
close();
}
If this is possible, how would i precede?
Cheers,
Mats

On OS X:
/Applications/Fiji.app/Contents/MacOS/ImageJ-macosx --headless -macro myAwesomeMacro.ijm
On Windows:
%USERPROFILE%\Fiji.app\ImageJ-win64.exe --headless -macro myAwesomeMacro.ijm
On Linux:
~/Fiji.app/ImageJ-linux64 --headless -macro myAwesomeMacro.ijm
Personally, I like to alias the full path to my ImageJ installation's launcher to either imagej or fiji so I can then just type:
imagej --headless -macro myAwesomeMacro.ijm
Of course, how you do that aliasing will also depend on your OS.
See the Headless page of the ImageJ wiki for further details on running macros and scripts from the console.

Related

How to create a shell script binary without harcoding a string in the nix file

To create a binary shell script I'm using writeShellScriptBin. This function takes a string that represents the shell script to be produced, e.g.:
my-script = writeShellScriptBin "my-script" ''
# Some script
''
Using writeShellScriptBin works great for small scripts, but once the script starts growing the string that produces it becomes hard to maintain. So I was wondering what are the alternatives to writeShellScriptBin.
There is substituteAll. Example:
substituteAll {
src = ./foo.in;
name = "foo";
dir = "/bin"; # If you omit it, you will get substitution result in $out
isExecutable = true; # it is script, so you are likely want this.
inherit curl jq execline;
}

Unrecognized Command: ''LoG 3D'' -- in IMAGEJ Macro Language

I am trying to write a code in macro language of ImageJ in order to automate manuel image analysis work. I have found another website to hande with this problem. Then, I have recently downloaded IMAGEJ v1.52q which is the latest version. Next, I pasted the code into the recorder of Marcos and I run the code. The execution caused 'Unrecognized Command':LoG 3D Error. I looked at plugin of LoG filters and I only found the one that is released in 2000. I uploaded this one into plugins part of the ImageJ, but I have got the same error. Please let me know if you have any solutions for this problem.
Thank you in advance.
The code I wrote is taken from the website: https://forum.image.sc/t/manual-image-analysis-works-but-not-the-macro-batch/134/15
and it is:
macro "Focal adhesion analysis" {
dir = getDirectory("Choose a Directory ");
list = getFileList(dir);
setBatchMode(true);
for (i=0; i<list.length; i++) {
path = dir+list[i];
open(path);
run("16-bit");
run("Subtract Background...", "rolling=50 sliding");
run("CLAHE ", "blocksize=15 histogram=256 maximum=6");
title = getTitle;
run("LoG 3D", "sigmax=4 sigmay=4");
selectWindow("LoG of "+title);
setAutoThreshold("Otsu");
run("Analyze Particles...", "size=1-Infinity circularity=0.05-1.00 clear add");
path2 = dir+File.nameWithoutExtension;
saveAs("JPEG", path2+"-bin.jpeg");
selectWindow(title);
run("Revert");
roiManager("Measure");
close();
saveAs("results", path2+"-results.tsv");
roiManager("reset");
}
}
Do you have the CLAHE and LoG 3D plugins installed? ImageJ does not come bundled with them.

waf - update and generate translation pot file

Is there a specific API call (maybe undocumented, none is listed here http://docs.waf.googlecode.com/git/apidocs_16/tools/intltool.html ) which allows me to create and/or update a translation template?
Or do I need use native system tools?
I could not find one either, so I introduced an option in my main wsript file.
opt.add_option('--update-po', action='store_true', default=False, dest='update_po', help='Update localization files')
// ...
def shutdown(self):
if Options.options.update_po:
os.chdir('./po')
try:
try:
size_old = os.stat (APPNAME + '.pot').st_size
except:
size_old = 0
subprocess.call (['intltool-update', '-p', '-g', APPNAME])
size_new = os.stat (APPNAME + '.pot').st_size
if size_new <> size_old:
Logs.info("Updated po template.")
try:
command = 'intltool-update -r -g %s' % APPNAME
self.exec_command (command)
Logs.info("Updated translations.")
except:
Logs.error("Failed to update translations.")
except:
traceback.print_exc(file=open("errlog.txt","a"))
Logs.error("Failed to generate po template.")
Logs.errors("Make sure intltool is installed.")
os.chdir ('..')
Unfortunately I haven't had the time to transform this into a tool yet. Is on my list. But you can find a full fledge sample here: https://bazaar.launchpad.net/~diodon-team/diodon/trunk/view/head:/wscript

echo "example" | clip, adds unwanted linebreak

So - I'm using an image capture tool (snagit).
By default, the image itself is saved to the clipboard (after a capture).
I would prefer that the image's path stored in the clipboard.
The application allows me to (instead) save the file, and pass the image as an argument to an external application. I'm passing it to the following .vbs file:
Dim Clipboard
Set args = WScript.Arguments
if args.length > 0 then
arg1 = trim(args.Item(0))
else
arg1 = "(No Data)"
end if
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "cmd /C echo "&arg1&" | CLIP", 2
This does 99% of what I want, except I find that 'ECHO ... | CLIP' tends to append formfeed/carriage return chars to my string.
Is there a better command I can use (in either cmd/vbs)?
Thanks in advance.
I seriously doubt your code produces <formfeed><carriage return> on the clipboard. It should produce <carriage return><line feed> at the end. Those are the standard line termination characters on Windows. They are automatically added by the ECHO command.
You can write to stdout without the new line using <NUL SET /P "=message"
I don't understand why you are using VBS when it can't access the clipboard directly. It makes more sense to me to use a batch file.
#echo off
setlocal
set "arg1=%~1"
if not defined arg1 set "arg1=(No Data)"
<nul set /p "=%arg1%"|clip
or as a one line batch file:
#if "%~1"=="" (<nul set/p"=(No Data)"|clip) else <nul set/p"=%~1"|clip
If you really want to use VBS, then here it is
Dim args, arg1, objShell
Set args = WScript.Arguments
if args.length > 0 then
arg1 = trim(args.Item(0))
else
arg1 = "(No Data)"
end if
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "cmd /C <nul set /p ""="&arg1&""" | CLIP", 2

Lua return directory path from path

I have string variable which represents the full path of some file, like:
x = "/home/user/.local/share/app/some_file" on Linux
or
x = "C:\\Program Files\\app\\some_file" on Windows
I'm wondering if there is some programmatic way, better then splitting string manually to get to directory path
How do I return directory path (path without filename) in Lua, without loading additional library like LFS, as I'm using Lua extension from other application?
In plain Lua, there is no better way. Lua has nothing working on paths. You'll have to use pattern matching. This is all in the line of the mentality of offering tools to do much, but refusing to include functions that can be replaced with one-liners:
-- onelined version ;)
-- getPath=function(str,sep)sep=sep or'/'return str:match("(.*"..sep..")")end
getPath=function(str,sep)
sep=sep or'/'
return str:match("(.*"..sep..")")
end
x = "/home/user/.local/share/app/some_file"
y = "C:\\Program Files\\app\\some_file"
print(getPath(x))
print(getPath(y,"\\"))
Here is a platform independent and simpler solution based on jpjacobs solution:
function getPath(str)
return str:match("(.*[/\\])")
end
x = "/home/user/.local/share/app/some_file"
y = "C:\\Program Files\\app\\some_file"
print(getPath(x)) -- prints: /home/user/.local/share/app/
print(getPath(y)) -- prints: C:\Program Files\app\
For something like this, you can just write your own code. But there are also libraries in pure Lua that do this, like lua-path or Penlight.

Resources